From b68f2eaedd73a5ebb483f7c30a33a25c2a592709 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 4 Jul 2026 14:49:06 -0700 Subject: [PATCH 1/2] Add unit tests for group_contiguous_integers This module-level utility (used by join_on_conjunctions) had no direct test coverage of its own, only indirect coverage through HumanName-level parsing tests. Add focused tests for its documented contract: empty/isolated/single values return no ranges, adjacent pairs are the smallest valid run, multiple separate runs are found independently, and out-of-order input isn't treated as contiguous (the function assumes ascending, strictly increasing input). --- tests/test_parser_util.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/test_parser_util.py diff --git a/tests/test_parser_util.py b/tests/test_parser_util.py new file mode 100644 index 0000000..a073a5b --- /dev/null +++ b/tests/test_parser_util.py @@ -0,0 +1,38 @@ +from nameparser.parser import group_contiguous_integers + + +def test_empty_list_returns_no_ranges() -> None: + assert group_contiguous_integers([]) == [] + + +def test_all_isolated_values_returns_no_ranges() -> None: + # no two values are adjacent, so nothing counts as a "run" + assert group_contiguous_integers([1, 3, 5]) == [] + + +def test_single_value_returns_no_ranges() -> None: + # a run of length 1 isn't a contiguous "run" by this function's definition + assert group_contiguous_integers([5]) == [] + + +def test_pair_of_adjacent_values_is_smallest_valid_run() -> None: + assert group_contiguous_integers([4, 5]) == [(4, 5)] + + +def test_single_contiguous_run() -> None: + assert group_contiguous_integers([1, 2, 3]) == [(1, 3)] + + +def test_multiple_separate_contiguous_runs() -> None: + assert group_contiguous_integers([1, 2, 5, 6, 7, 9]) == [(1, 2), (5, 7)] + + +def test_isolated_values_between_runs_are_excluded() -> None: + assert group_contiguous_integers([1, 2, 4, 6, 7]) == [(1, 2), (6, 7)] + + +def test_unsorted_input_is_not_treated_as_contiguous() -> None: + # the function assumes ascending, strictly increasing input (as produced + # by an `enumerate`-based index scan, which is how join_on_conjunctions + # uses it); descending or out-of-order input won't find real-world runs + assert group_contiguous_integers([3, 2, 1]) == [] From 8ed5a9a1f1b9298bb7c2d4ce2463132130dd0086 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 4 Jul 2026 14:51:55 -0700 Subject: [PATCH 2/2] Tighten comment on unsorted-input test for precision Code review noted the comment attributed the empty result to "unsorted input" generally, when the actual mechanism is that the groupby key (enumerate index - value) only repeats across an ascending run; a descending sequence changes the key at every step. --- tests/test_parser_util.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_parser_util.py b/tests/test_parser_util.py index a073a5b..a2b74f5 100644 --- a/tests/test_parser_util.py +++ b/tests/test_parser_util.py @@ -32,7 +32,8 @@ def test_isolated_values_between_runs_are_excluded() -> None: def test_unsorted_input_is_not_treated_as_contiguous() -> None: - # the function assumes ascending, strictly increasing input (as produced - # by an `enumerate`-based index scan, which is how join_on_conjunctions - # uses it); descending or out-of-order input won't find real-world runs + # the grouping key (enumerate index - value) only repeats for ascending, + # strictly increasing runs (as produced by an `enumerate`-based index + # scan, which is how join_on_conjunctions uses it); a descending + # sequence changes the key at every step, so no run is ever found assert group_contiguous_integers([3, 2, 1]) == []