|
| 1 | +# === CHECKS === |
| 2 | +# id: check_oewn_source_preserves_sense_order |
| 3 | +# proves: oewn_source_preserves_sense_order |
| 4 | +# call: self::test_loader_preserves_source_sense_order |
| 5 | +# requires: python3, pyyaml |
| 6 | +# timeout: 30 |
| 7 | +# mutates: filesystem |
| 8 | +# cleanup: tempdir_teardown |
| 9 | +# === END CHECKS === |
| 10 | + |
| 11 | +from __future__ import annotations |
| 12 | + |
| 13 | +from pathlib import Path |
| 14 | + |
| 15 | +import pytest |
| 16 | + |
| 17 | +import english_gonol.language.source as source |
| 18 | + |
| 19 | + |
| 20 | +def test_loader_preserves_source_sense_order( |
| 21 | + tmp_path: Path, |
| 22 | + monkeypatch: pytest.MonkeyPatch, |
| 23 | +) -> None: |
| 24 | + pytest.importorskip("yaml") |
| 25 | + |
| 26 | + # The identifiers are intentionally reverse-lexicographic. Sorting them |
| 27 | + # would silently destroy the source ordinal evidence used by construction. |
| 28 | + (tmp_path / "frames.yaml").write_text("{}\n", encoding="utf-8") |
| 29 | + (tmp_path / "entries-test.yaml").write_text( |
| 30 | + """word:\n" |
| 31 | + " n:\n" |
| 32 | + " sense:\n" |
| 33 | + " - id: z-sense\n" |
| 34 | + " synset: s-z\n" |
| 35 | + " - id: a-sense\n" |
| 36 | + " synset: s-a\n" |
| 37 | + """, |
| 38 | + encoding="utf-8", |
| 39 | + ) |
| 40 | + (tmp_path / "noun.test.yaml").write_text( |
| 41 | + """s-z:\n" |
| 42 | + " partOfSpeech: n\n" |
| 43 | + " members: [word]\n" |
| 44 | + " definition: [first definition]\n" |
| 45 | + "s-a:\n" |
| 46 | + " partOfSpeech: n\n" |
| 47 | + " members: [word]\n" |
| 48 | + " definition: [second definition]\n" |
| 49 | + """, |
| 50 | + encoding="utf-8", |
| 51 | + ) |
| 52 | + |
| 53 | + monkeypatch.setattr(source, "OEWN_EXPECTED_WORD_COUNT", 1) |
| 54 | + monkeypatch.setattr(source, "OEWN_EXPECTED_SYNSET_COUNT", 2) |
| 55 | + |
| 56 | + snapshot = source.load_oewn_2025(tmp_path) |
| 57 | + assert len(snapshot.lexemes) == 1 |
| 58 | + assert [sense.sense_id for sense in snapshot.lexemes[0].senses] == [ |
| 59 | + "z-sense", |
| 60 | + "a-sense", |
| 61 | + ] |
0 commit comments