From 7118adb796ad67ada176fe3cb8685aa4f9852571 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Thu, 22 Jan 2026 18:17:27 -0500 Subject: [PATCH] lint fixes --- getmyancestors/mergemyanc.py | 56 +++++++++++++++++++----------------- tests/offline_test.py | 14 +++++++-- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/getmyancestors/mergemyanc.py b/getmyancestors/mergemyanc.py index 0db1724..2652905 100755 --- a/getmyancestors/mergemyanc.py +++ b/getmyancestors/mergemyanc.py @@ -98,6 +98,35 @@ def main( # Default to stdin input_handles.append(sys.stdin) + # Helper for whitespace normalization in quotes + def norm_space(s): + return " ".join(s.split()) if s else "" + + # Deduplicate names by string representation (deterministic: first alphabetically wins) + def merge_names(target_set, source_set): + # Combine all names and sort deterministically + all_names = list(target_set) + list(source_set) + all_names.sort( + key=lambda x: ( + str(x), + x.given or "", + x.surname or "", + x.prefix or "", + x.suffix or "", + x.kind or "", + str(x.alternative) if hasattr(x, "alternative") else "", + x.note.text if hasattr(x, "note") and x.note else "", + ) + ) + # Rebuild target_set keeping first occurrence by string + target_set.clear() + seen = set() + for n in all_names: + s = str(n) + if s not in seen: + target_set.add(n) + seen.add(s) + try: # read the GEDCOM data for file in input_handles: @@ -109,33 +138,6 @@ def main( ged = Gedcom(file, tree) - # Deduplicate names by string representation (deterministic: first alphabetically wins) - def merge_names(target_set, source_set): - # Combine all names and sort deterministically - all_names = list(target_set) + list(source_set) - all_names.sort(key=lambda x: ( - str(x), - x.given or "", - x.surname or "", - x.prefix or "", - x.suffix or "", - x.kind or "", - str(x.alternative) if hasattr(x, 'alternative') else "", - x.note.text if hasattr(x, 'note') and x.note else "", - )) - # Rebuild target_set keeping first occurrence by string - target_set.clear() - seen = set() - for n in all_names: - s = str(n) - if s not in seen: - target_set.add(n) - seen.add(s) - - # Helper for whitespace normalization in quotes - def norm_space(s): - return " ".join(s.split()) if s else "" - # add information about individuals new_indi = 0 merged_indi = 0 diff --git a/tests/offline_test.py b/tests/offline_test.py index 34e268d..9f8557a 100644 --- a/tests/offline_test.py +++ b/tests/offline_test.py @@ -132,7 +132,6 @@ def test_offline(): expectations = load_expectations() exp_ada = expectations.get("EXPECTED_ADA_LINES", 0) exp_marie = expectations.get("EXPECTED_MARIE_LINES", 0) - exp_merged = expectations.get("EXPECTED_MERGED_LINES", 0) # 2. Setup Cache setup_cache() @@ -303,10 +302,19 @@ def test_offline(): # Check merged file with exact diff (no line count tolerance) diff_result = subprocess.run( - ["git", "diff", "--no-index", "--exit-code", "--color=always", str(merged), str(ARTIFACTS_DIR / "merged_scientists.ged")], + [ + "git", + "diff", + "--no-index", + "--exit-code", + "--color=always", + str(merged), + str(ARTIFACTS_DIR / "merged_scientists.ged"), + ], + check=False, ) if diff_result.returncode != 0: - print(f"❌ Merged file differs from artifact (see diff above)") + print("❌ Merged file differs from artifact (see diff above)") failed = True else: print(f"✓ Merged file matches artifact exactly ({l_merged} lines).") -- 2.52.0