def test_execute_passing_test_case(a_b_transducer_path: Path): test_case = _TestCase.from_description( {"upper": "a", "expect": "b"}, location=Path("test_verbs.toml") ) with FST.load_from_path(a_b_transducer_path) as fst: result = test_case.execute(fst) assert isinstance(result, PassedTestResult)
def test_path_exists_only_during_command_fomabin(a_b_transducer_path: Path): """ Test that a new Fomabin is created and disappears after the context. """ fst_desc = {"fomabin": a_b_transducer_path} with FST.load_from_description(fst_desc) as fst: assert fst.path.exists() assert not fst.path.exists()
def test_path_exists_only_during_command_xfst(fst_desc, rewrite_rules_path: Path): """ Test that the FST can be loaded from an XFST script. """ fst_desc["eval"] = rewrite_rules_path with FST.load_from_description(fst_desc) as fst: assert fst.path.exists() assert not fst.path.exists()
def test_load_fst_from_xfst_file(rewrite_rules_path: Path): """ Test that the FST can be loaded from an XFST script. """ fst_desc = {"eval": rewrite_rules_path, "regex": "Cleanup"} test_case = {"upper": "<", "expect": ""} with FST.load_from_description(fst_desc) as fst: results = execute_test_case(fst.path, test_case) assert results.n_passed == 1 assert results.n_total == 1
def test_load_from_path(a_b_transducer_path: Path): """ Test that an FST can be used from an existing path. """ with FST.load_from_path(a_b_transducer_path) as fst: assert fst.path.exists() assert fst.path != a_b_transducer_path assert fst.apply(["a"], direction="down") == {"a": ["b"]} assert not fst.path.exists()
def test_load_fst_from_xfst_with_compose(test_case, rewrite_rules_path: Path): """ Using the 'compose' feature to load an XFST script with multiple defined regexes. """ rules = ["TInsertion", "NiTDeletion", "Cleanup"] fst_desc = {"eval": rewrite_rules_path, "compose": rules} with FST.load_from_description(fst_desc) as fst: results = execute_test_case(fst.path, test_case) assert results.n_passed == 1 assert results.n_total == 1
def test_execute_failing_test_case(a_b_transducer_path: Path): test_case = _TestCase.from_description( {"upper": "a", "expect": "a"}, location=Path("test_verbs.toml") ) with FST.load_from_path(a_b_transducer_path) as fst: result = test_case.execute(fst) assert isinstance(result, FailedTestResult) assert result.location == test_case.location assert result.input == "a" assert result.expected == ["a"] assert result.actual == ["b"]
def test_load_fst_from_fomabin(a_b_transducer_path: Path): """ Test that the FST can be loaded from a fomabin. """ # Check that we can load this FST directly. fst_desc = {"fomabin": a_b_transducer_path} test_case = {"upper": "a", "expect": "b"} with FST.load_from_description(fst_desc) as fst: results = execute_test_case(fst.path, test_case) assert results.n_passed == 1 assert results.n_total == 1
def test_fst_execute_fomabin(a_b_transducer_path: Path): fst_desc = {"fomabin": a_b_transducer_path} with FST.load_from_description(fst_desc) as fst: results = fst.apply(["a"], direction="down") assert results == {"a": ["b"]}