Skip to content

Commit

Permalink
Add to_float to avoid parsing error
Browse files Browse the repository at this point in the history
Signed-off-by: hoangtungdinh <[email protected]>
  • Loading branch information
hoangtungdinh committed Sep 16, 2024
1 parent ceaf307 commit 259702e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ def check_rule(checker_data: models.CheckerData) -> None:

return

current_numeric_value = float(current_transition_time)
current_numeric_value = utils.to_float(current_transition_time)

if current_numeric_value is None:
continue

has_issue = current_numeric_value < 0

if has_issue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def check_rule(checker_data: models.CheckerData) -> None:

return

current_numeric_value = float(current_duration)
current_numeric_value = utils.to_float(current_duration)

if current_numeric_value is None:
continue

has_issue = current_numeric_value < 0

if has_issue:
Expand Down
7 changes: 7 additions & 0 deletions qc_openscenario/checks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
PARAMETER_PATTERN = re.compile(r"[$][A-Za-z_][A-Za-z0-9_]*")


def to_float(s):
try:
return float(s)
except (ValueError, TypeError):
return None


def get_root_without_default_namespace(path: str) -> etree._ElementTree:
with open(path, "rb") as raw_file:
xml_string = raw_file.read().decode()
Expand Down

0 comments on commit 259702e

Please sign in to comment.