nanoutils.testing_utils

Utility functions related to unit-testing.

Index

FileNotFoundWarning

A ResourceWarning subclass for when a file or directory is requested but doesn’t exist.

delete_finally(*paths[, prefix, warn])

A decorater which deletes the specified files and/or directories after calling the deocrated function.

API

exception nanoutils.FileNotFoundWarning[source]

A ResourceWarning subclass for when a file or directory is requested but doesn’t exist.

@nanoutils.delete_finally(*paths, prefix=None, warn=True)[source]

A decorater which deletes the specified files and/or directories after calling the deocrated function.

Examples

>>> import os
>>> from nanoutils import delete_finally

>>> file1 = 'file1.txt'
>>> dir1 = 'dir1/'
>>> os.path.isfile(file1) and os.path.isdir(dir1)  
True

>>> @delete_finally(file1, dir1)
... def func():
...     pass

>>> func()  
>>> os.path.isfile(file1) or os.path.isdir(dir1)  
False
Parameters:
  • *paths (str, bytes or os.PathLike) – Path-like objects with the names of to-be deleted files and/or directories.

  • prefix (str, bytes or os.PathLike, optional) – The directory where all user specified paths are located. If None, asume the files/directories are either absolute or located in the current working directory.

  • warn (bool) – If True issue a FileNotFoundWarning if a to-be deleted file or directory cannot be found.