vincenzopalazzo
commented at 7:36 am on September 29, 2021:
none
This PR removes when it is possible the native python assert, and use the test utils function, like assert_equal, assert_greater_than, assert_greater_than_or_equal.
Update
In addition, this PR includes a new operator assert_not_equal, which IMO it is useful to test other conditions and add the error message as a parameter of the function to give more flexibility.
Thanks, the important think it that we don’t make the double work :-)
vincenzopalazzo force-pushed
on Sep 29, 2021
vincenzopalazzo force-pushed
on Sep 29, 2021
vincenzopalazzo requested review from meshcollider
on Sep 29, 2021
DrahtBot
commented at 5:29 pm on September 29, 2021:
contributor
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Conflicts
Reviewers, this pull request conflicts with the following ones:
#25732 (tests: Use test utils each time that it is possible by vincenzopalazzo)
#25291 (test: Refactor rpc_fundrawtransaction.py by akankshakashyap)
#23502 (wallet: Avoid underpaying transaction fees when signing taproot spends by achow101)
#20892 (tests: Run both descriptor and legacy tests within a single test invocation by achow101)
#17794 (test: Use assert_greater_than_or_equal helper method to aid debugging. by jbampton)
#16545 (refactor: Implement missing error checking for ArgsManager flags by ryanofsky)
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.
vincenzopalazzo force-pushed
on Sep 29, 2021
vincenzopalazzo force-pushed
on Sep 30, 2021
vincenzopalazzo force-pushed
on Oct 2, 2021
vincenzopalazzo force-pushed
on Oct 3, 2021
michaelfolkson
commented at 10:02 am on October 4, 2021:
contributor
In this case splitting across multiple commits within the same PR would probably have been sufficient to make it easily reviewable but not a big deal and if it encourages multiple contributors to self-organize around completing it then that’s great.
in
test/functional/test_framework/util.py:54
in
80c593f4ecoutdated
49@@ -50,6 +50,11 @@ def assert_equal(thing1, thing2, *args):
50 raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
515253+def assert_not_equal(thing1, thing2, *args):
54+ if thing1 == thing2 or any(thing1 != arg for arg in args):
In this case splitting across multiple commits within the same PR would probably have been sufficient to make it easily reviewable but not a big deal and if it encourages multiple contributors to self-organize around completing it then that’s great.
It sounds great to me, I will go with this solution. Thansk!
vincenzopalazzo force-pushed
on Oct 5, 2021
vincenzopalazzo force-pushed
on Oct 5, 2021
vincenzopalazzo force-pushed
on Oct 10, 2021
vincenzopalazzo force-pushed
on Oct 10, 2021
dougEfresh
commented at 11:52 am on October 22, 2021:
contributor
stratospher
commented at 6:36 pm on October 27, 2021:
It’d be nice if the typo is fixed in this commit itself since each commit should compile and work independently.
vincenzopalazzo force-pushed
on Oct 28, 2021
vincenzopalazzo force-pushed
on Oct 28, 2021
brunoerg
commented at 12:31 pm on October 29, 2021:
contributor
Ready for review?
vincenzopalazzo
commented at 12:56 pm on October 29, 2021:
none
Ready for review?
All the commit for the moment yes, I need to finish other files in the next week, but until now yes, it is ready
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo renamed this:
tests: Use assert_equal* utils where possible
tests: Use test framework utils where possible
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 2, 2021
vincenzopalazzo force-pushed
on Nov 4, 2021
vincenzopalazzo force-pushed
on Nov 5, 2021
vincenzopalazzo force-pushed
on Nov 5, 2021
vincenzopalazzo force-pushed
on Nov 6, 2021
vincenzopalazzo force-pushed
on Nov 6, 2021
vincenzopalazzo force-pushed
on Nov 6, 2021
vincenzopalazzo force-pushed
on Nov 6, 2021
vincenzopalazzo force-pushed
on Nov 8, 2021
vincenzopalazzo force-pushed
on Nov 9, 2021
DrahtBot added the label
Needs rebase
on Nov 15, 2021
vincenzopalazzo force-pushed
on Nov 15, 2021
DrahtBot removed the label
Needs rebase
on Nov 15, 2021
vincenzopalazzo force-pushed
on Nov 15, 2021
DrahtBot added the label
Needs rebase
on Nov 16, 2021
vincenzopalazzo force-pushed
on Nov 16, 2021
DrahtBot removed the label
Needs rebase
on Nov 16, 2021
DrahtBot added the label
Needs rebase
on Nov 17, 2021
vincenzopalazzo force-pushed
on Nov 27, 2021
DrahtBot removed the label
Needs rebase
on Nov 27, 2021
vincenzopalazzo force-pushed
on Dec 6, 2021
laanwj
commented at 3:28 pm on December 13, 2021:
member
Concept ACK9edb3cc5d08caaf61ff00c49a698956f4ddaba08, looked over the commits briefly and a) didn’t find any mistakes b) checked the changes are contained to where they should be
though I haven’t reviewed the huge list of changes in detail so can’t warrant calling it a full code review ACK.
vincenzopalazzo
commented at 3:38 pm on December 13, 2021:
none
though I haven’t reviewed the huge list of changes in detail so can’t warrant calling it a full code review ACK.
Sorry about that, I should add some tips on the PR. However, there is only a critical change in the test utils framework, now all the assert support the error message as the parameter this only because we can support also custom message defined with assert False, "always false"
laanwj
commented at 3:52 pm on December 13, 2021:
member
Sorry about that, I should add some tips on the PR.
I think you misunderstood: It was not a comment on your work. I meant that I can’t call what I did a full code review. I should look in more detail, though generally getting the type of assert wrong will usually just result in the tests failing, so I’m reasonably confident in the correctness of the changes.
michaelfolkson
commented at 4:14 pm on December 13, 2021:
contributor
I think generally splitting across multiple pull requests works best for the monster sub-projects (AssumeUTXO, deglobalizing ChainstateManager, Process Separation etc).
I know I’ve previously said this (so apologies if this wasn’t helpful at the time) but I think the PR has got sufficiently big that a PR or two could maybe be spun out of this one to make it easier to review.
I also think the structure of commits could be improved, having a separate commit for each file doesn’t make much sense to me. Also the commit messages aren’t particularly informative for reviewers.
Commit messages such as “Define new assert functions in test utils”, “Replace assert with assert_equal across functional test suite” and “Use assert_greater_than instead of greater than asserts” would be more helpful than “filename.py: Use test framework”.
Reviewers can see what files are changed without looking at commit messages, what they want to see with the commit messages is what the commit is doing.
vincenzopalazzo force-pushed
on Dec 21, 2021
DrahtBot added the label
Needs rebase
on Dec 28, 2021
vincenzopalazzo force-pushed
on Dec 28, 2021
DrahtBot removed the label
Needs rebase
on Dec 28, 2021
elmarsan
commented at 5:16 pm on December 29, 2021:
none
I think generally splitting across multiple pull requests works best for the monster sub-projects (AssumeUTXO, deglobalizing ChainstateManager, Process Separation etc).
I know I’ve previously said this (so apologies if this wasn’t helpful at the time) but I think the PR has got sufficiently big that a PR or two could maybe be spun out of this one to make it easier to review.
I also think the structure of commits could be improved, having a separate commit for each file doesn’t make much sense to me. Also the commit messages aren’t particularly informative for reviewers.
Commit messages such as “Define new assert functions in test utils”, “Replace assert with assert_equal across functional test suite” and “Use assert_greater_than instead of greater than asserts” would be more helpful than “filename.py: Use test framework”.
Reviewers can see what files are changed without looking at commit messages, what they want to see with the commit messages is what the commit is doing.
Hey, I agree with you.
Maybe this pull request could be splitted into three different ones.
For example: one pull request per each assertion type to refactor assert_equal, assert_greater_than and assert_greater_than_or_equal
I’d would like to help with the reviews!
vincenzopalazzo
commented at 6:58 pm on December 29, 2021:
none
Maybe this pull request could be splitted into three different ones.
For example: one pull request per each assertion type to refactor assert_equal, assert_greater_than and
Each following step required the same trade-off with only personal preference, if you split the PR in more PRs, you have more work to do, and so on.
The change is not only in the change of the assert tp assert_* but this PR includes also some change inside the test framework, now the method accepts also an optional parameter err_msg
This required a big pr that include this change too.
In conclusion, I agree that small PR can be useful for other people, but at the end of the day, there is no real improvement inside the velocity of review.
This takes time, as with all types of refactoring. This time is chosen this way but the next time we can do in another way that we can set up before finish the work. Back in October, I chatted on IRC to choose which method is the best, so this is not my own choice.
vincenzopalazzo force-pushed
on Dec 30, 2021
vincenzopalazzo force-pushed
on Jan 9, 2022
in
test/functional/feature_segwit.py:48
in
38fe1453d4outdated
The only reason is to maintain consistency between error code format and code style. I usually try to avoid mixing different types of assert (from library and native assert) in the tests
MarcoFalke
commented at 7:08 am on January 15, 2022:
It is fine if you do this personally in your own projects, but for bitcoin-core this is impossible to maintain. Someone is going to break the consistency at some point. We can’t handle this if there are floods of follow-up pull requests. Also, if there is a linter to make lib assert illegal, it puts an unnecessary burden on developers for style reasons.
Mh I agree with the difficulty to add a change of style at this point on Bitcoin core, I only propose one way here and I’m super happy to revert the change and to have this great exchange of idea
in
test/functional/wallet_txn_doublespend.py:49
in
38fe1453d4outdated
45@@ -46,7 +46,7 @@ def run_test(self):
46 # blockchain sync later in the test when nodes are connected, due to
47 # timing issues.
48 for n in self.nodes:
49- assert n.getblockchaininfo()["initialblockdownload"] == False
50+ assert_equal(n.getblockchaininfo()["initialblockdownload"], False)
MarcoFalke
commented at 4:42 pm on January 13, 2022:
Seems there are too many ways to say the same thing. I think we shouldn’t be adding even more.
For boolean values, if the assertion fails, it is clear what value the bool was. There is no need to print the value and a constant.
Seems there are too many ways to say the same thing. I think we shouldn’t be adding even more.
Right, in this case, I use the assert_equal but I could use assert_true, and the reason that I used this is only for consistency across error messages and source code. However, if you like I can restore the pure assert
stickies-v
commented at 11:05 am on August 2, 2022:
For boolean values, if the assertion fails, it is clear what value the bool was. There is no need to print the value and a constant.
I’d agree in a statically typed environment, but in Python that doesn’t really hold? I think there’s merit in always printing the value, to more quickly debug cases where e.g. the type of a response changes or becomes None/empty string?
in
test/functional/feature_taproot.py:581
in
38fe1453d4outdated
591@@ -585,7 +592,7 @@ def bitflipper(expr):
592 """Return a callable that evaluates expr and returns it with a random bitflip."""
593 def fn(ctx):
594 sub = deep_eval(ctx, expr)
595- assert isinstance(sub, bytes)
596+ assert_true(isinstance(sub, bytes), err_msg="It is not a bytes instance")
niVelion
commented at 4:43 pm on January 13, 2022:
:eyes: The subject “it” here seems ambiguous, though I haven’t tried making this test fail to see whether it is.
Asserting prints the line where the error happens, right? The expression isinstance(sub, bytes) says it all, I don’t think any more information needs to be added here.
in
test/functional/feature_taproot.py:1295
in
38fe1453d4outdated
1290@@ -1284,15 +1291,16 @@ def block_submit(self, node, txs, msg, err_msg, cb_pubkey=None, fees=0, sigops_w
1291 block.solve()
1292 block_response = node.submitblock(block.serialize().hex())
1293 if err_msg is not None:
1294- assert block_response is not None and err_msg in block_response, "Missing error message '%s' from block response '%s': %s" % (err_msg, "(None)" if block_response is None else block_response, msg)
1295+ assert_true(block_response is not None and err_msg in block_response,
1296+ err_msg= "Missing error message '%s' from block response '%s': %s" % (err_msg, "(None)" if block_response is None else block_response, msg))
niVelion
commented at 4:44 pm on January 13, 2022:
Nit.
0 err_msg="Missing error message '%s' from block response '%s': %s" % (err_msg, "(None)" if block_response is None else block_response, msg))
in
test/functional/feature_taproot.py:1401
in
38fe1453d4outdated
1434@@ -1427,7 +1435,9 @@ def test_spenders(self, node, spenders, input_counts):
1435 for i in range(len(input_utxos)):
1436 if input_utxos[i].spender.need_vin_vout_mismatch:
1437 first_mismatch_input = i
1438- assert first_mismatch_input is None or first_mismatch_input > 0
1439+
1440+ if first_mismatch_input is not None:
1441+ assert_greater_than(first_mismatch_input, 0)
niVelion
commented at 4:52 pm on January 13, 2022:
:+1: in keeping with the line revised here, the first condition is tested for truthiness and then only if it is not true is the second condition tested.
in
test/functional/interface_zmq.py:27
in
38fe1453d4outdated
in
test/functional/interface_zmq.py:72
in
38fe1453d4outdated
68@@ -67,9 +69,9 @@ def receive_sequence(self):
69 label = chr(body[32])
70 mempool_sequence = None if len(body) != 32+1+8 else struct.unpack("<Q", body[32+1:])[0]
71 if mempool_sequence is not None:
72- assert label == "A" or label == "R"
73+ assert_true(label == "A" or label == "R", err_msg="{} different from A or C".format(label))
niVelion
commented at 5:02 pm on January 13, 2022:
Error message fix.
0 assert_true(label == "A" or label == "R", err_msg="{} different from A or R".format(label))
in
test/functional/mining_getblocktemplate_longpoll.py:13
in
38fe1453d4outdated
niVelion
commented at 5:16 pm on January 13, 2022:
If the original predicate was already truthy, I assume the addition of > 0 is to improve readability? The original reads better imo. Same comment L768.
I make this choice for consistency, across error messages and assert convention. I usually try to avoid missing pure assert and assert that came from utils code like the bitcoin test framework.
But I admit that in this case, it would be better assert_not_empity(self.utxos)
However, if you disagree I would restore the previous status with the pure assert
in
test/functional/wallet_disable.py:15
in
38fe1453d4outdated
niVelion
commented at 5:44 pm on January 13, 2022:
Nit.
0 count_bytes,
1 fail,
2 find_vout_for_address,
in
test/functional/test_framework/util.py:83
in
38fe1453d4outdated
94+def assert_true(thing, err_msg=None):
95+ if thing is not True:
96+ msg = "%s it is not True" % str(thing)
97+ if err_msg is not None:
98+ msg = err_msg
99+ raise AssertionError(msg)
niVelion
commented at 6:09 pm on January 13, 2022:
Minor: avoid initializing a default message when an err_msg is provided.
0def assert_true(thing, err_msg=None):
1 if thing is not True:
2 msg = err_msg or "%s it is not True" % str(thing)
3 raise AssertionError(msg)
in
test/functional/test_framework/util.py:50
in
38fe1453d4outdated
44@@ -45,19 +45,52 @@ def assert_fee_amount(fee, tx_size, feerate_BTC_kvB):
45 raise AssertionError("Fee of %s BTC too high! (Should be %s BTC)" % (str(fee), str(target_fee)))
464748-def assert_equal(thing1, thing2, *args):
49+def assert_equal(thing1, thing2, *args, err_msg=None):
50 if thing1 != thing2 or any(thing1 != arg for arg in args):
51- raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
52+ msg = "not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args)
niVelion
commented at 6:19 pm on January 13, 2022:
niVelion
commented at 8:59 pm on January 13, 2022:
Comment # Unknown type likely redundant now.
niVelion
commented at 9:05 pm on January 13, 2022:
none
Thoroughly reviewed and just for good measure, checked out compiled and ran test/functional/test_runner.py --extended.
vincenzopalazzo force-pushed
on Jan 15, 2022
kallewoof
commented at 7:36 am on January 15, 2022:
member
I don’t see why splitting into one commit per file does anything to help review. The contrary, I’d say. The UI already splits per file for you.
vincenzopalazzo
commented at 8:11 am on January 15, 2022:
none
I don’t see why splitting into one commit per file does anything to help review. The contrary, I’d say. The UI already splits per file for you.
When I start to work on that I had the opposite advice, I think this could be a personal choice, I’m sorry if it makes things worse for you.
I’m fine with this splitting because each commit has only a personal portion of all the change, and usually, the UI starts to be very slow for a lot of changes. In addition, for disability reason, I don’t use the UI to review PR, but only to leave a comment, so I considered this approach more accessible too
vincenzopalazzo force-pushed
on Jan 15, 2022
DrahtBot added the label
Needs rebase
on Feb 24, 2022
vincenzopalazzo force-pushed
on Mar 23, 2022
DrahtBot removed the label
Needs rebase
on Mar 23, 2022
vincenzopalazzo force-pushed
on Mar 23, 2022
DrahtBot added the label
Needs rebase
on Mar 24, 2022
vincenzopalazzo force-pushed
on Mar 24, 2022
DrahtBot removed the label
Needs rebase
on Mar 24, 2022
michaelfolkson
commented at 3:38 pm on March 24, 2022:
contributor
I don’t see why splitting into one commit per file does anything to help review. The contrary, I’d say. The UI already splits per file for you.
When I start to work on that I had the opposite advice, I think this could be a personal choice, I’m sorry if it makes things worse for you.
I don’t think anyone suggested that it should be one commit per file right? I suggested splitting across commits rather than different PRs but not giving each file a separate commit.
I suggested this:
I also think the structure of commits could be improved, having a separate commit for each file doesn’t make much sense to me. Also the commit messages aren’t particularly informative for reviewers.
Commit messages such as “Define new assert functions in test utils”, “Replace assert with assert_equal across functional test suite” and “Use assert_greater_than instead of greater than asserts” would be more helpful than “filename.py: Use test framework”.
Reviewers can see what files are changed without looking at commit messages, what they want to see with the commit messages is what the commit is doing.
I personally think this isn’t serious enough (others can assess) that it means it is not yet in a merge-able state but yeah I agree with Kalle that splitting into one commit per file isn’t optimal.
vincenzopalazzo force-pushed
on Mar 24, 2022
vincenzopalazzo
commented at 5:25 pm on March 24, 2022:
none
I don’t think anyone suggested that it should be one commit per file right? I suggested splitting across commits rather than different PRs but not giving each file a separate commit.
Splitting between commits is a too general definition because splitting between commits brings the following problems:
1: What do we need to insert inside one commit? How do you define a good commit for this PR?
2: The commit should be independent of other changes, this means the following things
2.1: improve the test unit should have a separate PR
2.1: moving the test assert in a way that is independent testable.
This is the reason that I choose to divide the file change each one in a separate commit because you can fetch one commit and test in a clean env only on the functional test that you need.
IMHO this is the more clean way to help the reviewer and avoid introducing regression
This is also a good PR definition because to make small PRs you need just to cherry-pick the commits!
I don’t see any drawback with my solution, right?
P.S: In addition, this solution helps also to rebase the PRs and make the tests only on the file changed, that in this case is the single commit
in
test/functional/test_framework/util.py:71
in
4a993641dboutdated
65@@ -66,6 +66,11 @@ def assert_greater_than_or_equal(thing1, thing2):
66 raise AssertionError("%s < %s" % (str(thing1), str(thing2)))
676869+def assert_true(thing, message = None):
70+ if thing is not True:
71+ msg = "%s it is not True" if message is None else message
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2024-12-23 00:13 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me