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

Martin A. Brown martin at linux-ip.net
Fri Jan 29 00:45:51 EST 2016


Hello there,

>> 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?

Oh dear--yes.  Apologies, Danny and boB.

To the doghouse with me.

-Martin

-- 
Martin A. Brown
http://linux-ip.net/


More information about the Tutor mailing list