Group copies only when they all match, compare towns through places.towns, and record the rule in the plan

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-29 22:12:39 +02:00
1 parent fdb6264c98
commit b09a2f6b33
4 files changed
+90 -134

No files matched your search

+34 -6
View File
@@ -12,7 +12,8 @@ if str(ROOT) not in sys.path:
import pytest # noqa: E402
from app.dupes import Copy, assign, keep_order, same_posting, towns # noqa: E402
from app.dupes import Copy, assign, keep_order, same_posting # noqa: E402
from app.places import towns # noqa: E402
def cp(uid: str = "u", company: str = "acme", title: str = "engineer", country: str = "DE",
@@ -70,7 +71,7 @@ def test_houston_state_code():
def test_copenhagen_district_and_remote_phrase():
a = cp("a", "acme", "x", "DK", "København K og mulighed for hjemmearbejde")
b = cp("b", "acme", "x", "DK", "Copenhagen, Denmark")
assert towns(a.place, "DK") == {"copenhagen"}
assert towns(a.place) == {"copenhagen"}
assert same_posting(a, b)
@@ -114,21 +115,35 @@ def test_country_rules():
("Aalborg, Copenhagen, Kolding, Aarhus, Hybrid position", "DK",
{"aalborg", "copenhagen", "kolding", "aarhus"}),
("Berlin und Munich", "DE", {"berlin", "munich"}),
("Mountain View, California", "US", {"mountain view"}),
("Ningbo, Zhejiang, China", "CN", {"ningbo"}),
("Germany", "DE", set()),
("Remote", "", set()),
("", "", set()),
])
def test_towns(place, country, expected):
assert towns(place, country) == expected
# A head `places` cannot parse, "remote berlin", may come along; it matches
# nothing, so only the towns that must be there and the empty case count.
found = towns(place)
assert found >= expected and (expected or not found)
def test_assign_is_transitive():
# A matches B by Berlin, B matches C by Hamburg, A and C alone do not match.
def test_a_state_or_province_is_not_a_shared_town():
# Live false merges before `places.towns`: Databricks and Bosch.
assert not same_posting(cp("a", country="US", place="Mountain View, California"),
cp("b", country="US", place="San Francisco, California"))
assert not same_posting(cp("a", country="CN", place="Ningbo, Zhejiang, China"),
cp("b", country="CN", place="Hangzhou, Zhejiang, China"))
def test_assign_does_not_chain():
# A matches B by Berlin, B matches C by Hamburg, A and C do not match, so A
# cannot share C's group.
a = cp("a", place="Berlin", posted="2026-09-03")
b = cp("b", place="Berlin, Hamburg", posted="2026-09-02")
c = cp("c", place="Hamburg", posted="2026-09-01")
assert not same_posting(a, c)
assert assign([a, b, c]) == {"a": "c", "b": "c", "c": None}
assert assign([a, b, c]) == {"a": None, "b": "c", "c": None}
def test_assign_returns_every_uid():
@@ -166,3 +181,16 @@ def test_a_row_without_a_town_joins_only_one_group():
assert assign(rows) == {"a": None, "b": "a", "c": "a"}
rows = [cp("a", place=""), cp("b", place="Germany")]
assert assign(rows) == {"a": None, "b": "a"}
def test_a_row_without_a_place_never_bridges_two_countries():
# Live: LEGO "Sales Associate", three rows with no place, one Belgium, one
# Netherlands, `country` empty on all five until the place names one.
rows = [cp("a", country="", place=""), cp("b", country="", place=""),
cp("c", country="", place=""), cp("d", country="BE", place="Belgium"),
cp("e", country="NL", place="Netherlands")]
got = assign(rows)
assert got["d"] is None and got["e"] is None
assert got == {"a": None, "b": "a", "c": "a", "d": None, "e": None}
assert not same_posting(cp("a", country="EU", place="Belgium"),
cp("b", country="EU", place="Netherlands"))