|
34 | 34 | from typing import NamedTuple |
35 | 35 |
|
36 | 36 | HERE = Path(__file__).resolve().parent |
37 | | -DEFAULT_BASELINE = "2.8.0" |
| 37 | +DEFAULT_BASELINE = "3.0.0" |
38 | 38 | REPO_ROOT = HERE.parents[1] |
39 | 39 |
|
40 | 40 |
|
@@ -124,10 +124,15 @@ def _surfaces_for(version: str) -> frozenset[str]: |
124 | 124 | # whether this release reports the reading a fork did not take (2.7, |
125 | 125 | # #752 phase 2m): compare() compares the alternatives only where it does |
126 | 126 | _AMBIGUITY = getattr(nameparser, "Ambiguity", None) |
| 127 | +# the views this release's ParsedName has (3.0's suffix, patronymic and |
| 128 | +# second-surname views): compare() compares a view only where it does |
| 129 | +_PARSED = getattr(nameparser, "ParsedName", None) |
127 | 130 | print(json.dumps({"__version__": nameparser.__version__, |
128 | 131 | "__file__": nameparser.__file__, |
129 | 132 | "alternatives": "alternative" in getattr( |
130 | | - _AMBIGUITY, "__dataclass_fields__", {})}), flush=True) |
| 133 | + _AMBIGUITY, "__dataclass_fields__", {}), |
| 134 | + "views": [v for v in @@VIEWS@@ |
| 135 | + if hasattr(_PARSED, v)]}), flush=True) |
131 | 136 |
|
132 | 137 | if WANT_V2: |
133 | 138 | from nameparser import Parser, Policy, parse |
@@ -163,6 +168,9 @@ def _v2_row(p): |
163 | 168 | forced = str(p.capitalized(force=True)) |
164 | 169 | row["_capitalized"] = plain if plain != rendered else "" |
165 | 170 | row["_capitalized_force"] = forced if forced != plain else "" |
| 171 | + # 3.0's views, as snapshot.read() records them: empty before 3.0 |
| 172 | + for key in @@VIEW_ROW_KEYS@@: |
| 173 | + row[f"_{key}"] = getattr(p, key, "") or "" |
166 | 174 | return row |
167 | 175 |
|
168 | 176 |
|
@@ -201,6 +209,9 @@ def _worker_source(version: str, want_v2: bool) -> str: |
201 | 209 | """ |
202 | 210 | return (_WORKER_TEMPLATE |
203 | 211 | .replace("@@VERSION@@", version) |
| 212 | + .replace("@@VIEWS@@", repr(tuple(VIEW_KEYS))) |
| 213 | + .replace("@@VIEW_ROW_KEYS@@", |
| 214 | + repr(tuple(k for ks in VIEW_KEYS.values() for k in ks))) |
204 | 215 | .replace("@@WANT_V2@@", "True" if want_v2 else "False")) |
205 | 216 |
|
206 | 217 |
|
@@ -329,11 +340,25 @@ class Result(NamedTuple): |
329 | 340 | unrecorded: tuple[str, ...] = () # keys the baseline cannot read |
330 | 341 |
|
331 | 342 |
|
| 343 | +#: The ParsedName views a row records (3.0), each with the row keys it |
| 344 | +#: fills: `generation` fills `credentials` beside it (snapshot.row). |
| 345 | +#: test_differential holds this to snapshot.RECORDED_LATER. |
| 346 | +VIEW_KEYS = {"generation": ("generation", "credentials"), |
| 347 | + "honorifics": ("honorifics",), |
| 348 | + "patronymic": ("patronymic",), |
| 349 | + "surname2": ("surname2",)} |
| 350 | + |
| 351 | + |
332 | 352 | def unrecorded(tell: Mapping[str, object]) -> tuple[str, ...]: |
333 | 353 | """The row keys the baseline worker's release cannot record, which |
334 | 354 | compare() leaves out of both sides: the alternatives before 2.7, |
| 355 | + and each view before the release whose ParsedName has it (3.0), |
335 | 356 | since a tree reporting one is not a name that moved.""" |
336 | | - return () if tell.get("alternatives") else ("alternatives",) |
| 357 | + has = tell.get("views") or () |
| 358 | + assert isinstance(has, (list, tuple)) |
| 359 | + return ((() if tell.get("alternatives") else ("alternatives",)) |
| 360 | + + tuple(k for view, keys in VIEW_KEYS.items() |
| 361 | + if view not in has for k in keys)) |
337 | 362 |
|
338 | 363 |
|
339 | 364 | def compare(baseline: str, corpora: list[Path] | None = None) -> Result: |
|
0 commit comments