-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_ontology_problem_models.py
93 lines (78 loc) · 3.09 KB
/
test_ontology_problem_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import pandas as pd
import pytest
from pandas.testing import assert_frame_equal
from dsp_tools.commands.xmlupload.models.ontology_problem_models import InvalidOntologyElementsInData
def test_print_problem_string_cls() -> None:
onto = InvalidOntologyElementsInData([("clsA", ["idA"], "wrong")], [], ontos_on_server=["test"])
msg = onto._compose_problem_string_for_cls()
assert msg == (
"The following resource(s) have an invalid resource type:\n\n"
" Resource Type: 'clsA'\n"
" Problem: 'wrong'\n"
" Resource ID(s):\n"
" - idA"
)
def test_print_problem_string_no_cls() -> None:
onto = InvalidOntologyElementsInData([], [], [])
assert not onto._compose_problem_string_for_cls()
def test_print_problem_string_prop() -> None:
onto = InvalidOntologyElementsInData([], [("propA", ["idA"], "wrong")], ["test"])
msg = onto._compose_problem_string_for_props()
assert msg == (
"The following resource(s) have invalid property type(s):\n\n"
" Property Name: 'propA'\n"
" Problem: 'wrong'\n"
" Resource ID(s):\n"
" - idA"
)
def test_print_problem_string_no_prop() -> None:
onto = InvalidOntologyElementsInData([], [], [])
assert not onto._compose_problem_string_for_props()
def test_execute_problem_protocol() -> None:
onto = InvalidOntologyElementsInData(
[("clsA", ["idA"], "wrong")],
[("propA", ["idA"], "wrong"), ("propB", ["idB", "idC"], "wrong")],
["test1", "test2"],
)
expected_msg = (
"\nSome property and/or class type(s) used in the XML are unknown.\n"
"The ontologies for your project on the server are:\n"
" - test1\n"
" - test2"
"\n\n---------------------------------------\n\n"
"The following resource(s) have an invalid resource type:\n\n"
" Resource Type: 'clsA'\n"
" Problem: 'wrong'\n"
" Resource ID(s):\n"
" - idA"
"\n\n---------------------------------------\n\n"
"The following resource(s) have invalid property type(s):\n\n"
" Property Name: 'propA'\n"
" Problem: 'wrong'\n"
" Resource ID(s):\n"
" - idA"
"\n----------------------------\n"
" Property Name: 'propB'\n"
" Problem: 'wrong'\n"
" Resource ID(s):\n"
" - idB\n"
" - idC"
)
msg, df = onto.execute_problem_protocol()
assert not df
assert msg == expected_msg
def test_get_problems_as_df() -> None:
onto = InvalidOntologyElementsInData(
[("clsA", ["idA"], "wrongA")], [("propB", ["idB"], "wrongB"), ("propC", ["idC1", "idC2"], "wrongC")], ["test"]
)
expected_df = pd.DataFrame(
{
"problematic type": ["clsA", "propB", "propC", "propC"],
"resource id": ["idA", "idB", "idC1", "idC2"],
"problem": ["wrongA", "wrongB", "wrongC", "wrongC"],
}
)
res_df = onto._get_problems_as_df()
assert_frame_equal(res_df, expected_df)
if __name__ == "__main__":
pytest.main([__file__])