election-game/backend/data/pipeline/tests/people/test_people_names_education.py

67 lines
3.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
import pytest
from election_data.people.education import UNSPECIFIED, parse_education
from election_data.people.names import han_key, name_key, slug_name, wikidata_label_variants
pytestmark = pytest.mark.unit
def test_name_key_ignores_spacing_dots_and_case() -> None:
assert name_key("伍麗華 Saidhai.Tahovecahe") == name_key("伍麗華Saidhai‧Tahovecahe")
assert name_key("鄭天財 Sra‧Kacaw") == name_key("鄭天財Sra Kacaw") == "鄭天財srakacaw"
def test_name_key_folds_known_variants_but_slug_keeps_them() -> None:
assert name_key("張啓楷") == name_key("張啟楷")
assert name_key("李姸慧") == name_key("李妍慧")
assert slug_name("李姸慧") == "李姸慧"
def test_name_key_keeps_tai_characters_in_person_names() -> None:
assert "台灣" in name_key("黃宏成台灣阿成世界偉人財神總統")
def test_han_key_drops_romanized_indigenous_names() -> None:
assert han_key("伍麗華Saidhai‧Tahovecahe") == "伍麗華"
assert han_key("曾智勇 Ljaucu‧Zingrur") == "曾智勇"
def test_wikidata_label_variants_include_han_only_and_folded() -> None:
assert wikidata_label_variants("伍麗華Saidhai‧Tahovecahe") == ("伍麗華Saidhai‧Tahovecahe", "伍麗華")
assert wikidata_label_variants("李姸慧") == ("李姸慧", "李妍慧")
@pytest.mark.parametrize(
("text", "expected"),
[
("國立政治大學外交學系學士", [("學士", "國立政治大學外交學系")]),
("國立虎尾科技大學碩士學位", [("碩士", "國立虎尾科技大學")]),
("中興大學法律系畢業", [("學士", "中興大學法律系")]),
(
"法國巴黎第十大學政治、經濟、社會哲學博士候選人",
[("博士候選人", "法國巴黎第十大學政治、經濟、社會哲學")],
),
("屏東師範學院國民教育硏究所碩士(85年-87年)", [("碩士", "屏東師範學院國民教育硏究所")]),
("國立臺灣大學EMBA碩士班", [("碩士", "國立臺灣大學EMBA")]),
("國立政治大學新聞學系", [(UNSPECIFIED, "國立政治大學新聞學系")]),
(
"龜山國小、大有國中、武陵高中",
[("國小", "龜山國小"), ("國中", "大有國中"), ("高中職", "武陵高中")],
),
("嘉義大學管理碩士、", [("碩士", "嘉義大學管理")]),
("臺北縣立頂溪國小畢業", [("國小", "臺北縣立頂溪國小")]),
("屏東師專(73年-78年)", [("專科", "屏東師專")]),
("臺灣會計師高考及格", []),
("國立清華大學\t博士後研究", []),
],
)
def test_parse_education(text: str, expected: list[tuple[str, str | None]]) -> None:
assert parse_education(text) == expected
def test_parse_education_splits_semicolons_and_dedupes() -> None:
text = "東海大學社會工作學系學士;東海大學社會工作學系碩士;東海大學社會工作學系學士"
assert parse_education(text) == [("學士", "東海大學社會工作學系"), ("碩士", "東海大學社會工作學系")]