test: Use pathlib over os path#28392
test: Use pathlib over os path#28392fanquake merged 1 commit intobitcoin:masterfrom nsvrn:tests_use_pathlib
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
https://cirrus-ci.com/task/5520063122374656: |
Thank you for pointing this out, seems like readlink was introduced in python 3.9 and we're using 3.8 here. I will fix that shortly. Secondly, it seems like this issue is causing 3 other failures as well but I will double check and once I fix this issue - is it ok for me to close this PR and open a new one because i will do a fresh fork and PR to make it cleaner (otherwise I can follow the squash commit instructions as per contribution guidelines). |
Links should be available via the "Checks" tab in this PR on the GitHub web-interface. Perhaps, a Cirrus CI account is required as well.
No need to close a PR and open another. The accepted routine is to update your local EDIT: While CI fails, you also might mark this PR as a draft. |
FYI: #28211 |
maflcko
left a comment
There was a problem hiding this comment.
Left some questions on the closed pull and here.
test/functional/wallet_backup.py
Outdated
There was a problem hiding this comment.
the original . here pathlib was resolving it to remove it whereas os.path was keeping it and since it was passing as strings I mixed this up thinking we're trying to fail one of these source paths but you're right, I switched it back to . and it works.
There was a problem hiding this comment.
If you are changing the behavior of a test, for example removing test coverage or changing it, it would be good to leave as-is for now. There is no need to remove all use of os.path.join. The main goal should be to remove the TestNode.datadir method
test/functional/wallet_backup.py
Outdated
There was a problem hiding this comment.
Is this needed? RPC methods should be able to be passed pathlib paths.
There was a problem hiding this comment.
you're correct, removed
test/functional/feature_addrman.py
Outdated
There was a problem hiding this comment.
nit: Is this change needed? Seems better to just leave as-is if there is no reason to change?
There was a problem hiding this comment.
ya i think in python3 both pathlib and os open use io.open so no difference, in general my thought was to remove import os from files so that there's an extra step of adding the import is involved in using os.path.join in the code just as a deterrent but ya I will revert this one.
EDIT: never mind, open is available without import os so what I said i is incorrect
There was a problem hiding this comment.
open is a built-in, not os.open, so I don't think this affects os imports at all.
test/functional/combine_logs.py
Outdated
There was a problem hiding this comment.
nit: Not sure if it makes sense to change this. Either logfile is a Path to begin with and is using the Path interface throughout, or it isn't. Converting a string to Path just to call is_file on it doesn't seem to add any value, does it? My preference for this pull would be to focus on removing the TestNode.datadir helper only.
maflcko
left a comment
There was a problem hiding this comment.
Not sure about the random Path constructors inserted, which clutter the code. I think it would be easier to review if no new Path constructor was added.
test/functional/combine_logs.py
Outdated
There was a problem hiding this comment.
basename is a str already, no? Seems odd to change this
test/functional/wallet_signer.py
Outdated
There was a problem hiding this comment.
Not sure if this makes sense. Either cwd is a Path to begin with, but wrapping a str into Path for no benefit, seems not worth it.
For now, my preference would be to focus on removing TestNode.datadir only.
test/functional/feature_settings.py
Outdated
There was a problem hiding this comment.
| conf = Path(node.datadir_path, "bitcoin.conf") | |
| conf = node.datadir_path / "bitcoin.conf" |
nit: This is already a path, so no need to run a no-op on it again.
test/functional/feature_settings.py
Outdated
There was a problem hiding this comment.
| "-datadir=" + str(self.datadir_path), | |
| f"-datadir={self.datadir_path}", |
There was a problem hiding this comment.
| return pathlib.Path(dirname) / f"node{n}" | |
| return pathlib.Path(dirname) / f"node{n}" |
There was a problem hiding this comment.
May be better to just fixup the send_cli method?
|
If you are done with the changes and confident in them, you can take this pull out of draft. |
|
@ns-xvrn when you rebase this, can you update the commit message to drop all the now-redundant messages from your previously squashed commits? i.e we don't things like "reversions after PR review" included in the commit message. |
maflcko
left a comment
There was a problem hiding this comment.
I think you'll have to rebase on current master. Otherwise:
Nice, lgtm ACK 12c8a210fe8a9e1e4cce95e719da0728a53866ef 🔊
Show signature
Signature:
untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: Nice, lgtm ACK 12c8a210fe8a9e1e4cce95e719da0728a53866ef 🔊
nRLN+xBFTudmjfgANKjDSiWaCvK/pfswAHKlWzf8NyiteLNzZhGP6l2wiZzab1v8twadrnY1ETOCUR7oAGDtDA==
|
Thanks, you'll need to update |
revert netutil chgs py3.8 compliant fixes based on PR review
|
re-ACK bfa0bd6 🐨 Show signatureSignature: |
willcl-ark
left a comment
There was a problem hiding this comment.
ACK bfa0bd6
Changes look good to me. I ran a few quick greps to try and find any places that this had been missed but couldn't find any.
I did spot one or two changed lines where we could have taken the opportunity to switch to format strings from .format(), along with switching to double-quoted strings (which, if I am correct we are preferring and switching to?), but not relevant to the correctness of these changes.
In reference to issue #28362 refactoring of functional tests to use pathlib over os.path to reduce verbosity and increase the intuitiveness of managing file access.