Repository navigation
qa: assert_equal -> assert_true/assert_false - #36257
hodlinator wants to merge 6 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process. 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. |
l0rinc
left a comment
There was a problem hiding this comment.
I don't mind the change, the only reason I see to use explicit True and False is to flip these after a characterization test - but they could also flip the method name.
Based on https://mirror.b10c.me/bitcoin-bitcoin/34773#discussion_r3009767675 and https://mirror.b10c.me/bitcoin-bitcoin/34773#discussion_r3009771746, @maflcko might be interested.
14ed48a to
01ff43d
Compare
hodlinator
left a comment
There was a problem hiding this comment.
I don't mind the change, the only reason I see to use explicit
TrueandFalseis to flip these after a characterization test - but they could also flip the method name.
It was reviewing your characterization test flipping which made me flip and implement this. :)
This isn't wrong, but seems to be missing the point: The reason why assert_equal with So the only real remaining motivation for this is to reduce code bloat. No objection, but overall I am ~0 on this. |
|
Thanks for having a look @maflcko. Re-orged the PR desc to add the truthyness nuance of |
01ff43d to
77e6026
Compare
d43be21 to
cada9cf
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
Agree both are very low-priority, but it seems quite subjective which one is more useful (abbreviating the names of functions vs removing begging-the-question tokens (equals ...to arbitrarily long expression ... Liked how that PR added a guard in the scripted diff against the new names, added a commit here doing the same before introducing the new functions. |
cada9cf to
772a560
Compare
-BEGIN VERIFY SCRIPT- git grep -E "\b(assert_true|assert_false)\b" -- test/functional && echo "Error: Target names already exist" >&2 && exit 1 || exit 0 -END VERIFY SCRIPT-
Before 2ef6679 introduced finalized2 we had: assert_equal(finalized["complete"], True) ...so this is changing things back towards that.
…ssert_true/assert_false -BEGIN VERIFY SCRIPT- sed -i -E "s/assert_equal\((.*)\, (True|False)\)( *(#.*))?$/assert_\L\2(\E\1)\3/g" $( git grep -lE "assert_equal\(.*, (True|False)\)" -- test/functional/ ) sed -i -E "s/assert_equal\((True|False), (.*)$/assert_\L\1\E\(\2/g" $( git grep -lE "assert_equal\((True|False)" -- test/functional/ ) -END VERIFY SCRIPT-
772a560 to
f1196fb
Compare
| from test_framework.test_framework import BitcoinTestFramework | ||
| from test_framework.test_node import ErrorMatch | ||
| from test_framework.util import assert_equal | ||
| from test_framework.util import assert_equal, assert_false, assert_true |
|
@maflcko I checked your approach in #35139, where you only have |
|
I don't think #35139 is going to make it any time soon, it is marked as DRAFT , mostly meant as a tracking issue for the bugs, but maybe I should close it. Also, for reference it has
Personally, I sometimes use |
Yes, I'm all for keeping
One could create a scripted diff for switching existing cases of |

Instead of this in the functional tests:
we get:
The main point of this change is that
assert_true()/assert_false()reduce cognitive tokens when scanning the code (equals to what...?). (As a consequence,assert_true()/assert_false()are also common in other test frameworks).assert_equal()continues to be used in cases where we don't compare to boolean literals.assert_true([expression])is different from plainassert [expression]in thatassertis truthy whileassert_truerequires booleanTrue. (assertcan also be deactivated when executing Python code in optimized mode (see #30529 (comment))).A smaller scale attempt at introducing
assert_true()was originally included in #31874 before being dropped.