You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stop doctests polluting current dir with temporary files #264
Or.. A utility to create a temp directory that will be consistently destroyed afterwards might be useful
(as opposed to tempdir which does not arrange for destruction).
# in <testutils.py>
import pathlib
class TempDir(pathlib.Path):
def __init__(self):
# self.context is deleted when self is deleted --> destroys directory
self.context = tempfile.TemporaryDirectory()
self.path_str = self.context.__enter__()
self.path = pathlib.Path(self.dirpath_str)
# a single common per-import object
tempdir = TempDir()
# ...
# in docstrings / docs
# Usage is generally shorter, and directory is removed on program exit
>>> from testutils import tempdir
...
>>> filepath = tempdir.path / "tmp.nc"
>>> to_nc4(data, filepath)
>>> result = from_nc4(filepath)
Activity