Пример #1
0
def test_temp_dir_sentinel():
    from os.path import join, isdir, exists, abspath
    basedir = "test_temp_dir_sentinel"
    fn = join(basedir, "foo", "bar")
    if exists(basedir):
        print("Path %s exists, not running test_temp_dir_sentinel()" % basedir)
        return
    os.makedirs(basedir)
    eq_(get_closest_dir(fn)[0], basedir)
    eq_(get_closest_dir(fn)[1], "foo")
    sentinel = join(basedir, "foo.inuse")
    try:
        with temp_dir(fn, erase_after=True, with_sentinel=True):
            assert isdir(fn)
            assert exists(sentinel)
            # simulate work
            open(join(fn, "dummy.txt"), "w").close()
        # work file should be deleted together with directory
        assert not exists(fn)
        assert not exists(join(basedir, "foo"))
        # basedir should still exist, though!
        assert isdir(basedir)
    finally:
        if isdir(basedir):
            shutil.rmtree(basedir)
Пример #2
0
def test_temp_dir_sentinel():
    from os.path import join, isdir, exists, abspath
    basedir = "test_temp_dir_sentinel"
    fn = join(basedir, "foo", "bar")
    if exists(basedir):
        print("Path %s exists, not running test_temp_dir_sentinel()" % basedir)
        return
    os.makedirs(basedir)
    eq_(get_closest_dir(fn)[0], basedir)
    eq_(get_closest_dir(fn)[1], "foo")
    sentinel = join(basedir, "foo.inuse")
    try:
        with temp_dir(fn, erase_after=True, with_sentinel=True):
            assert isdir(fn)
            assert exists(sentinel)
            # simulate work
            open(join(fn, "dummy.txt"), "w").close()
        # work file should be deleted together with directory
        assert not exists(fn)
        assert not exists(join(basedir, "foo"))
        # basedir should still exist, though!
        assert isdir(basedir)
    finally:
        if isdir(basedir):
            shutil.rmtree(basedir)
Пример #3
0
def test_temp_dir():
    fn = "test_temp_dir"
    if os.path.exists(fn):
        print("Path %s exists, not running test_temp_dir()" % fn)
        return
    try:
        assert not os.path.exists(fn)
        with temp_dir(fn):
            assert os.path.exists(fn)
        assert os.path.exists(fn)
        os.rmdir(fn)

        assert not os.path.exists(fn)
        with temp_dir(fn, erase_after=True):
            assert os.path.exists(fn)
        assert not os.path.exists(fn)
    finally:
        if os.path.isdir(fn):
            os.rmdir(fn)
Пример #4
0
def test_temp_dir():
    fn = "test_temp_dir"
    if os.path.exists(fn):
        print("Path %s exists, not running test_temp_dir()" % fn)
        return
    try:
        assert not os.path.exists(fn)
        with temp_dir(fn):
            assert os.path.exists(fn)
        assert os.path.exists(fn)
        os.rmdir(fn)

        assert not os.path.exists(fn)
        with temp_dir(fn, erase_after=True):
            assert os.path.exists(fn)
        assert not os.path.exists(fn)
    finally:
        if os.path.isdir(fn):
            os.rmdir(fn)
Пример #5
0
def test_temp_dir_pardir():
    with temp_dir("../test_temp_dir"):
        pass
Пример #6
0
def test_temp_dir_pardir():
    with temp_dir("../test_temp_dir"):
        pass