diff --git a/tests/parse/test_document.py b/tests/parse/test_document.py index 496a046861d67b1427cb0a42744704769abf3dbe..e8243e39de0767873e8b18abff97629c758b519a 100644 --- a/tests/parse/test_document.py +++ b/tests/parse/test_document.py @@ -1,36 +1,35 @@ -from bio_parser.parse.document import Document, Span, Tag, Token -from tests.parse import DATA_DIR import pytest +from bio_parser.parse.document import Document, Span, Tag, Token, _make_ner_label -from bio_parser.parse.document import _make_ner_label +from tests.parse import DATA_DIR FILEPATH = DATA_DIR / "valid.bio" -@pytest.fixture +@pytest.fixture() def document(): return Document.from_file(FILEPATH) @pytest.mark.parametrize( - "tag, label, output", - ( + ("tag", "label", "output"), + [ (Tag.OUTSIDE, None, "O"), (Tag.BEGINNING, "GPE", "B-GPE"), (Tag.INSIDE, "GPE", "I-GPE"), - ), + ], ) def test_make_ner_label(tag: Tag, label: str, output: str): assert _make_ner_label(tag=tag, label=label) == output @pytest.mark.parametrize( - "tag, label, error", - ( + ("tag", "label", "error"), + [ (Tag.OUTSIDE, "GPE", "Invalid label `GPE` with tag `O`"), (Tag.BEGINNING, None, "No named entity label found with tag `B`"), (Tag.INSIDE, None, "No named entity label found with tag `I`"), - ), + ], ) def test_make_ner_label_invalid(tag: Tag, label: str, error: str): with pytest.raises(AssertionError, match=error): @@ -71,7 +70,6 @@ def test_parse_document(document: Document): ] * len(" considers ") + ["B-VERB"] + ["I-VERB"] * len("anning") + ["O"] * len( " sidewalk delivery robots" ) - print(document.word_labels) assert document.word_labels == [ "GPE", "GPE", @@ -193,7 +191,7 @@ def test_parse_token(document: Document): @pytest.mark.parametrize( "annotation", - ("Something something", "Something A-GPE", "Something GPE-A", "Something A"), + ["Something something", "Something A-GPE", "Something GPE-A", "Something A"], ) def test_invalid_token(annotation: str): with pytest.raises(AssertionError, match="Could not parse annotation"): diff --git a/tests/parse/test_validate.py b/tests/parse/test_validate.py index b9ef73f02e6bd67fb60a201ab99d59f98cb8e864..160ea7b253e4f4987d1e2f9f725ab0a4425916db 100644 --- a/tests/parse/test_validate.py +++ b/tests/parse/test_validate.py @@ -1,5 +1,7 @@ import json + from bio_parser.parse.validate import run as validate + from tests.parse import DATA_DIR diff --git a/tests/ruff.toml b/tests/ruff.toml index 48ca1e68090a0c3c1d01488bb55dfb52a399ae3f..ac81ceaf0288462a6d2477c8f044c22357b2a743 100644 --- a/tests/ruff.toml +++ b/tests/ruff.toml @@ -1,3 +1,6 @@ +# Extend the `pyproject.toml` file in the parent directory... +extend = "../pyproject.toml" + ignore = [ # Pydocstyles. "D", diff --git a/tests/test_utils.py b/tests/test_utils.py index 0162bffb89ba6bbac3f07a2be5b2ba6d2f1f92e9..1269b25d0f9fe1cb919b31bd9f4b453679e58e02 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,6 +1,7 @@ import pytest from bio_parser.parse.document import Document -from bio_parser.utils import load_dataset, check_valid_bio, check_complete +from bio_parser.utils import check_complete, check_valid_bio, load_dataset + from tests import FIXTURES DATA = FIXTURES / "utils" @@ -8,7 +9,7 @@ DATA = FIXTURES / "utils" @pytest.mark.parametrize( "filenames", - ( + [ ( [ DATA / "bad_format.bio", @@ -27,16 +28,16 @@ DATA = FIXTURES / "utils" DATA / "bad_entity_name.bio", ] ), - ), + ], ) def test_check_valid_bio_raise(filenames): - with pytest.raises(Exception): + with pytest.raises(Exception): # noqa: PT011 check_valid_bio(filenames) @pytest.mark.parametrize( "filenames", - ( + [ ( [ DATA / "labels" / "example_0.bio", @@ -52,15 +53,15 @@ def test_check_valid_bio_raise(filenames): ] ), ([]), - ), + ], ) def test_check_valid_bio(filenames): check_valid_bio(filenames) @pytest.mark.parametrize( - "labels, predictions", - ( + ("labels", "predictions"), + [ ( [ DATA / "labels" / "example_0.bio", @@ -77,15 +78,15 @@ def test_check_valid_bio(filenames): [], [], ), - ), + ], ) def test_check_complete(labels, predictions): check_complete(labels, predictions) @pytest.mark.parametrize( - "labels, predictions, message", - ( + ("labels", "predictions", "message"), + [ ( [ DATA / "labels" / "example_0.bio", @@ -121,7 +122,7 @@ def test_check_complete(labels, predictions): ], "Missing prediction files: {'example_0.bio'}.\nMissing label files: {'example_1.bio'}.", ), - ), + ], ) def test_check_complete_raise(labels, predictions, message): with pytest.raises(FileNotFoundError, match=message): @@ -141,8 +142,8 @@ def test_load_dataset(): @pytest.mark.parametrize( - "label_dir, prediction_dir, message", - ( + ("label_dir", "prediction_dir", "message"), + [ ( DATA / "labels_empty", DATA / "predictions", @@ -153,7 +154,7 @@ def test_load_dataset(): DATA / "predictions_empty", "Empty prediction directory", ), - ), + ], ) def test_load_empty_dataset(label_dir, prediction_dir, message): with pytest.raises(FileNotFoundError, match=f"^{message}: .*"):