Skip to content

Commit

Permalink
fix(xmlupload): subpar output of onto consistency check (DEV-3727) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum authored Sep 8, 2024
1 parent 2bf8ad8 commit edb58a9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
23 changes: 15 additions & 8 deletions src/dsp_tools/commands/xmlupload/models/ontology_problem_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

separator = "\n "
list_separator = "\n - "
medium_separator = "\n----------------------------\n"
grand_separator = "\n\n---------------------------------------\n\n"
medium_separator = "\n\n"
maximum_prints = 50


Expand All @@ -32,12 +31,12 @@ def execute_problem_protocol(self) -> tuple[str, pd.DataFrame | None]:
base_msg = (
f"\nSome property and/or class type(s) used in the XML are unknown.\n"
f"The ontologies for your project on the server are:{list_separator}"
f"{list_separator.join(self.ontos_on_server)}{grand_separator}"
f"{list_separator.join(self.ontos_on_server)}{medium_separator}"
)
if cls_msg := self._compose_problem_string_for_cls():
base_msg += cls_msg + grand_separator
base_msg += cls_msg + "\n"
if prop_msg := self._compose_problem_string_for_props():
base_msg += prop_msg
base_msg += prop_msg + "\n"
if (
self._calculate_num_resources(self.classes) + self._calculate_num_resources(self.properties)
> maximum_prints
Expand Down Expand Up @@ -92,7 +91,11 @@ def _format_cls(cls_tup: tuple[str, list[str], str]) -> str:

problems = [_format_cls(x) for x in self.classes]

return "The following resource(s) have an invalid resource type:\n\n" + medium_separator.join(problems)
return (
f"The following resource(s) have an invalid resource type:{medium_separator}"
+ medium_separator.join(problems)
+ "\n"
)
else:
return None

Expand All @@ -110,7 +113,11 @@ def _format_prop(prop_tup: tuple[str, list[str], str]) -> str:
)

problems = [_format_prop(x) for x in self.properties]
return "The following resource(s) have invalid property type(s):\n\n" + medium_separator.join(problems)
return (
f"The following resource(s) have invalid property type(s):{medium_separator}"
+ medium_separator.join(problems)
+ "\n"
)
else:
return None

Expand Down Expand Up @@ -144,7 +151,7 @@ def execute_problem_protocol(self) -> tuple[str, pd.DataFrame | None]:
df = self._get_problems_as_df()
if len(df) > maximum_prints:
return base_msg, df
return base_msg + grand_separator + _make_msg_from_df(df), None
return base_msg + medium_separator + _make_msg_from_df(df), None

def _get_problems_as_df(self) -> pd.DataFrame:
df = pd.DataFrame(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,13 @@ def test_error_on_nonexistent_onto_name() -> None:
"\nSome property and/or class type(s) used in the XML are unknown.\n"
"The ontologies for your project on the server are:\n"
" - testonto\n"
" - knora-api\n\n"
"---------------------------------------\n\n"
" - knora-api"
"\n\n"
"The following resource(s) have an invalid resource type:\n\n"
" Resource Type: ':minimalResource'\n"
" Problem: 'Unknown ontology prefix'\n"
" Resource ID(s):\n"
" - the_only_resource\n\n"
"---------------------------------------\n\n"
)
with pytest.raises(InputError, match=expected):
do_xml_consistency_check_with_ontology(ontology_client, root)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_print_problem_string_cls(self) -> None:
" Resource Type: 'clsA'\n"
" Problem: 'wrong'\n"
" Resource ID(s):\n"
" - idA"
" - idA\n"
)

def test_print_problem_string_no_cls(self) -> None:
Expand All @@ -32,7 +32,7 @@ def test_print_problem_string_prop(self) -> None:
" Property Name: 'propA'\n"
" Problem: 'wrong'\n"
" Resource ID(s):\n"
" - idA"
" - idA\n"
)

def test_print_problem_string_no_prop(self) -> None:
Expand All @@ -50,24 +50,25 @@ def test_execute_problem_protocol(self) -> None:
"The ontologies for your project on the server are:\n"
" - test1\n"
" - test2"
"\n\n---------------------------------------\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"
"\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"
"\n\n"
" Property Name: 'propB'\n"
" Problem: 'wrong'\n"
" Resource ID(s):\n"
" - idB\n"
" - idC"
"\n\n"
)
msg, df = onto.execute_problem_protocol()
assert not df
Expand Down Expand Up @@ -141,7 +142,7 @@ def test_make_msg_from_df(self) -> None:
"Resource ID: 'id1' | Resource Type: ':restype'\n"
" - Property Name: ':rich' -> Encoding Used: 'utf8'\n"
" - Property Name: ':simple' -> Encoding Used: 'xml'"
"\n----------------------------\n"
"\n\n"
"Resource ID: 'id2' | Resource Type: ':restype'\n"
" - Property Name: ':rich' -> Encoding Used: 'utf8'"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ def test_check_all_classes_and_properties_in_onto_problem() -> None:
"The ontologies for your project on the server are:\n"
" - test\n"
" - knora-api"
"\n\n---------------------------------------\n\n"
"\n\n"
"The following resource(s) have an invalid resource type:\n\n"
" Resource Type: 'knora'\n"
" Problem: 'Invalid Class Type'\n"
" Resource ID(s):\n"
" - idA"
"\n\n---------------------------------------\n\n"
"\n\n"
)
res_msg = _check_all_classes_and_properties_in_onto(classes, properties, onto_lookup)
assert res_msg == expected_msg
Expand Down Expand Up @@ -626,10 +626,10 @@ def test_analyse_all_text_value_encodings_are_correct_problems() -> None:
"\nSome text encodings used in the XML data file are not conform with the gui_element "
"specified in the JSON ontology.\n"
"Please consult the ontology regarding the assigned gui_elements."
"\n\n---------------------------------------\n\n"
"\n\n"
"Resource ID: 'resC' | Resource Type: ':TestThing2'\n"
" - Property Name: ':hasRichtext' -> Encoding Used: 'utf8'"
"\n----------------------------\n"
"\n\n"
"Resource ID: 'test_thing_1' | Resource Type: ':TestThing'\n"
" - Property Name: ':hasText' -> Encoding Used: 'xml'"
)
Expand Down

0 comments on commit edb58a9

Please sign in to comment.