[Tutor] How do I test file operations (Such as opening, reading, writing, etc.)?

boB Stepp robertvstepp at gmail.com
Thu Jan 28 23:32:05 EST 2016


On Thu, Jan 28, 2016 at 2:44 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:

> Danny has shown you one way using a mocked filesystem.
> But for your case can't you just specify a file location
> as an environment variable or argv? That way you get the
> advantage of using real files, which can be an important
> factor in timing issues, especially if you plan on having
> any concurrency going on. And it's simple to do...

This type of approach was actually what first popped into my head.  It
is partially why I set up my project structure as grammar/grammar and
grammar/test, where my actual program code would be under grammar.  I
thought this way I could have an identically structured data/ folder
under both grammar/ and test/.  But it was not coming to me how to set
up class Editor(), so that it would seamlessly access the *correct*
filesystem, depending on whether I was running program code or test
code.  But amongst all the things Danny clarified, he really helped me
see how to do this in the context of writing classes.

But in choosing what approach to use, I had not considered the
possible importance of using real files in some instances, which you
allude to.

Thanks!

boB


More information about the Tutor mailing list