fixture.io

Working with temporary file systems.

See Using TempIO for examples.

fixture.io.TempIO(deferred=False, **kw)

self-destructing, temporary directory.

Takes the same keyword args as tempfile.mkdtemp with these additional keywords:

deferred
If True, destruction will be put off until atexit. Otherwise, it will be destructed when it falls out of scope

Returns an instance of DeletableDirPath

class fixture.io.DeletableDirPath

Bases: fixture.io.DirPath

A temporary directory path.

That is, one that can be deleted.

Note

Use the TempIO() function to create an instance

__del__()
removes the root directory and everything under it.
rmtree()

forcefully removes the root directory and everything under it.

This can be trusted more than del self because it is guaranteed to remove the directory tree.

class fixture.io.DirPath

A directory path.

The instance will function exactly like a string but is enhanced with a few common methods from os.path. Note that path.split() is implemented as self.splitpath() since otherwise paths may not work right in other applications (conflicts with str.split()).

abspath()
os.path.abspath(self)
basename()
os.path.basename(self)
dirname()
os.path.dirname(self)
exists()
os.path.exists(self)
join(*dirs)
os.path.join(self, *dirs)
mkdir(name)

makes a directory in the root and returns its full path.

the path is split each non-existant directory is made. returns full path to new directory.

normpath()
os.path.normpath(self)
putfile(fname, contents, mode=None)

puts new filename relative to your TempIO() root. Makes all directories along the path to the final file.

The fname argument can be a complete path, but must not start with a slash. Any missing directories will be created relative to the TempIO() root

returns absolute filename.

realpath()
os.path.realpath(self)
splitext()
os.path.splitext(self)
splitpath()
os.path.split(self)

Previous topic

fixture.exc

Next topic

fixture.loadable