示例#1
0
    def test_cleanup_lock_create(self, tmp_path):
        d = tmp_path.joinpath("test")
        d.mkdir()
        lockfile = create_cleanup_lock(d)
        with pytest.raises(OSError, match="cannot create lockfile in .*"):
            create_cleanup_lock(d)

        lockfile.unlink()
示例#2
0
    def test_cleanup_locked(self, tmp_path):
        p = make_numbered_dir(root=tmp_path, prefix=self.PREFIX)

        create_cleanup_lock(p)

        assert not pathlib.ensure_deletable(
            p, consider_lock_dead_if_created_before=p.stat().st_mtime - 1)
        assert pathlib.ensure_deletable(
            p, consider_lock_dead_if_created_before=p.stat().st_mtime + 1)
示例#3
0
    def test_cleanup_lock_create(self, tmp_path):
        d = tmp_path.joinpath("test")
        d.mkdir()
        from _pytest.pathlib import create_cleanup_lock

        lockfile = create_cleanup_lock(d)
        with pytest.raises(EnvironmentError, match="cannot create lockfile in .*"):
            create_cleanup_lock(d)

        lockfile.unlink()
示例#4
0
    def test_cleanup_lock_create(self, tmp_path):
        d = tmp_path.joinpath("test")
        d.mkdir()
        from _pytest.pathlib import create_cleanup_lock

        lockfile = create_cleanup_lock(d)
        with pytest.raises(EnvironmentError, match="cannot create lockfile in .*"):
            create_cleanup_lock(d)

        lockfile.unlink()
示例#5
0
    def test_cleanup_locked(self, tmp_path):

        from _pytest import pathlib

        p = pathlib.make_numbered_dir(root=tmp_path, prefix=self.PREFIX)

        pathlib.create_cleanup_lock(p)

        assert not pathlib.ensure_deletable(
            p, consider_lock_dead_if_created_before=p.stat().st_mtime - 1
        )
        assert pathlib.ensure_deletable(
            p, consider_lock_dead_if_created_before=p.stat().st_mtime + 1
        )
示例#6
0
    def test_lock_register_cleanup_removal(self, tmp_path: Path) -> None:
        lock = create_cleanup_lock(tmp_path)

        registry: List[Callable[..., None]] = []
        register_cleanup_lock_removal(lock, register=registry.append)

        (cleanup_func, ) = registry

        assert lock.is_file()

        cleanup_func(original_pid="intentionally_different")

        assert lock.is_file()

        cleanup_func()

        assert not lock.exists()

        cleanup_func()

        assert not lock.exists()
示例#7
0
    def test_lock_register_cleanup_removal(self, tmp_path):
        from _pytest.pathlib import create_cleanup_lock, register_cleanup_lock_removal

        lock = create_cleanup_lock(tmp_path)

        registry = []
        register_cleanup_lock_removal(lock, register=registry.append)

        cleanup_func, = registry

        assert lock.is_file()

        cleanup_func(original_pid="intentionally_different")

        assert lock.is_file()

        cleanup_func()

        assert not lock.exists()

        cleanup_func()

        assert not lock.exists()
示例#8
0
    def test_lock_register_cleanup_removal(self, tmp_path):
        from _pytest.pathlib import create_cleanup_lock, register_cleanup_lock_removal

        lock = create_cleanup_lock(tmp_path)

        registry = []
        register_cleanup_lock_removal(lock, register=registry.append)

        cleanup_func, = registry

        assert lock.is_file()

        cleanup_func(original_pid="intentionally_different")

        assert lock.is_file()

        cleanup_func()

        assert not lock.exists()

        cleanup_func()

        assert not lock.exists()
示例#9
0
 def test_removal_accepts_lock(self, tmp_path):
     folder = make_numbered_dir(root=tmp_path, prefix=self.PREFIX)
     create_cleanup_lock(folder)
     maybe_delete_a_numbered_dir(folder)
     assert folder.is_dir()
示例#10
0
 def test_removal_accepts_lock(self, tmp_path):
     folder = pathlib.make_numbered_dir(root=tmp_path, prefix=self.PREFIX)
     pathlib.create_cleanup_lock(folder)
     pathlib.maybe_delete_a_numbered_dir(folder)
     assert folder.is_dir()