-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate tests to use pathlib.Path #11170
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I'm +1 on this. I'm going to assume that if the tests pass it's probably OK.
I did start reading through, and made a couple of comments, but I lost the will to live with all those str calls 🙂 Also, black reformattings make the diffs a bit harder to skim. I wouldn't bother doing it now1, but splitting the commit into (1) mechanical str changes, (2) black reformattings and (3) substantial changes, might hae made it easier to review.
I added a couple of suggestions, but they aren't critical - feel free to treat them as matters of opinion and stick with what you have.
Footnotes
-
And to be 100% clear, if I'd been doing this PR I would never have thought of doing this either... ↩
tests/functional/test_freeze.py
Outdated
direct_url_path = get_created_direct_url_path(result, "testpkg") | ||
assert direct_url_path | ||
# patch direct_url.json to simulate an editable install | ||
with open(direct_url_path) as f: | ||
direct_url = DirectUrl.from_json(f.read()) | ||
direct_url = DirectUrl.from_json(direct_url_path.read_text()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to the Path
change, but shouldn't we specify an encoding here? (And below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @sbidoul I’m not sure if platform-dependant encoding is intended here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is was not intended, no. I'll do a PR to fix this (it should not matter much for the tests in practice but I spotted one place in the code where it could be an issue).
eaa2503
to
1b0e0be
Compare
cf2047e
to
5799151
Compare
Hurray! Thanks for picking this up @uranusjr! ^.^ |
04941e1
to
eb75460
Compare
The pip-specific Path implementation has been removed, and all its usages replaced by pathlib.Path. The tmpdir and tmpdir_factory fixtures are also removed, and all usages are replaced by tmp_path and tmp_path_factory, which use pathlib.Path. The pip() function now also accepts pathlib.Path so we don't need to put str() everywhere. Path arguments are coerced with os.fspath() into str.
Hmm, a couple of failing tests that I can’t figure out. They pass on my machine, and this PR doesn’t even touch those.
|
@uranusjr I can reproduce on Linux with With 3.7, the pip freeze --all output is
so there is With 3.8 the pip freeze output is similar to what we have in the CI log
so here we have no That is super weird. Would the We could fix the test with |
Ah interesting. So in a sense the test is wrong—the behaviour they intend to test was broken by #5031 (before it I suspect the behaviour change is due to |
Found the exact bugfix that changed behaviour: python/cpython#83571 This can be fixed by using |
This resolves a behavioral different between Python 3.7 and 3.8+, where a == comparison would incorrectly compare Path against str and cause incorrect results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this!
🎉 |
@@ -171,7 +170,7 @@ def _customize_site(self) -> None: | |||
def clear(self) -> None: | |||
self._create(clear=True) | |||
|
|||
def move(self, location: str) -> None: | |||
def move(self, location: Union[Path, str]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error: Argument 1 to "move" has incompatible type "Path"; expected "str"
see: https://github.com/python/typeshed/blob/91d6383d9d1ca38157ce46bb498a11347658db1d/stdlib/shutil.pyi#L105
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it seems PathLike support here was only added in 3.9, and pre-commit missed this since we only run linters against the newest Python version.
I was annoyed enough to spend a day on this.
The pip-specific
Path
implementation has been removed, and all its usages replaced bypathlib.Path
. Thetmpdir
andtmpdir_factory
fixtures are also removed, and all usages replaced bytmp_path
andtmp_path_factory
, which use pathlib.Path.As anyone might expect, the bulk of the work is simply adding
str()
everywhere.