def test_raises_exception_on_invalid_file() -> None: with pytest.raises(Exception) as exception_info: # The python test file is not a valid transducer. TransducerFile(__file__) exception_messages = " ".join(exception_info.value.args) assert "wrong or corrupt file?" in exception_messages
def test_raises_exception_on_missing_file() -> None: with pytest.raises(Exception) as exception_info: TransducerFile("/does-not-exist.hfstol") exception_messages = " ".join(exception_info.value.args) assert "Transducer not found" in exception_messages assert "‘/does-not-exist.hfstol’" in exception_messages
def relaxed_analyzer(): return TransducerFile(FST_DIR / settings.RELAXED_ANALYZER_FST_FILENAME)
def test_symbol_lookup1(fst: TransducerFile, surface: str, deep: list[list[str]]) -> None: assert fst.lookup_symbols(surface) == deep
def test_limit(fst: TransducerFile) -> None: assert fst.lookup("môswa", limit=1) == ["môswa+N+A+Sg"] # type: ignore
def test_create_from_path_obj() -> None: fst = TransducerFile(Path(TEST_FST)) assert fst.lookup("itwêwina") == ["itwêwin+N+I+Pl"]
def test_bulk_lookup_with_iterator(fst: TransducerFile) -> None: assert (fst.bulk_lookup(w for w in EXPECTED_BULK_LOOKUP_RESULT_1.keys()) == EXPECTED_BULK_LOOKUP_RESULT_1)
def test_bulk_lookup(fst: TransducerFile) -> None: assert (fst.bulk_lookup( EXPECTED_BULK_LOOKUP_RESULT_1.keys()) == EXPECTED_BULK_LOOKUP_RESULT_1)
def strict_generator_with_morpheme_boundaries(): return TransducerFile( FST_DIR / "crk-strict-generator-with-morpheme-boundaries.hfstol" )
def test_valid_lookup_with_invalid_symbol(fst: TransducerFile) -> None: assert fst.lookup("avocado") == [] assert fst.lookup("navajo") == []
def test_subsequent_lookups(fst: TransducerFile) -> None: assert fst.lookup("itwêwina") == ["itwêwin+N+I+Pl"] assert fst.lookup("nikî-nipân") == ["PV/ki+nipâw+V+AI+Ind+1Sg"]
def test_symbol_count() -> None: # If this returned a non-number, we’d get a TypeError here. assert TransducerFile(TEST_FST).symbol_count() > 0
def test_lookup_lemma_with_affixes(fst: TransducerFile, surface: str, example: Analysis) -> None: analyses = fst.lookup_lemma_with_affixes(surface) assert example in analyses
def fst() -> TransducerFile: return TransducerFile(TEST_FST)
def strict_analyzer(): return TransducerFile(FST_DIR / settings.STRICT_ANALYZER_FST_FILENAME)
def test_multiple_analyses(fst: TransducerFile) -> None: assert fst.lookup("môswa") == ["môswa+N+A+Sg", "môswa+N+A+Obv"]
def strict_generator(): return TransducerFile(FST_DIR / settings.STRICT_GENERATOR_FST_FILENAME)
def cmro_transcriptor(): return TransducerFile(settings.BASE_DIR / "resources" / "fst" / "default-to-cmro.hfstol")