From 8b28e90d2f553203362468e70f0fe7cf7763e225 Mon Sep 17 00:00:00 2001 From: "Chaurasiya, Payal" Date: Thu, 26 Dec 2024 06:23:44 -0800 Subject: [PATCH] convert to json Signed-off-by: Chaurasiya, Payal --- .../test_suites/memory_logs_tests.py | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/end_to_end/test_suites/memory_logs_tests.py b/tests/end_to_end/test_suites/memory_logs_tests.py index b152cd0852..0a1be8e2c0 100644 --- a/tests/end_to_end/test_suites/memory_logs_tests.py +++ b/tests/end_to_end/test_suites/memory_logs_tests.py @@ -78,7 +78,7 @@ def _log_memory_usage(request, fed_obj): ), "Aggregator memory usage file is not available" # Log the aggregator memory usage details - memory_usage_dict = json.load(open(aggregator_memory_usage_file)) + memory_usage_dict = _convert_to_json(aggregator_memory_usage_file) # check memory usage entries for each round assert ( @@ -98,10 +98,28 @@ def _log_memory_usage(request, fed_obj): collaborator_memory_usage_file ), f"Memory usage file for collaborator {collaborator.collaborator_name} is not available" - memory_usage_dict = json.load(open(collaborator_memory_usage_file)) + memory_usage_dict = _convert_to_json(collaborator_memory_usage_file) assert ( len(memory_usage_dict) == request.config.num_rounds ), f"Memory usage details are not available for all rounds for collaborator {collaborator.collaborator_name}" log.info("Memory usage details are available for all participants") + + +def _convert_to_json(file): + """ + Reads a file containing JSON objects, one per line, and converts them into a list of parsed JSON objects. + + Args: + file (str): The path to the file containing JSON objects. + + Returns: + list: A list of parsed JSON objects. + """ + with open(file, 'r') as infile: + json_objects = infile.readlines() + + # Parse each JSON object + parsed_json_objects = [json.loads(obj) for obj in json_objects] + return parsed_json_objects