Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
BIO Parser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Named Entity Recognition
BIO Parser
Commits
253bd2f7
Verified
Commit
253bd2f7
authored
1 year ago
by
Yoann Schneider
Browse files
Options
Downloads
Patches
Plain Diff
Fix ruff config for tests folder
parent
ecabf84a
No related branches found
No related tags found
1 merge request
!4
Fix ruff config for tests folder
Pipeline
#152478
passed
1 year ago
Stage: test
Stage: build
Stage: deploy
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
tests/parse/test_document.py
+10
-12
10 additions, 12 deletions
tests/parse/test_document.py
tests/parse/test_validate.py
+2
-0
2 additions, 0 deletions
tests/parse/test_validate.py
tests/ruff.toml
+3
-0
3 additions, 0 deletions
tests/ruff.toml
tests/test_utils.py
+16
-15
16 additions, 15 deletions
tests/test_utils.py
with
31 additions
and
27 deletions
tests/parse/test_document.py
+
10
−
12
View file @
253bd2f7
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
"
):
...
...
This diff is collapsed.
Click to expand it.
tests/parse/test_validate.py
+
2
−
0
View file @
253bd2f7
import
json
from
bio_parser.parse.validate
import
run
as
validate
from
tests.parse
import
DATA_DIR
...
...
This diff is collapsed.
Click to expand it.
tests/ruff.toml
+
3
−
0
View file @
253bd2f7
# Extend the `pyproject.toml` file in the parent directory...
extend
=
"../pyproject.toml"
ignore
=
[
# Pydocstyles.
"D"
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_utils.py
+
16
−
15
View file @
253bd2f7
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
'
}.
\n
Missing 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
}
: .*
"
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment