Skip to content

Commit

Permalink
Minor changes in import
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuynh95 committed Oct 2, 2024
1 parent 5113f98 commit 5b194b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.common.actions.wheel_input import ScrollOrigin
from lavague.sdk.utilities.format_utils import quote_numeric_yaml_values
from lavague.sdk.base_driver import (
BaseDriver,
JS_GET_INTERACTIVES,
Expand Down
27 changes: 27 additions & 0 deletions lavague-sdk/lavague/sdk/utilities/format_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import re

def quote_numeric_yaml_values(yaml_string: str) -> str:
"""Wrap numeric values in quotes in a YAML string.
This is helpful when the YAML might contain numeric values that are not wrapped in quotes which can cause issues when parsing the YAML.
In Navigation Engine, we expect values to be always strings, so this avoids issues when the YAML does not wrap numeric values in quotes, such as outputting "value: 01" instead of "value: '01'".
"""

def replace_value(match):
full_match, value = match.groups()
try:
# Try to convert to float to catch both integers and decimal numbers
float(value)
# If successful, it's a number, so wrap it in quotes
return f'value: "{value}"'
except ValueError:
# If it's not a number, return the original match
return full_match

# Regex to match 'value:' followed by a space and then any numeric
pattern = r"(value: ([\d.]+))"

# Replace values that are numeric
modified_yaml = re.sub(pattern, replace_value, yaml_string)

return modified_yaml

0 comments on commit 5b194b9

Please sign in to comment.