Repository navigation
PYTHON-5728 Improve bson code coverage - #2880
Conversation
There was a problem hiding this comment.
Pull request overview
Adds targeted regression/unit tests to improve BSON-related code coverage, focusing on list encoding edge cases and DatetimeMS behavior.
Changes:
- Add a round-trip encoding/decoding test for lists that cross the
gen_list_namecached-key boundary. - Add tests covering
DatetimeMShashing,reprround-tripping, and constructor type/range validation.
| # Unequal values should produce unequal hashes (not guaranteed, but | ||
| # true for plain int hashes which is what DatetimeMS delegates to). | ||
| self.assertNotEqual(hash(DatetimeMS(0)), hash(DatetimeMS(1))) |
There was a problem hiding this comment.
I agree with the robot, we have enough issues caused by potential CPython/PyPy conflicts 😅 .
| # Spot-check: the 1000th and 1001st elements (0-indexed) must | ||
| # survive the cache/on-demand boundary intact. | ||
| self.assertEqual(decode(doc)["a"][1000], 1000) | ||
| self.assertEqual(decode(doc)["a"][1001], 1001) |
There was a problem hiding this comment.
We should also check that the other side of the boundary doc["a"][999] is correct.
| # boundary and verify the round-trip is correct. | ||
| values = list(range(1002)) | ||
| doc = encode({"a": values}) | ||
| self.assertEqual(decode(doc)["a"], values) |
There was a problem hiding this comment.
Store decode(doc) in a variable instead of decoding three times.
| # Unequal values should produce unequal hashes (not guaranteed, but | ||
| # true for plain int hashes which is what DatetimeMS delegates to). | ||
| self.assertNotEqual(hash(DatetimeMS(0)), hash(DatetimeMS(1))) |
There was a problem hiding this comment.
I agree with the robot, we have enough issues caused by potential CPython/PyPy conflicts 😅 .
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…brittle hash inequality assertion
PYTHON-5728
Changes in this PR
Test Plan
Checklist
Checklist for Author
Checklist for Reviewer