-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5392 Better test assertions for comparisons #2350
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
Open
sleepyStick
wants to merge
2
commits into
mongodb:master
Choose a base branch
from
sleepyStick:better-comparison-assertions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1045,46 +1045,46 @@ def test_exception_wrapping(self): | |
|
||
def test_minkey_maxkey_comparison(self): | ||
# MinKey's <, <=, >, >=, !=, and ==. | ||
self.assertTrue(MinKey() < None) | ||
self.assertTrue(MinKey() < 1) | ||
self.assertTrue(MinKey() <= 1) | ||
self.assertTrue(MinKey() <= MinKey()) | ||
self.assertFalse(MinKey() > None) | ||
self.assertFalse(MinKey() > 1) | ||
self.assertFalse(MinKey() >= 1) | ||
self.assertTrue(MinKey() >= MinKey()) | ||
self.assertTrue(MinKey() != 1) | ||
self.assertFalse(MinKey() == 1) | ||
self.assertTrue(MinKey() == MinKey()) | ||
self.assertLess(MinKey(), None) | ||
self.assertLess(MinKey(), 1) | ||
self.assertLessEqual(MinKey(), 1) | ||
self.assertLessEqual(MinKey(), MinKey()) | ||
self.assertLessEqual(MinKey(), None) | ||
self.assertLessEqual(MinKey(), 1) | ||
self.assertLess(MinKey(), 1) | ||
self.assertGreaterEqual(MinKey(), MinKey()) | ||
self.assertNotEqual(MinKey(), 1) | ||
self.assertNotEqual(MinKey(), 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need duplicate assertions: the case above checks |
||
self.assertEqual(MinKey(), MinKey()) | ||
|
||
# MinKey compared to MaxKey. | ||
self.assertTrue(MinKey() < MaxKey()) | ||
self.assertTrue(MinKey() <= MaxKey()) | ||
self.assertFalse(MinKey() > MaxKey()) | ||
self.assertFalse(MinKey() >= MaxKey()) | ||
self.assertTrue(MinKey() != MaxKey()) | ||
self.assertFalse(MinKey() == MaxKey()) | ||
self.assertLess(MinKey(), MaxKey()) | ||
self.assertLessEqual(MinKey(), MaxKey()) | ||
self.assertLessEqual(MinKey(), MaxKey()) | ||
self.assertLess(MinKey(), MaxKey()) | ||
self.assertNotEqual(MinKey(), MaxKey()) | ||
self.assertNotEqual(MinKey(), MaxKey()) | ||
|
||
# MaxKey's <, <=, >, >=, !=, and ==. | ||
self.assertFalse(MaxKey() < None) | ||
self.assertFalse(MaxKey() < 1) | ||
self.assertFalse(MaxKey() <= 1) | ||
self.assertTrue(MaxKey() <= MaxKey()) | ||
self.assertTrue(MaxKey() > None) | ||
self.assertTrue(MaxKey() > 1) | ||
self.assertTrue(MaxKey() >= 1) | ||
self.assertTrue(MaxKey() >= MaxKey()) | ||
self.assertTrue(MaxKey() != 1) | ||
self.assertFalse(MaxKey() == 1) | ||
self.assertTrue(MaxKey() == MaxKey()) | ||
self.assertGreaterEqual(MaxKey(), None) | ||
self.assertGreaterEqual(MaxKey(), 1) | ||
self.assertGreater(MaxKey(), 1) | ||
self.assertLessEqual(MaxKey(), MaxKey()) | ||
self.assertGreater(MaxKey(), None) | ||
self.assertGreater(MaxKey(), 1) | ||
self.assertGreaterEqual(MaxKey(), 1) | ||
self.assertGreaterEqual(MaxKey(), MaxKey()) | ||
self.assertNotEqual(MaxKey(), 1) | ||
self.assertNotEqual(MaxKey(), 1) | ||
self.assertEqual(MaxKey(), MaxKey()) | ||
|
||
# MaxKey compared to MinKey. | ||
self.assertFalse(MaxKey() < MinKey()) | ||
self.assertFalse(MaxKey() <= MinKey()) | ||
self.assertTrue(MaxKey() > MinKey()) | ||
self.assertTrue(MaxKey() >= MinKey()) | ||
self.assertTrue(MaxKey() != MinKey()) | ||
self.assertFalse(MaxKey() == MinKey()) | ||
self.assertGreaterEqual(MaxKey(), MinKey()) | ||
self.assertGreater(MaxKey(), MinKey()) | ||
self.assertGreater(MaxKey(), MinKey()) | ||
self.assertGreaterEqual(MaxKey(), MinKey()) | ||
self.assertNotEqual(MaxKey(), MinKey()) | ||
self.assertNotEqual(MaxKey(), MinKey()) | ||
|
||
def test_minkey_maxkey_hash(self): | ||
self.assertEqual(hash(MaxKey()), hash(MaxKey())) | ||
|
@@ -1094,25 +1094,25 @@ def test_minkey_maxkey_hash(self): | |
def test_timestamp_comparison(self): | ||
# Timestamp is initialized with time, inc. Time is the more | ||
# significant comparand. | ||
self.assertTrue(Timestamp(1, 0) < Timestamp(2, 17)) | ||
self.assertTrue(Timestamp(2, 0) > Timestamp(1, 0)) | ||
self.assertTrue(Timestamp(1, 7) <= Timestamp(2, 0)) | ||
self.assertTrue(Timestamp(2, 0) >= Timestamp(1, 1)) | ||
self.assertTrue(Timestamp(2, 0) <= Timestamp(2, 0)) | ||
self.assertTrue(Timestamp(2, 0) >= Timestamp(2, 0)) | ||
self.assertFalse(Timestamp(1, 0) > Timestamp(2, 0)) | ||
self.assertLess(Timestamp(1, 0), Timestamp(2, 17)) | ||
self.assertGreater(Timestamp(2, 0), Timestamp(1, 0)) | ||
self.assertLessEqual(Timestamp(1, 7), Timestamp(2, 0)) | ||
self.assertGreaterEqual(Timestamp(2, 0), Timestamp(1, 1)) | ||
self.assertLessEqual(Timestamp(2, 0), Timestamp(2, 0)) | ||
self.assertGreaterEqual(Timestamp(2, 0), Timestamp(2, 0)) | ||
self.assertLessEqual(Timestamp(1, 0), Timestamp(2, 0)) | ||
|
||
# Comparison by inc. | ||
self.assertTrue(Timestamp(1, 0) < Timestamp(1, 1)) | ||
self.assertTrue(Timestamp(1, 1) > Timestamp(1, 0)) | ||
self.assertTrue(Timestamp(1, 0) <= Timestamp(1, 0)) | ||
self.assertTrue(Timestamp(1, 0) <= Timestamp(1, 1)) | ||
self.assertFalse(Timestamp(1, 0) >= Timestamp(1, 1)) | ||
self.assertTrue(Timestamp(1, 0) >= Timestamp(1, 0)) | ||
self.assertTrue(Timestamp(1, 1) >= Timestamp(1, 0)) | ||
self.assertFalse(Timestamp(1, 1) <= Timestamp(1, 0)) | ||
self.assertTrue(Timestamp(1, 0) <= Timestamp(1, 0)) | ||
self.assertFalse(Timestamp(1, 0) > Timestamp(1, 0)) | ||
self.assertLess(Timestamp(1, 0), Timestamp(1, 1)) | ||
self.assertGreater(Timestamp(1, 1), Timestamp(1, 0)) | ||
self.assertLessEqual(Timestamp(1, 0), Timestamp(1, 0)) | ||
self.assertLessEqual(Timestamp(1, 0), Timestamp(1, 1)) | ||
self.assertLess(Timestamp(1, 0), Timestamp(1, 1)) | ||
self.assertGreaterEqual(Timestamp(1, 0), Timestamp(1, 0)) | ||
self.assertGreaterEqual(Timestamp(1, 1), Timestamp(1, 0)) | ||
self.assertGreater(Timestamp(1, 1), Timestamp(1, 0)) | ||
self.assertLessEqual(Timestamp(1, 0), Timestamp(1, 0)) | ||
self.assertLessEqual(Timestamp(1, 0), Timestamp(1, 0)) | ||
|
||
def test_timestamp_highorder_bits(self): | ||
doc = {"a": Timestamp(0xFFFFFFFF, 0xFFFFFFFF)} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 want to preserve the operation that each test is verifying. This test should be an
assertGreater
, not anassertLessEqual
. The same holds for any other tests that have had their operations changed to preserve the original test case. The value should change so the test accurately reflects what operation is being verified.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.
to clarify, instead of being
assertFalse(a > b)
it should beassertGreater(b, a)
, correct?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.
Hmm, in this case
MinKey
andMaxKey
define their ge and such methods to be different. @ShaneHarvey can you offer the reasoning behind these tests?