コード例 #1
0
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}")
コード例 #2
0
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
コード例 #3
0
 def __enter__(self):
     self._d = mkdtemp(suffix='-dmf')
     if self._chdir:
         self._origdir = os.getcwd()
         os.chdir(self._d)
     return self._d
コード例 #4
0
 def __enter__(self):
     self._d = mkdtemp(*self._a)
     return self._d
コード例 #5
0
def tmpd():
    d = mkdtemp(suffix="codesearch_get_modules")
    yield d
    shutil.rmtree(d)
コード例 #6
0
def wspath():
    dirname = mkdtemp()
    yield dirname
    # teardown
    shutil.rmtree(dirname)
コード例 #7
0
 def setUpClass(cls):
     cls.dirname = mkdtemp()
     cls.fname = os.path.join(cls.dirname, "crAzYStuff1010202030.json")
コード例 #8
0
def tmpd():
    d = mkdtemp(prefix="test_resource_", suffix=".idaes")
    yield d
    shutil.rmtree(d)