Skip to content
Snippets Groups Projects
Commit 4cd1a234 authored by Benedikt's avatar Benedikt
Browse files

added warnings to the invalide dict

parent 0a2753b6
No related branches found
No related tags found
No related merge requests found
...@@ -37,15 +37,19 @@ def process_units(unit_dict): ...@@ -37,15 +37,19 @@ def process_units(unit_dict):
if unit.valid: if unit.valid:
valid_units[key] = value # Assuming you want to return the string value valid_units[key] = value # Assuming you want to return the string value
else: else:
invalid_units[key] = value invalid_units[key] = {
"unit": value,
"warnings": unit.warnings
}
print(f"Warning: Invalid unit at {key} with value: {value}") print(f"Warning: Invalid unit at {key} with value: {value}")
except Exception as e: except Exception as e:
print(f"Error processing unit at {key} with value: {value}. Error: {e}") print(f"Error processing unit at {key} with value: {value}. Error: {e}")
invalid_units[key] = value # Optionally store the raw value or create an error object invalid_units[key] = {
"unit": value,
"error": str(e)
}
return valid_units, invalid_units return valid_units, invalid_units
def parse_and_process(xml_string): def parse_and_process(xml_string):
unit_dict = parse_plain_utf8_xml(xml_string) unit_dict = parse_plain_utf8_xml(xml_string)
valid_units, invalid_units = process_units(unit_dict) valid_units, invalid_units = process_units(unit_dict)
......
...@@ -67,7 +67,10 @@ def test_parse_xml(): ...@@ -67,7 +67,10 @@ def test_parse_xml():
# Check invalid units # Check invalid units
assert "4" in invalid_units # Line number for <si:unit>not_a_unit</si:unit> assert "4" in invalid_units # Line number for <si:unit>not_a_unit</si:unit>
assert invalid_units["4"] == "not_a_unit" assert invalid_units["4"]['unit'] == "not_a_unit"
assert invalid_units["4"]['warnings']==[r'String should start with \, string given was «not_a_unit»',
r'The identifier «not_a_unit» does not match any D-SI units!']
# Check invalid units # Check invalid units
assert "5" in invalid_units # Line number for <si:unit>not_a_unit</si:unit> assert "5" in invalid_units # Line number for <si:unit>not_a_unit</si:unit>
assert invalid_units["5"] == "\seconds" assert invalid_units["5"]['unit'] == "\seconds"
assert invalid_units["5"]['warnings']==[r'The identifier «seconds» does not match any D-SI units! Did you mean one of these «\second, \arcsecond»?']
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment