def test_constructor(self): """ One should be able to readily construct a temporary directory """ d = TempDir() assert isinstance(d, path.Path) assert d.exists() assert d.isdir() d.rmdir() assert not d.exists()
def test_context_manager_exception(self): """ The context manager will not clean up if an exception occurs. """ d = TempDir() d.__enter__() (d / 'somefile.txt').touch() assert not isinstance(d / 'somefile.txt', TempDir) d.__exit__(TypeError, TypeError('foo'), None) assert d.exists()
def test_context_manager(self): """ One should be able to use a TempDir object as a context, which will clean up the contents after. """ d = TempDir() res = d.__enter__() assert res == path.Path(d) (d / 'somefile.txt').touch() assert not isinstance(d / 'somefile.txt', TempDir) d.__exit__(None, None, None) assert not d.exists()