def tmp_dmf(): """Test fixture to create a DMF in a temporary directory. """ tmpdir = mkdtemp() dmf = dmfbase.DMF(path=tmpdir, create=True) yield dmf removed = False for i in range(3): try: shutil.rmtree(tmpdir) removed = True print(f"@@ removed DMF temp dir on try {i+1}") except Exception as err: print(f"@@ error removing tempdir: {err}") time.sleep(1) print(f"@@ tries = {i + 1}") if not removed: warnings.warn(f"failed to remove temporary directory: {tmpdir}")
def dummy_package(): random.seed() saved_sys_path = sys.path[:] # build a bad module in a temporary package d = mkdtemp() sys.path.append(d) foo = os.path.join(d, "foo{}".format(random.randint(1e6, 1e7 - 1))) os.mkdir(foo) open(os.path.join(foo, "__init__.py"), "w") # create some modules m = open(os.path.join(foo, "goodmodule.py"), "w") m.write("class IndexMe(object):\n pass\n") m.close() m = open(os.path.join(foo, "badmodule.py"), "w") m.write("This is a bad module.\n") m.close() yield foo # clean up shutil.rmtree(d) sys.path = saved_sys_path
def __enter__(self): self._d = mkdtemp(suffix='-dmf') if self._chdir: self._origdir = os.getcwd() os.chdir(self._d) return self._d
def __enter__(self): self._d = mkdtemp(*self._a) return self._d
def tmpd(): d = mkdtemp(suffix="codesearch_get_modules") yield d shutil.rmtree(d)
def wspath(): dirname = mkdtemp() yield dirname # teardown shutil.rmtree(dirname)
def setUpClass(cls): cls.dirname = mkdtemp() cls.fname = os.path.join(cls.dirname, "crAzYStuff1010202030.json")
def tmpd(): d = mkdtemp(prefix="test_resource_", suffix=".idaes") yield d shutil.rmtree(d)