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

boB Stepp robertvstepp at gmail.com
Fri Jan 29 00:03:27 EST 2016


On Thu, Jan 28, 2016 at 5:09 PM, Martin A. Brown <martin at linux-ip.net> wrote:

> I'll add one option to the mix, and summarize the other options I saw listed
> earlier.
>
> Option A (tempfile):
>
>   Create a directory and copy your pristine tree into the directory
>   and make the base directory for the important data files configurable.
>   Also known as parameterization.
>
> Option B (starting with Danny's sample code)
>
>   Create the objects to emulate whatever filesystem behaviour you need.
>
> Option C (use pyfakefs):
>
>   Use pyfakefs, which acts like a filesystem for testing purposes.
>   https://pypi.python.org/pypi/pyfakefs
>   https://github.com/jmcgeheeiv/pyfakefs
>
> Option D (use StringIO):
>
>   If you are less concerned about filesystem interactions and really
>   just want an individual thingy that that behaves like a file, but
>   can be constructed in memory, use StringIO (or cStringIO).

Isn't option D what Danny was using to make option B?  Or are you
saying keep things even simpler?

boB


More information about the Tutor mailing list