Files
familienarchiv/tools/import-normalizer/tests/test_persons_tree.py

62 lines
1.7 KiB
Python

import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
import persons_tree
def test_parse_year_iso_string():
assert persons_tree._parse_year("1920-09-20") == 1920
def test_parse_year_excel_serial_birth():
# 7568 days from 1899-12-30 = 1920-09-19 or -20 depending on leap counting
assert persons_tree._parse_year("7568") == 1920
def test_parse_year_excel_serial_death():
# 36222 days from 1899-12-30 ≈ 1999
assert persons_tree._parse_year("36222") == 1999
def test_parse_year_excel_serial_small():
# 177 days from 1899-12-30 = 1900-06-25
assert persons_tree._parse_year("177") == 1900
def test_parse_year_german_date_string():
assert persons_tree._parse_year("30.8.1862") == 1862
def test_parse_year_year_only():
assert persons_tree._parse_year("1930") == 1930
def test_parse_year_free_text():
assert persons_tree._parse_year("August 1941") == 1941
def test_parse_year_none():
assert persons_tree._parse_year(None) is None
def test_parse_year_empty():
assert persons_tree._parse_year("") is None
def test_parse_year_unresolvable_truncated():
# "2.9.196" has no valid 4-digit year — returns None
assert persons_tree._parse_year("2.9.196") is None
def test_parse_year_typo_year():
# "4.3.1023" — year 1023 outside 1700-2100 guard — returns None
assert persons_tree._parse_year("4.3.1023") is None
def test_parse_year_bare_out_of_range_year_is_none():
# "1023" is a plausible typo for "1923" but is NOT an Excel serial.
# parse_date("1023") parses it as year 1023 (out of 1700-2100 guard).
# The serial branch must NOT re-interpret it as a serial.
assert persons_tree._parse_year("1023") is None