-
Blanche Miret authoredBlanche Miret authored
test_parse_bio.py 2.23 KiB
import pytest
from nerval import evaluate
NO_EXIST_BIO = "no_exist.bio"
EMPTY_BIO = "test_empty.bio"
BAD_BIO = "test_bad.bio"
FAKE_ANNOT_BIO = "test_annot.bio"
FAKE_PREDICT_BIO = "test_predict.bio"
expected_parsed_annot = {
'entity_count': {'All': 3, 'DAT': 1, 'LOC': 1, 'PER': 1},
'tags': ['PER', 'PER', 'PER', 'PER', 'PER', 'PER',
'PER',
'PER', 'PER',
'PER',
'PER', 'PER', 'PER', 'PER', 'PER', 'PER',
'O',
'O','O','O',
'O',
'O', 'O', 'O','O',
'O',
'O','O',
'O',
'LOC','LOC','LOC','LOC','LOC',
'O',
'O','O',
'O',
'DAT','DAT','DAT','DAT',
'O',
'O'
],
'words': 'Gérard de Nerval was born in Paris in 1808 .'
}
expected_parsed_predict = {
'entity_count': {'All': 3, 'DAT': 1, '***': 1, 'PER': 1},
'tags': ['PER', 'PER', 'PER', 'PER', 'PER', 'PER',
'PER',
'PER', 'PER',
'PER',
'PER', 'PER', 'PER', 'PER', 'PER', 'PER', 'PER','PER',
'O',
'O','O','O','O','O',
'O',
'O','O',
'O',
'***','***','***','***','***',
'O',
'O','O',
'O',
'DAT','DAT','DAT','DAT',
'O',
'O', 'O'
],
'words': 'G*rard de *N*erval bo*rn in Paris in 1833 *.'
}
@pytest.mark.parametrize("test_input, expected",
[(FAKE_ANNOT_BIO, expected_parsed_annot),
(FAKE_PREDICT_BIO, expected_parsed_predict),
(EMPTY_BIO, None)],
)
def test_parse_bio(test_input, expected) :
assert evaluate.parse_bio(test_input) == expected
def test_parse_bio_bad_input() :
with pytest.raises(Exception) :
evaluate.parse_bio(BAD_BIO)
def test_parse_bio_no_input() :
with pytest.raises(AssertionError) :
evaluate.parse_bio(NO_EXIST_BIO)