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
test: Use test framework utils in functional tests #28528
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. |
Though the change is simple, it touches a ton of files. I can break it into multiple PRs if that makes sense. |
@theStack Added you as reviewer/mentor, because the issue was opened by you |
@osagie98: Can you squash the commits and rebase on master? Happy to review. |
1163d61
to
995cc47
Compare
@theStack done (I hope, still getting used to the GitHub workflow). Let me know if you'll need anything else |
995cc47
to
ad6d9e2
Compare
Yes, planning to (finally) review this within the next 1-2 days. |
@@ -226,7 +228,7 @@ def _test_coin_stats_index(self): | |||
|
|||
self.generate(index_node, 1, sync_fun=self.no_op) | |||
res10 = index_node.gettxoutsetinfo('muhash') | |||
assert res8['txouts'] < res10['txouts'] | |||
assert_greater_than(res10['txouts'], res8['txouts']) |
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.
I noticed that here (and at some other places), assert x < y
is replaced by assert_greater_than(y, x)
rather than the more obvious assert_less_than(x, y)
. Is that change intentional or is that a left-over from an earlier version, when assert_less_than
was not introduced yet?
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.
Yes, early on I kept only assert_greater_than()
before I decided that assert_less_than()
was needed. I can go back and fix those to make it clear.
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.
Done. Force pushed to allow for the rebase.
8f00a52
to
146d75c
Compare
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.
Concept ACK
This PR improves functional tests (readability) by using/introducing complimentary util functions to assert
ie assert_equal
, assert_not_equal
, assert_less_than
, assert_less_than_or_equal
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.
There are still some instances of bare assert which could be replaced by the helpers such as in rpc_psbt.py
, wallet_disable.py
is this intentional?
Replaces bare asserts with test framework utils across both the functional tests and the test framework itself. Also adds the `assert_not_equal`, `assert_less_than`, and `assert_less_than_or_equal` util functions for greater readability. Fixes bitcoin#23119.
146d75c
to
2103e12
Compare
Hi @BrandonOdiwuor, Sorry, I missed the notification of your messages. I missed a few asserts, so I went back to add them. I also initially chose not to change any Please take another look whenever you're free, thank you! |
@@ -275,7 +276,8 @@ def signing_test( | |||
self.wait_until(lambda: txid in self.funder.getrawmempool()) | |||
self.funder.generatetoaddress(1, self.funder.getnewaddress()) | |||
utxo = self.ms_sig_wallet.listunspent(addresses=[addr])[0] | |||
assert txid == utxo["txid"] and utxo["solvable"] | |||
assert_equal(txid == utxo["txid"]) |
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.
assert_equal(txid == utxo["txid"]) | |
assert_equal(txid, utxo["txid"]) |
@@ -67,6 +72,16 @@ def assert_greater_than_or_equal(thing1, thing2): | |||
raise AssertionError("%s < %s" % (str(thing1), str(thing2))) | |||
|
|||
|
|||
def assert_less_than(thing1, thing2): | |||
if thing1 >= thing2: | |||
raise AssertionError("%s .= %s" % (str(thing1), str(thing2))) |
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.
2103e12: here and for assert_less_than_or_equal
too.
raise AssertionError("%s .= %s" % (str(thing1), str(thing2))) | |
raise AssertionError("%s >= %s" % (str(thing1), str(thing2))) |
@@ -57,6 +57,11 @@ def assert_equal(thing1, thing2, *args): | |||
raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args)) | |||
|
|||
|
|||
def assert_not_equal(thing1, thing2, *args): |
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.
2103e12: maybe just have assert_not_equal(thing1, thing2)
. i couldn't find an occurrence where we needed to assert_not_equal
3+ things. ex: assert_not_equal(2, 2, 3)
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.
i think you can find more places where assert_not_equal
can be used using the command @theStack mentioned here!
example first 3 lines output:
$ git grep "assert ".*\!=
feature_fee_estimation.py: assert fee_dat_current_content != fee_dat_initial_content
feature_fee_estimation.py: assert fee_dat_current_content != fee_dat_initial_content
mempool_accept_wtxid.py: assert child_one_wtxid != child_two_wtxid
🐙 This pull request conflicts with the target branch and needs rebase. |
Closing for now due to inactivity. I think it is pretty clear that a change like this won't be going in in one go. If someone wants to try this again, I'd recommend to try a smaller portion and see if reviewers like it. If not, then maybe it isn't worth changing? |
Replaces bare asserts with test framework utils across both the functional tests and the test framework itself.
Also adds the
assert_not_equal
,assert_less_than
, andassert_less_than_or_equal
util functions for greater readability.Fixes #23119.