Skip to content

Commit

Permalink
fix processor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu-g committed Oct 14, 2024
1 parent ba7a1df commit 41d8a30
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/processors/test_jumanpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def test_whitespace() -> None:
assert sent.morphemes[1].subpos == "空白"


@pytest.mark.skipif(not is_jumanpp_available, reason="Juman++ is not available")
def test_keep_id_sentence() -> None:
jumanpp = Jumanpp()
sent = Sentence.from_raw_text("外国人参政権")
Expand All @@ -128,6 +129,7 @@ def test_keep_id_sentence() -> None:
assert sent.sent_id == "test-1"


@pytest.mark.skipif(not is_jumanpp_available, reason="Juman++ is not available")
def test_keep_doc_id_document() -> None:
jumanpp = Jumanpp()
doc = Document.from_sentences(["米原発の電力供給", "米原発の521系の列車"])
Expand All @@ -140,6 +142,7 @@ def test_keep_doc_id_document() -> None:
assert sent.doc_id == "test"


@pytest.mark.skipif(not is_jumanpp_available, reason="Juman++ is not available")
def test_keep_id_document() -> None:
jumanpp = Jumanpp()
doc = Document.from_sentences(["米原発の電力供給", "米原発の521系の列車"])
Expand Down Expand Up @@ -198,6 +201,7 @@ def test_runtime_error2() -> None:
_ = jumanpp.apply_to_sentence(inp)


@pytest.mark.skipif(not is_jumanpp_available, reason="Juman++ is not available")
def test_repr() -> None:
jumanpp = Jumanpp(options=["--juman"], senter=RegexSenter())
assert repr(jumanpp) == "Jumanpp(executable='jumanpp', options=['--juman'], senter=RegexSenter())"
4 changes: 4 additions & 0 deletions tests/processors/test_knp.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def test_apply_to_document(text: str) -> None:
assert doc.text == text.replace("\r", "").replace("\n", "")


@pytest.mark.skipif(not is_knp_available, reason="KNP is not available")
def test_keep_id_sentence() -> None:
knp = KNP()
sent = Sentence.from_raw_text("外国人参政権")
Expand All @@ -121,6 +122,7 @@ def test_keep_id_sentence() -> None:
assert sent.sent_id == "test-1"


@pytest.mark.skipif(not is_knp_available, reason="KNP is not available")
def test_keep_doc_id_document() -> None:
knp = KNP()
doc = Document.from_sentences(["米原発の電力供給", "米原発の521系の列車"])
Expand All @@ -133,6 +135,7 @@ def test_keep_doc_id_document() -> None:
assert sent.doc_id == "test"


@pytest.mark.skipif(not is_knp_available, reason="KNP is not available")
def test_keep_id_document() -> None:
knp = KNP()
doc = Document.from_sentences(["米原発の電力供給", "米原発の521系の列車"])
Expand Down Expand Up @@ -200,6 +203,7 @@ def test_invalid_option() -> None:
# _ = KNP(options=["-tab", "--anaphora"])


@pytest.mark.skipif(not is_knp_available, reason="KNP is not available")
def test_repr() -> None:
knp = KNP(options=["-tab"], senter=RegexSenter(), jumanpp=Jumanpp())
assert (
Expand Down
3 changes: 3 additions & 0 deletions tests/processors/test_kwja.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def test_apply() -> None:
_ = kwja.apply(1) # type: ignore


@pytest.mark.skipif(not is_kwja_available, reason="KWJA is not available")
def test_keep_doc_id_document() -> None:
kwja = KWJA(options=["--model-size", "tiny"])
doc = Document.from_sentences(["こんにちは。", "さようなら。"])
Expand Down Expand Up @@ -162,12 +163,14 @@ def test_unsupported_option() -> None:
_ = KWJA(options=["--model-size", "tiny", "--input-format", "seq2seq"])


@pytest.mark.skipif(not is_kwja_available, reason="KWJA is not available")
def test_apply_to_sentence() -> None:
kwja = KWJA(options=["--model-size", "tiny"])
with pytest.raises(NotImplementedError):
_ = kwja.apply_to_sentence("外国人参政権")


@pytest.mark.skipif(not is_kwja_available, reason="KWJA is not available")
def test_repr() -> None:
kwja = KWJA(options=["--model-size", "tiny", "--tasks", "char,word"])
assert repr(kwja) == "KWJA(executable='kwja', options=['--model-size', 'tiny', '--tasks', 'char,word'])"

0 comments on commit 41d8a30

Please sign in to comment.