Replace py.path.local usages by pathlib.Path

This commit is contained in:
Bruno Oliveira
2022-10-21 22:09:38 -03:00
parent f04cd22fd6
commit 25cc1a4119
10 changed files with 121 additions and 73 deletions

View File

@@ -1,4 +1,6 @@
import py
import unittest.mock
from typing import List
import pytest
import shutil
import textwrap
@@ -16,7 +18,7 @@ class TestStatRecorder:
tmp = tmp_path
hello = tmp / "hello.py"
hello.touch()
sd = StatRecorder([py.path.local(tmp)])
sd = StatRecorder([tmp])
changed = sd.check()
assert not changed
@@ -56,15 +58,12 @@ class TestStatRecorder:
tmp = tmp_path
tmp.joinpath("dir").mkdir()
tmp.joinpath("dir", "hello.py").touch()
sd = StatRecorder([py.path.local(tmp)])
assert not sd.fil(py.path.local(tmp / "dir"))
sd = StatRecorder([tmp])
assert not sd.fil(tmp / "dir")
def test_filechange_deletion_race(
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
def test_filechange_deletion_race(self, tmp_path: Path) -> None:
tmp = tmp_path
pytmp = py.path.local(tmp)
sd = StatRecorder([pytmp])
sd = StatRecorder([tmp])
changed = sd.check()
assert not changed
@@ -76,16 +75,20 @@ class TestStatRecorder:
p.unlink()
# make check()'s visit() call return our just removed
# path as if we were in a race condition
monkeypatch.setattr(pytmp, "visit", lambda *args: [py.path.local(p)])
changed = sd.check()
dirname = str(tmp)
dirnames: List[str] = []
filenames = [str(p)]
with unittest.mock.patch(
"os.walk", return_value=[(dirname, dirnames, filenames)], autospec=True
):
changed = sd.check()
assert changed
def test_pycremoval(self, tmp_path: Path) -> None:
tmp = tmp_path
hello = tmp / "hello.py"
hello.touch()
sd = StatRecorder([py.path.local(tmp)])
sd = StatRecorder([tmp])
changed = sd.check()
assert not changed
@@ -100,7 +103,7 @@ class TestStatRecorder:
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
tmp = tmp_path
sd = StatRecorder([py.path.local(tmp)])
sd = StatRecorder([tmp])
ret_values = [True, False]
monkeypatch.setattr(StatRecorder, "check", lambda self: ret_values.pop())

View File

@@ -1,5 +1,4 @@
import pprint
import py
import pytest
import sys
import uuid
@@ -108,7 +107,7 @@ class TestWorkerInteractor:
assert ev.name == "collectionstart"
assert not ev.kwargs
ev = worker.popevent("collectionfinish")
assert ev.kwargs["topdir"] == py.path.local(worker.pytester.path)
assert ev.kwargs["topdir"] == str(worker.pytester.path)
ids = ev.kwargs["ids"]
assert len(ids) == 1
worker.sendcommand("runtests", indices=list(range(len(ids))))

View File

@@ -1,5 +1,4 @@
import execnet
import py
import pytest
import shutil
import textwrap
@@ -7,6 +6,7 @@ import warnings
from pathlib import Path
from util import generate_warning
from xdist import workermanage
from xdist._path import visit_path
from xdist.remote import serialize_warning_message
from xdist.workermanage import HostRSync, NodeManager, unserialize_warning_message
@@ -157,12 +157,9 @@ class TestHRSync:
source.joinpath("somedir").mkdir()
source.joinpath("somedir", "editfile~").touch()
syncer = HostRSync(source, ignores=NodeManager.DEFAULT_IGNORES)
files = list(py.path.local(source).visit(rec=syncer.filter, fil=syncer.filter))
assert len(files) == 3
basenames = [x.basename for x in files]
assert "dir" in basenames
assert "file.txt" in basenames
assert "somedir" in basenames
files = list(visit_path(source, recurse=syncer.filter, filter=syncer.filter))
names = {x.name for x in files}
assert names == {"dir", "file.txt", "somedir"}
def test_hrsync_one_host(self, source: Path, dest: Path) -> None:
gw = execnet.makegateway("popen//chdir=%s" % dest)