TempIO
self-destructable temporary directory root.
The TempIO class is accessible via the testtools.io module.
Takes the same keyword args as tempfile.mkdtemp.
You will most likely create this in a test module like so (nosetests/ py.test style) :
>>> tmp = None >>> def setup_module(self): ... self.tmp = TempIO() >>> def teardown_module(self): ... del self.tmp >>> def test_something(): ... tmp.root ... # ... >>>
NOTE: due to the unpredictability of when destructors get called, you may want to explicitly delete your instance in a teardown method. however, an atexit function will try and clean up too.
Methods
f mkdir(self, name, mkall=True) ...
makes a directory in the root and returns its full path.
if mkall is True, will split the path and make each non-existant directory. returns full path to new directory.
f mkfile(self, fname) ...
makes a filename in root.
- the path is relative to your TempIO root.
- all subdirectories are created if they don't exist
- no checking is done as to whether this file exists or not
returns full path to new file.
f newdir(self, name) ...
makes a directory in the root.
it also adds name as a property to this instance. returns full path to new directory.
See the source for more information.