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
set_test_key("_CAOSDB_ADV_TEST_SUITE")
def rfp(*pathcomponents):
"""
Return full path.
......@@ -183,6 +184,7 @@ def setup(clear_database):
c.extend(testdata)
c.insert()
def test_successful_export():
records = next(db.execute_query("FIND Record", page_length=50))
tmp_path = Path('temp_test_successful_export.xlsx')
......@@ -252,7 +254,6 @@ def test_export_list_refs(tmpdir):
# Check: Filled XLSX
filled_generated = load_workbook(tmpdir / "result.xlsx")
# For the moment: just check a few samples
assert filled_generated.get_sheet_names() == ['Training',
'Training.Organisation',
'Training.Organisation.Person',
......
......@@ -21,6 +21,7 @@
"""Utilities for the tests.
"""
from datetime import datetime
from typing import Iterable, Union
from openpyxl import Workbook
......@@ -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,
path=this_path)
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
# Case 2: exists only in one collection
existing = json1.get(key, json2.get(key))
......@@ -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,
path=this_path)
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]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment