toolrack.testing

Unit-test features.

class toolrack.testing.Dir(path: pathlib.Path)

A helper for creating files and directories under a base directory.

This is meant to be used for test fixtures.

join(*paths)

Join the specified path fragments with directory prefix.

mkdir(path=None)

Create a temporary directory and return the pathlib.Path.

By default, a random name is chosen.

Parameters:path – if specified, it’s appended to the base directory and all intermiediate directories are created too. A relative path must be specified. A tuple of strings can be also passed, in which case elements are joined using os.path.sep().
mkfile(path=None, content='', mode=None)

Create a temporary file and return the pathlib.Path.

By default, a random name is chosen.

Parameters:
  • path – if specified, it’s appended to the base directory and all intermiediate directories are created too. A relative path must be specified. A tuple of strings can be also passed, in which case elements are joined using os.path.sep().
  • content (str) – the content of the file.
  • mode (int) – Unix permissions for the file.

Create a symbolic link and return the pathlib.Path.

By default, a random name is chosen.

Parameters:
  • target – path of the symlink target.
  • path – if specified, it’s appended to the base directory and all intermiediate directories are created too. A relative path must be specified. A tuple of strings can be also passed, in which case elements are joined using os.path.sep().
toolrack.testing.tempdir(tmpdir)

A temporary directory fixture.