Repository navigation
test: Fix failing tests due to parallelization - #159
Conversation
Reviewer's GuideUpdates stream tests so they validate the contents and valid grouping outcomes without assuming deterministic ordering introduced by parallelization, while improving object representations for readable assertion failures. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/_streams/test_stream_implementation.py" line_range="198" />
<code_context>
.group_by(lambda x: x.isalnum())\
.to_list()
- self.assertListEqual(result, [(True, ["b", "a"])])
+ self.assertIn(result, [
+ [(True, ['b', 'a'])],
+ [(True, ['a', 'b'])]
</code_context>
<issue_to_address>
**Valid parallel groups fail tests**
When parallel scheduling produces either omitted key and bucket ordering, `ParallelStream._group_to_dict` can insert keys and append bucket values independently, producing valid permutations absent from the six `assertIn` alternatives; the grouping test then fails despite correct grouping.
Assert group membership and bucket contents without requiring a particular parallel key or value order.
Also at `tests/_streams/test_stream_implementation.py:204-205`.
</issue_to_address>
### Comment 2
<location path="tests/_streams/test_stream_implementation.py" line_range="37" />
<code_context>
out = []
self.stream([1, 2, 3, 9]).map_to_str().for_each(out.append)
- self.assertListEqual(out, ["1", "2", "3", "9"])
+ self.assertCountEqual(out, ["1", "2", "3", "9"])
def test_map_str_to_int(self):
</code_context>
<issue_to_address>
**Sequential callback order regressions pass**
When a sequential implementation invokes callbacks out of encounter order, the parameterized test uses `assertCountEqual`, so reordered `for_each` or `peek` callbacks still pass and the suite misses a sequential encounter-order regression.
Keep an order-sensitive assertion for sequential callbacks while allowing unordered parallel callbacks.
Also at `tests/_streams/test_stream_implementation.py:127`, `tests/_streams/test_stream_implementation.py:198-205`, `tests/_streams/test_stream_implementation.py:220-225`, `tests/_streams/error/test_error_handler_streams.py:66-70`.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: tests/_streams/test_stream_implementation.py:198, tests/_streams/test_stream_implementation.py:37
| .group_by(lambda p: p.x) \ | ||
| .to_list() | ||
| self.assertListEqual(result, [(1, [pt1, pt2]), (2, [pt3, pt4])]) | ||
| self.assertIn(result, [ |
There was a problem hiding this comment.
🟡 Medium · Valid parallel groups fail tests
When parallel scheduling produces either omitted key and bucket ordering, ParallelStream._group_to_dict can insert keys and append bucket values independently, producing valid permutations absent from the six assertIn alternatives; the grouping test then fails despite correct grouping.
Assert group membership and bucket contents without requiring a particular parallel key or value order.
Also at tests/_streams/test_stream_implementation.py:204-205.
Prompt for AI agents
In `tests/_streams/test_stream_implementation.py` at line 198:
**Valid parallel groups fail tests**
When parallel scheduling produces either omitted key and bucket ordering, `ParallelStream._group_to_dict` can insert keys and append bucket values independently, producing valid permutations absent from the six `assertIn` alternatives; the grouping test then fails despite correct grouping.
Assert group membership and bucket contents without requiring a particular parallel key or value order.
Also at `tests/_streams/test_stream_implementation.py:204-205`.| out = [] | ||
| self.stream([1, 2, 3, 9]).map_to_str().for_each(out.append) | ||
| self.assertListEqual(out, ["1", "2", "3", "9"]) | ||
| self.assertCountEqual(out, ["1", "2", "3", "9"]) |
There was a problem hiding this comment.
🟡 Medium · Sequential callback order regressions pass
When a sequential implementation invokes callbacks out of encounter order, the parameterized test uses assertCountEqual, so reordered for_each or peek callbacks still pass and the suite misses a sequential encounter-order regression.
Keep an order-sensitive assertion for sequential callbacks while allowing unordered parallel callbacks.
Also at tests/_streams/test_stream_implementation.py:127, tests/_streams/test_stream_implementation.py:198-205, tests/_streams/test_stream_implementation.py:220-225, tests/_streams/error/test_error_handler_streams.py:66-70.
Prompt for AI agents
In `tests/_streams/test_stream_implementation.py` at line 37:
**Sequential callback order regressions pass**
When a sequential implementation invokes callbacks out of encounter order, the parameterized test uses `assertCountEqual`, so reordered `for_each` or `peek` callbacks still pass and the suite misses a sequential encounter-order regression.
Keep an order-sensitive assertion for sequential callbacks while allowing unordered parallel callbacks.
Also at `tests/_streams/test_stream_implementation.py:127`, `tests/_streams/test_stream_implementation.py:198-205`, `tests/_streams/test_stream_implementation.py:220-225`, `tests/_streams/error/test_error_handler_streams.py:66-70`.


Summary by Sourcery
Allow parallelized stream tests to pass regardless of result ordering.
Enhancements:
Tests: