diff --git a/tests/armarx/armarx_memory/ltm/test_storing.py b/tests/armarx/armarx_memory/ltm/test_storing.py index 1600c6e9baeb081bcf51c6c09db91a2a972455f1..a1a30d461c160d11045ddf888ea073d3971cb697 100644 --- a/tests/armarx/armarx_memory/ltm/test_storing.py +++ b/tests/armarx/armarx_memory/ltm/test_storing.py @@ -71,7 +71,8 @@ def test_access_data_from_instance(create_test_memory): data = entity_instance.data assert isinstance(data, AronDict) aron_dict = data - assert aron_dict == AronDict(elements=["testData", AronInt(["TestInteger"], 42)], path=["t"]) + assert isinstance(aron_dict.elements["testData"], AronInt) + assert aron_dict.elements["testData"].value == 42 assert aron_dict.path == ["t"] def test_data_conversion_primitive(create_test_memory): @@ -167,6 +168,92 @@ def test_store_snapshot(create_test_memory): assert True +def test_store_full_memory(create_test_memory): + memory :Memory = create_test_memory + for coreSegment in memory.coreSegments.values(): + for providerSegment in coreSegment.providerSegments.values(): + for entity in providerSegment.entities.values(): + entity.store() + test_dir = os.path.dirname(os.path.abspath(__file__)) + intended_path_dir = os.path.join(test_dir, "testData/2024_07_16", "LTM", "TestWritingMemory", "TestCoreSegment", "TestProviderSegment", "TestEntity", "100", "0") + assert os.path.isdir(intended_path_dir) + intended_data_path = os.path.join(intended_path_dir, "data.aron.json") + intended_metadata_path = os.path.join(intended_path_dir, "metadata.aron.json") + assert os.path.isfile(intended_data_path) + assert os.path.isfile(intended_metadata_path) + + correct_info_path_dir = os.path.join(test_dir, "testData/2024_07_16", "LTM", "TestWritingMemoryIntended", "TestCoreSegment", "TestProviderSegment", "TestEntity", "100", "0") + correct_data_path = os.path.join(correct_info_path_dir, "data.aron.json") + correct_metadata_path = os.path.join(correct_info_path_dir, "metadata.aron.json") + + # assert that the files also contain the correct information: + correct_data_string = "" + try: + with open(correct_data_path, 'r') as json_file_intended_data: + # Load the JSON data and dump it as a normalized string + data = json.load(json_file_intended_data) + correct_data_string = json.dumps(data, sort_keys=True) # Sort keys for consistent comparison + except FileNotFoundError: + print(f"File not found: {correct_data_path}") + assert False, "File not found" + except json.JSONDecodeError as e: + print(f"Error decoding JSON in file {correct_data_path}: {e}") + assert False, "Error decoding JSON" + + written_data_string = "" + try: + with open(intended_data_path, 'r') as json_file_intended_data: + # Load the JSON data and dump it as a normalized string + data = json.load(json_file_intended_data) + written_data_string = json.dumps(data, sort_keys=True) # Sort keys for consistent comparison + except FileNotFoundError: + print(f"File not found: {intended_data_path}") + assert False, "File not found" + except json.JSONDecodeError as e: + print(f"Error decoding JSON in file {intended_data_path}: {e}") + assert False, "Error decoding JSON" + + if correct_data_string is not None and written_data_string is not None: + if correct_data_string == written_data_string: + print("The content of both JSON files is the same for data.aron.json.") + else: + assert False, "The content of the JSON files is different." + + # assert that the files also contain the correct information: + correct_metadata_string = "" + try: + with open(correct_metadata_path, 'r') as json_file_intended_data: + # Load the JSON data and dump it as a normalized string + data = json.load(json_file_intended_data) + correct_metadata_string = json.dumps(data, sort_keys=True) # Sort keys for consistent comparison + except FileNotFoundError: + print(f"File not found: {correct_metadata_path}") + assert False, "File not found" + except json.JSONDecodeError as e: + print(f"Error decoding JSON in file {correct_metadata_path}: {e}") + assert False, "Error decoding JSON" + + written_metadata_string = "" + try: + with open(intended_metadata_path, 'r') as json_file_intended_data: + # Load the JSON data and dump it as a normalized string + data = json.load(json_file_intended_data) + written_metadata_string = json.dumps(data, sort_keys=True) # Sort keys for consistent comparison + except FileNotFoundError: + print(f"File not found: {intended_metadata_path}") + assert False, "File not found" + except json.JSONDecodeError as e: + print(f"Error decoding JSON in file {intended_metadata_path}: {e}") + assert False, "Error decoding JSON" + + if correct_metadata_string is not None and written_metadata_string is not None: + if correct_metadata_string == written_metadata_string: + print("The content of both JSON files is the same for metadata.aron.json.") + else: + assert False, "The content of the JSON files is different." + + assert True + if __name__ == "__main__": pytest.main() \ No newline at end of file