from scripts.extract_k1_specialties import active_codes, build_reference, parse_rows import pytest def test_vak_continuation_and_historical_dates(): rows = [ {"page": 1, "cells": ["1.", "Journal", "1234-5678", "1.2.2. First", "с 01.02.2022\nпо 01.02.2023"]}, {"page": 2, "cells": ["", "continued", "", "2.3.5. Second", ""]}, {"page": 2, "cells": ["", "", "", "2.3.6. Current", "с 02.02.2023"]}, {"page": 3, "cells": ["", "", "", "2.3.1. Future", "с 01.02.2027"]}, ] journal = parse_rows(rows)[0] assert journal["name"] == "Journal continued" and journal["pages"] == [1, 2, 3] assert journal["assignments"][0]["codes"] == ["1.2.2", "2.3.5"] assert active_codes(journal, "2026-09-15") == ["2.3.6"] assert active_codes(journal, "2023-02-01") == ["1.2.2", "2.3.5"] with pytest.raises(ValueError, match="numbering"): parse_rows([{"page": 1, "cells": ["2.", "Journal", "1234-5678", "1.2.2. Test", "с 01.02.2022"]}]) def test_ambiguous_titles_do_not_union_specialties_and_reviewed_matches_are_checked(): rows = [{"page": n, "cells": [f"{n}.", "Same title", str(n), code + ". Test", "с 01.02.2022"]} for n, code in [(1, "1.2.2"), (2, "2.3.1")]] journals = parse_rows(rows) k1 = {"journals": [{"name": "Same title"}, {"name": "Similar title"}]} result = build_reference(journals, k1, [], "2026-09-15") assert result[0]["status"] == "ambiguous" and result[0]["specialty_codes"] == [] assert result[1]["status"] == "not_found" and result[1]["specialty_codes"] == [] with pytest.raises(ValueError, match="title changed"): build_reference(journals, k1, [{"k1_name": "Similar title", "vak_row": 1, "vak_name": "Wrong title"}], "2026-09-15") def test_malformed_source_start_date_is_preserved_without_inventing_date(): journal = parse_rows([{"page": 1, "cells": ["1.", "Journal", "1234-5678", "1.3.8. Test", "с 01.02.200"]}])[0] assignment = journal["assignments"][0] assert assignment["source_dates"] == "с 01.02.200" assert assignment["valid_from"] is None and assignment["date_note"] assert active_codes(journal, "2026-09-15") == ["1.3.8"]