Skip to content
Snippets Groups Projects
Verified Commit 253bd2f7 authored by Yoann Schneider's avatar Yoann Schneider :tennis:
Browse files

Fix ruff config for tests folder

parent ecabf84a
No related branches found
No related tags found
1 merge request!4Fix ruff config for tests folder
Pipeline #152478 passed
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"):
......
import json
from bio_parser.parse.validate import run as validate
from tests.parse import DATA_DIR
......
# Extend the `pyproject.toml` file in the parent directory...
extend = "../pyproject.toml"
ignore = [
# Pydocstyles.
"D",
......
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}: .*"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment