Skip to content

Commit a31420c

Browse files
committed
BUGFIX: annotate_params.py unittests
1 parent 1044af7 commit a31420c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

MethodicConfigurator/annotate_params.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,18 @@ def get_xml_data(base_url: str, directory: str, filename: str) -> ET.Element:
345345
raise SystemExit("permission denied to write online XML documentation to file") from e
346346

347347
# Parse the XML data
348-
root = DET.fromstring(xml_data)
348+
return DET.fromstring(xml_data)
349349

350+
351+
def load_default_param_file(directory: str) -> Dict[str, Any]:
350352
# Load parameter default values if the 00_default.param file exists
351353
try:
352354
param_default_dict = Par.load_param_file_into_dict(os_path.join(directory, '00_default.param'))
353355
except FileNotFoundError:
354356
logging.warning("Default parameter file 00_default.param not found. No default values will be annotated.")
355357
logging.warning("Create one by using the command ./extract_param_defaults.py log_file.bin > 00_default.param")
356358
param_default_dict = {}
357-
return root, param_default_dict
359+
return param_default_dict
358360

359361

360362
def remove_prefix(text: str, prefix: str) -> str:
@@ -679,7 +681,8 @@ def get_xml_url(vehicle_type: str, firmware_version: str) -> str:
679681

680682
def parse_parameter_metadata(xml_url: str, xml_dir: str, xml_file: str,
681683
vehicle_type: str, max_line_length: int) -> Dict[str, Any]:
682-
xml_root, param_default_dict = get_xml_data(xml_url, xml_dir, xml_file)
684+
xml_root = get_xml_data(xml_url, xml_dir, xml_file)
685+
param_default_dict = load_default_param_file(xml_dir)
683686
doc_dict = create_doc_dict(xml_root, vehicle_type, max_line_length)
684687
return doc_dict, param_default_dict
685688

unittests/annotate_params_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_get_xml_data_local_file(self, mock_load_param, mock_isfile, mock_open):
7373
mock_load_param.side_effect = FileNotFoundError
7474

7575
# Call the function with a local file
76-
result, _d = get_xml_data("/path/to/local/file/", ".", "test.xml")
76+
result = get_xml_data("/path/to/local/file/", ".", "test.xml")
7777

7878
# Check the result
7979
self.assertIsInstance(result, ET.Element)
@@ -94,7 +94,7 @@ def test_get_xml_data_remote_file(self, mock_get):
9494
pass
9595

9696
# Call the function with a remote file
97-
result, _d = get_xml_data("http://example.com/", ".", "test.xml")
97+
result = get_xml_data("http://example.com/", ".", "test.xml")
9898

9999
# Check the result
100100
self.assertIsInstance(result, ET.Element)
@@ -117,7 +117,7 @@ def side_effect(filename):
117117
mock_open = mock.mock_open(read_data='<root></root>')
118118
with patch('builtins.open', mock_open):
119119
# Call the function with a filename that exists in the script directory
120-
result, _d = get_xml_data(BASE_URL, ".", PARAM_DEFINITION_XML_FILE)
120+
result = get_xml_data(BASE_URL, ".", PARAM_DEFINITION_XML_FILE)
121121

122122
# Check the result
123123
self.assertIsInstance(result, ET.Element)
@@ -161,7 +161,7 @@ def test_get_xml_data_valid_xml(self, mock_get):
161161
mock_get.return_value.text = "<root></root>"
162162

163163
# Call the function with a remote file
164-
result, _d = get_xml_data("http://example.com/", ".", "test.xml")
164+
result = get_xml_data("http://example.com/", ".", "test.xml")
165165

166166
# Check the result
167167
self.assertIsInstance(result, ET.Element)

0 commit comments

Comments
 (0)