Repository navigation
scripted-diff: replace bare assert == with assert_equal in functional tests - #34761
Bortlesboat wants to merge 2 commits into
Conversation
|
♻️ Automatically closing for now based on heuristics. Please leave a comment, if this was erroneous. 📝 Moderators: If this is spam, please replace the title with |
|
This was specifically requested by @l0rinc in #34753:
I closed #34752 and #34753 and consolidated them into this single scripted-diff as suggested. The verify script reproduces the diff exactly. Could this be reopened? |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste |
|
Let's open it again, I want to review this. |
|
not sure if i am able to reopen it or the @DrahtBot needs to |
1f4a62b to
9631d40
Compare
There was a problem hiding this comment.
Approach NACK
Lots of tests are failing, it's obvious you haven't even tried it locally:
feature_fee_estimation.py | ✖ Failed | 250 s
feature_posix_fs_permissions.py | ✖ Failed | 1 s
feature_reindex.py | ✖ Failed | 38 s
feature_reindex_readonly.py | ✖ Failed | 2 s
mempool_updatefromblock.py | ✖ Failed | 282 s
mining_getblocktemplate_longpoll.py | ✖ Failed | 2 s
p2p_handshake.py | ✖ Failed | 3 s
p2p_handshake.py --v2transport | ✖ Failed | 3 s
p2p_headers_sync_with_minchainwork.py | ✖ Failed | 228 s
p2p_invalid_tx.py --v1transport | ✖ Failed | 5 s
p2p_invalid_tx.py --v2transport | ✖ Failed | 5 s
wallet_disable.py | ✖ Failed | 1 s Now that's I've spent time with this, I will push an alternative PR instead of babysitting this one.
There was a problem hiding this comment.
sed -i --regexp-extended '/ or /b; / and /b; / #/b; / for /b; s/^(\s*)assert ([^,][^=!<>]) == ([^,])$/\1assert_equal(\2, \3)/' $(git grep -l 'assert .* == ' -- 'test/functional/' ':(exclude)test/functional/test_framework/')
The point of the scripted diff is to help the reviewer be more confident in the changes.
This vibe-regex doesn't help me with that.
But we should be able to do it in two commits instead: the first one covering the values that a simple regex cannot reliably detect (e.g. because of complicated formatting or new imports). The second commit could be a simple regex via sed/grep/python for the remaining trivial cases.
There was a problem hiding this comment.
Good call — restructured into two commits:
- Manual commit: adds imports, converts lines with spaces in operands, inline comments, list/bytes literals (17 conversions)
- Scripted-diff using
\S+— only matches single-token operands, so no exclusion heuristics needed:
sed -i --regexp-extended 's/^(\s*)assert (\S+) == (\S+)$/\1assert_equal(\2, \3)/' \
$(git grep -l 'assert [^ ]* == [^ ]*$' -- 'test/functional/' ':(exclude)test/functional/test_framework/')
| @@ -22,12 +22,12 @@ def skip_test_if_missing_module(self): | |||
| def check_directory_permissions(self, dir): | |||
| mode = os.lstat(dir).st_mode | |||
| self.log.info(f"{stat.filemode(mode)} {dir}") | |||
| assert mode == (stat.S_IFDIR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) | |||
| assert_equal(mode, (stat.S_IFDIR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)) | |||
There was a problem hiding this comment.
Have you tried this locally? This is missing a from test_framework.util import assert_equal
There was a problem hiding this comment.
Fixed — added the missing import. All 6 files that needed new assert_equal imports are handled in commit 1 now. Verified with py_compile across all 30 changed files.
…matting Convert assert == to assert_equal() for cases that cannot be handled by a simple scripted-diff regex: - Add assert_equal import to 6 files that were missing it - Convert lines with spaces in operands (arithmetic, bitwise, stat flags) - Convert lines with inline comments (preserving the comments) - Convert lines with list/bytes literals containing commas or spaces Lines with assertion messages, compound conditions (and/or), and comprehensions are intentionally left unchanged.
… tests Replace remaining simple assert x == y with assert_equal(x, y) for better failure diagnostics. Only matches single-token operands (no spaces), so compound expressions, assertion messages, and inline comments are unaffected. -BEGIN VERIFY SCRIPT- sed -i --regexp-extended 's/^(\s*)assert (\S+) == (\S+)$/\1assert_equal(\2, \3)/' $(git grep -l 'assert [^ ]* == [^ ]*$' -- 'test/functional/' ':(exclude)test/functional/test_framework/') -END VERIFY SCRIPT-
9631d40 to
04a8cb6
Compare
|
Force-pushed with the two-commit approach: Commit 1 (manual): Adds Commit 2 (scripted-diff): Uses 72 conversions across 25 files in the scripted-diff, 17 manual conversions in commit 1. Lines with assertion messages, Sorry for the noise on the earlier pushes — should have caught the missing imports before pushing. |
|
Maybe try to review some other pull requests locally first before contributing a change yourself. You are required to run the tests and understand what they in the context of your change before opening a pull request. We generally also don't accept trivial refactoring PRs from fresh contributors, see the contributing guidelines: https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#refactoring . |
Replace bare
assert x == ywithassert_equal(x, y)across functional test files for better failure diagnostics.Split into two commits per review feedback from @l0rinc:
Manual commit (17 conversions, 14 files): Handles cases requiring new imports (6 files) or complex formatting (spaces in operands, inline comments, list/bytes literals).
Scripted-diff commit (72 conversions, 25 files): Simple
\S+regex matches only single-token operands — no risk of mishandling compound expressions, messages, or comments.Lines with assertion messages,
and/orcompound conditions, and comprehensions are intentionally left unchanged.Consolidates the approach from #34752 and #34753 per feedback from @l0rinc.