Skip to content
Snippets Groups Projects
Verified Commit a0332e09 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

TEST: Try casting before comparison.

parent a869af41
No related branches found
No related tags found
No related merge requests found
Pipeline #62813 failed
...@@ -47,6 +47,7 @@ from utils import ( # noqa: E402, pylint: disable=wrong-import-position ...@@ -47,6 +47,7 @@ from utils import ( # noqa: E402, pylint: disable=wrong-import-position
set_test_key("_CAOSDB_ADV_TEST_SUITE") set_test_key("_CAOSDB_ADV_TEST_SUITE")
def rfp(*pathcomponents): def rfp(*pathcomponents):
""" """
Return full path. Return full path.
...@@ -166,11 +167,11 @@ def setup(clear_database): ...@@ -166,11 +167,11 @@ def setup(clear_database):
.add_property(test_prop_2, value=0) .add_property(test_prop_2, value=0)
.add_property(test_prop_3, value=test_person_2)) .add_property(test_prop_3, value=test_person_2))
test_conference_0 = (db.Record(description="Only for Also").add_parent(test_rt_2) test_conference_0 = (db.Record(description="Only for Also").add_parent(test_rt_2)
.add_property(test_prop_4, value=[test_person_1])) .add_property(test_prop_4, value=[test_person_1]))
test_conference_1 = (db.Record(name="Official Conf", description="For everyone") test_conference_1 = (db.Record(name="Official Conf", description="For everyone")
.add_parent(test_rt_2) .add_parent(test_rt_2)
.add_property(test_prop_4, .add_property(test_prop_4,
value=[test_person_0, test_person_1, test_person_2])) value=[test_person_0, test_person_1, test_person_2]))
testdata = [test_rt_0, test_rt_1, test_rt_2, testdata = [test_rt_0, test_rt_1, test_rt_2,
test_prop_0, test_prop_1, test_prop_2, test_prop_0, test_prop_1, test_prop_2,
test_prop_3, test_prop_4, test_prop_3, test_prop_4,
...@@ -183,6 +184,7 @@ def setup(clear_database): ...@@ -183,6 +184,7 @@ def setup(clear_database):
c.extend(testdata) c.extend(testdata)
c.insert() c.insert()
def test_successful_export(): def test_successful_export():
records = next(db.execute_query("FIND Record", page_length=50)) records = next(db.execute_query("FIND Record", page_length=50))
tmp_path = Path('temp_test_successful_export.xlsx') tmp_path = Path('temp_test_successful_export.xlsx')
...@@ -252,7 +254,6 @@ def test_export_list_refs(tmpdir): ...@@ -252,7 +254,6 @@ def test_export_list_refs(tmpdir):
# Check: Filled XLSX # Check: Filled XLSX
filled_generated = load_workbook(tmpdir / "result.xlsx") filled_generated = load_workbook(tmpdir / "result.xlsx")
# For the moment: just check a few samples # For the moment: just check a few samples
assert filled_generated.get_sheet_names() == ['Training', assert filled_generated.get_sheet_names() == ['Training',
'Training.Organisation', 'Training.Organisation',
'Training.Organisation.Person', 'Training.Organisation.Person',
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
"""Utilities for the tests. """Utilities for the tests.
""" """
from datetime import datetime
from typing import Iterable, Union from typing import Iterable, Union
from openpyxl import Workbook from openpyxl import Workbook
...@@ -48,7 +49,8 @@ Raise an assertion exception if they are not equal.""" ...@@ -48,7 +49,8 @@ Raise an assertion exception if they are not equal."""
assert_equal_jsons(el1, el2, allow_none=allow_none, allow_empty=allow_empty, assert_equal_jsons(el1, el2, allow_none=allow_none, allow_empty=allow_empty,
path=this_path) path=this_path)
continue continue
assert el1 == el2, f"Values at path {this_path} are not equal:\n{el1},\n{el2}" assert equals_with_casting(el1, el2), (
f"Values at path {this_path} are not equal:\n{el1},\n{el2}")
continue continue
# Case 2: exists only in one collection # Case 2: exists only in one collection
existing = json1.get(key, json2.get(key)) existing = json1.get(key, json2.get(key))
...@@ -66,7 +68,18 @@ Raise an assertion exception if they are not equal.""" ...@@ -66,7 +68,18 @@ Raise an assertion exception if they are not equal."""
assert_equal_jsons(el1, el2, allow_none=allow_none, allow_empty=allow_empty, assert_equal_jsons(el1, el2, allow_none=allow_none, allow_empty=allow_empty,
path=this_path) path=this_path)
else: else:
assert el1 == el2, f"Values at path {this_path} are not equal:\n{el1},\n{el2}" assert equals_with_casting(el1, el2), (
f"Values at path {this_path} are not equal:\n{el1},\n{el2}")
def equals_with_casting(value1, value2) -> bool:
"""Compare two values, return True if equal, False otherwise. Try to cast to clever datatypes.
"""
try:
return datetime.fromisoformat(value1) == datetime.fromisoformat(value2)
except (ValueError, TypeError):
pass
return value1 == value2
def purge_from_json(data: Union[dict, list], remove_keys: list[str]) -> Union[dict, list]: def purge_from_json(data: Union[dict, list], remove_keys: list[str]) -> Union[dict, list]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment