Skip to content

Commit

Permalink
BUGFIX: annotate_params.py unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Jun 17, 2024
1 parent 1044af7 commit a31420c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions MethodicConfigurator/annotate_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,18 @@ def get_xml_data(base_url: str, directory: str, filename: str) -> ET.Element:
raise SystemExit("permission denied to write online XML documentation to file") from e

# Parse the XML data
root = DET.fromstring(xml_data)
return DET.fromstring(xml_data)


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


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

def parse_parameter_metadata(xml_url: str, xml_dir: str, xml_file: str,
vehicle_type: str, max_line_length: int) -> Dict[str, Any]:
xml_root, param_default_dict = get_xml_data(xml_url, xml_dir, xml_file)
xml_root = get_xml_data(xml_url, xml_dir, xml_file)
param_default_dict = load_default_param_file(xml_dir)
doc_dict = create_doc_dict(xml_root, vehicle_type, max_line_length)
return doc_dict, param_default_dict

Expand Down
8 changes: 4 additions & 4 deletions unittests/annotate_params_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_get_xml_data_local_file(self, mock_load_param, mock_isfile, mock_open):
mock_load_param.side_effect = FileNotFoundError

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

# Check the result
self.assertIsInstance(result, ET.Element)
Expand All @@ -94,7 +94,7 @@ def test_get_xml_data_remote_file(self, mock_get):
pass

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

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

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

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

# Check the result
self.assertIsInstance(result, ET.Element)
Expand Down

0 comments on commit a31420c

Please sign in to comment.