Skip to main content

Create and recursively fill a temporary directory

Project description

A context manager that creates a temporary directory using tempfile.TemporaryDirectory and then populates it.

Extremely useful for unit tests where you want a whole directory full of files really fast.

EXAMPLE

import tdir

with tdir.tdir(
    'one', 'two', 'three',
    four='two\nlines',
    sub1={
        'six': 'A short file',
        'seven': 'blank lines\n\n\n\n',
        'eight': ['a', 'b', 'c']
}) as td:
    # Now the directory `td` has files `one`, `two` and `three`, each with
    # one line, file `four` with two lines, and then a subdirectory `sub/`
    # with more files.

API

tdir.tdir(*args, cwd=True, **kwargs)

(tdir.py, 39-71)

A context that creates and fills a temporary directory

ARGUMENTS
args:

A list of string file names. Each file is created and filled with the string value of its name.

cwd:

If true, change the working directory to the temp dir at the start of the context and restore the original working directory at the end.

kwargs:

A dictionary mapping file or directory names to values. If the key’s value is a string it is used to file a file of that name. If it’s a dictionary, its contents are used to recursively create and fill a directory.

tdir.fill(root, *args, **kwargs)

(tdir.py, 73-116)

Fill a directory with files containing strings

ARGUMENTS
root:

The root directory to fill

args:

A list of string file names. Each file is created and filled with the string value of its name.

kwargs:

A dictionary mapping file or directory names to values. If the key’s value is a string it is used to file a file of that name. If it’s a dictionary, its contents are used to recursively create and fill a directory.

(automatically generated by doks on 2020-06-22T19:52:19.175342)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tdir-0.9.1.tar.gz (2.8 kB view hashes)

Uploaded Source

Built Distribution

tdir-0.9.1-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page