# -*- coding: utf-8 -*- import pytest from nerval import evaluate FAKE_ANNOT_BIO = "tests/test_annot.bio" FAKE_PREDICT_BIO = "tests/test_predict.bio" EMPTY_BIO = "tests/test_empty.bio" FAKE_BIO_NESTED = "tests/test_nested.bio" expected_scores_nested = { "All": { "P": 1.0, "R": 1.0, "F1": 1.0, "predicted": 3, "matched": 3, "Support": 3, }, "PER": {"P": 1.0, "R": 1.0, "F1": 1.0, "predicted": 1, "matched": 1, "Support": 1}, "LOC": { "P": 1.0, "R": 1.0, "F1": 1.0, "predicted": 2, "matched": 2, "Support": 2, }, } expected_scores = { "***": { "P": 0.0, "R": None, "F1": None, "predicted": 1, "matched": 0, "Support": None, }, "DAT": {"P": 0.0, "R": 0.0, "F1": 0, "predicted": 1, "matched": 0, "Support": 1}, "All": { "P": 0.3333333333333333, "R": 0.3333333333333333, "F1": 0.3333333333333333, "predicted": 3, "matched": 1, "Support": 3, }, "PER": {"P": 1.0, "R": 1.0, "F1": 1.0, "predicted": 1, "matched": 1, "Support": 1}, "LOC": { "P": None, "R": 0.0, "F1": None, "predicted": None, "matched": 0, "Support": 1, }, } @pytest.mark.parametrize( "test_input, expected", [ ((FAKE_ANNOT_BIO, FAKE_PREDICT_BIO), expected_scores), ((FAKE_BIO_NESTED, FAKE_BIO_NESTED), expected_scores_nested), ], ) def test_run(test_input, expected): # print(evaluate.run(*test_input)) assert evaluate.run(*test_input) == expected def test_run_empty_bio(): with pytest.raises(Exception): evaluate.run(EMPTY_BIO, EMPTY_BIO) def test_run_empty_entry(): with pytest.raises(TypeError): evaluate.run(None, None)