-
Notifications
You must be signed in to change notification settings - Fork 13
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
#66 loosen tolerance for comparing memory consumption #67
#66 loosen tolerance for comparing memory consumption #67
Conversation
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.
Hi @jschneidereit. thanks for this PR. Overall I like the changes your suggest. My main critique that I have is that you added a new dependency for assertpy
which I'm generally not in favor for. Can you implement your memory consumption relaxation without this new package?
Also please run the black
code formatter to resolve the clean code failures.
@@ -28,11 +28,11 @@ dependencies: | |||
- numpy | |||
- pandas | |||
# Developer tools | |||
- assertpy |
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.
Do we need this package for this fix? I appreciate that it cleans up some of the test code for readability, however I would prefer to not add another dependency to scyjava.
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.
@elevans If it were a transitive dependency for the main codebase I'd fully agree, but since it's only a developer dependency... I think I feel less strongly than you do about it. 😅
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.
Can I interest you in the power of readable test failure messages?
This is the original error message:
assert abs(mb_total - mb_initial) < 5, f"{mb_total=} {mb_initial=}"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: mb_total=56 mb_initial=50
While this is th error message using assertpy:
AssertionError: [total mb should be close to initial] Expected <56> to be close to <50> within tolerance <5>, but was not.
The value becomes more clear when you write tests checking more complex things than number comparisons, take a scroll through their README to see if you recognize any patterns 😎
A more concrete example is near the end of test_arrays.py
:
for i in range(len(nums_delta)):
for j in range(len(nums_delta[i])):
assert nums_delta[i][j] == pdoubles[i][j]
If you used assertpy you'd get a nice error message displaying both lists showing how they differ instead of just "false"
for i in range(len(nums_delta)):
assert_that(nums_delta[i]).is_equal_to(pdoubles[i])
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.
Persuasion successful! Curtis is right and perhaps I was too against adding a new dependency. Since this would just be in the development config and not the main code base I have no problems here and in fact I think we could use assertpy
in pyimagej
and perhaps imglyb
!
tests/it/java_heap.py
Outdated
# Most of that memory should still be free; i.e., | ||
# we should not be using more than a few MB yet. | ||
assert mb_used <= 5, f"{mb_used=}" | ||
tolerance = pow(10, magnitude(mb_initial)) |
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.
Add a comment about what tolerance
does here.
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.
This logic feels like overkill to me... I would have just changed the 5
to 10
and called it good 😆
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.
😂 you're not wrong, somehow felt better than just "10" - I'll change it to that
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'll wait to add the comment on the above discussion, in test assertion frameworks they generally let you say how close two numbers should be to each other within some magnitude. This is that, but if y'all put the kibosh on assertpy then it would just be < 10
(which I would still rename to tolerance or delta or something as opposed to an inlined number)
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.
We will keep assertpy
but I also agree with @ctrueden that this does feel a bit much. I say just set the tolerance
to <10
.
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 kinda like the elegance of the assert_that
calls. I would personally suggest to leave off the magnitude
reasoning though, in favor of just hardcoding the tolerance
to 10
.
@elevans I defer to you on both decisions to be made here:
- Do we keep the new
assertpy
dev dependency, or stick with built-in Python asserts? - Do we keep the
magnitude
reasoning, or just set it to 10 (or 15 or whatever)?
@@ -28,11 +28,11 @@ dependencies: | |||
- numpy | |||
- pandas | |||
# Developer tools | |||
- assertpy |
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.
@elevans If it were a transitive dependency for the main codebase I'd fully agree, but since it's only a developer dependency... I think I feel less strongly than you do about it. 😅
tests/it/java_heap.py
Outdated
# Most of that memory should still be free; i.e., | ||
# we should not be using more than a few MB yet. | ||
assert mb_used <= 5, f"{mb_used=}" | ||
tolerance = pow(10, magnitude(mb_initial)) |
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.
This logic feels like overkill to me... I would have just changed the 5
to 10
and called it good 😆
Do we keep the new assertpy dev dependency, or stick with built-in Python asserts? I agree that Do we keep the magnitude reasoning, or just set it to 10 (or 15 or whatever)? I think the magnitude reasoning is more complicated than what we need it to be. I prefer that the desired tolerance is |
433abae
to
88769c4
Compare
I took the liberty of pushing commits fixing the linting errors and simplifying the tolerance logic. |
But still only three Pythons. Five Pythons is too many Pythons.
88769c4
to
b414c55
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #67 +/- ##
=======================================
Coverage 53.15% 53.15%
=======================================
Files 12 12
Lines 1285 1285
=======================================
Hits 683 683
Misses 602 602 ☔ View full report in Codecov by Sentry. |
Thank you @jschneidereit for the very tidy contribution! |
Not sure how I feel about the actual fix to the test here, order of magnitude for the memory requested is 1 and
10^2
is just 10 which feels better than 5 to me 😛.Not sure why this M chip is using up one more megabyte but the tests pass on osx-arm64 now!
(fixes #66)