fix tests

This commit is contained in:
Jesse Bannon 2026-01-03 21:09:22 -08:00
parent 9745f6130d
commit 2eabb3ee62
2 changed files with 18 additions and 15 deletions

View file

@ -105,6 +105,19 @@ class ScriptUtils:
raise UNREACHABLE raise UNREACHABLE
@classmethod
def _get_quote_char(cls, arg: str) -> str:
contains_single_quote = "'" in arg
contains_double_quote = '"' in arg
if not contains_single_quote and not contains_double_quote:
return '"'
if not contains_single_quote and contains_double_quote:
return "'"
if contains_single_quote and not contains_double_quote:
return '"'
return "'''"
@classmethod @classmethod
def _to_script_code(cls, arg: Argument, top_level: bool = False) -> str: def _to_script_code(cls, arg: Argument, top_level: bool = False) -> str:
if not top_level and isinstance(arg, (Integer, Boolean, Float)): if not top_level and isinstance(arg, (Integer, Boolean, Float)):
@ -114,17 +127,7 @@ class ScriptUtils:
if arg.native == "": if arg.native == "":
return "" if top_level else "''" return "" if top_level else "''"
contains_single_quote = "'" in arg.native quote = cls._get_quote_char(arg.native)
contains_double_quote = '"' in arg.native
if not contains_single_quote and not contains_double_quote:
quote = '"'
elif not contains_single_quote and contains_double_quote:
quote = "'"
elif contains_single_quote and not contains_double_quote:
quote = '"'
else:
quote = "'''"
return arg.native if top_level else f"{quote}{arg.native}{quote}" return arg.native if top_level else f"{quote}{arg.native}{quote}"

View file

@ -115,12 +115,12 @@ class TestUnstructuredDictFormatterValidator(object):
assert len(validator.dict) == 8 assert len(validator.dict) == 8
assert all(isinstance(val, expected_formatter_class) for val in validator.dict.values()) assert all(isinstance(val, expected_formatter_class) for val in validator.dict.values())
assert validator.dict_with_format_strings == { assert validator.dict_with_format_strings == {
"key1": "{ %concat( %string( '''string with ''' ), %string( variable ) ) }", "key1": '{ %concat( %string( "string with " ), %string( variable ) ) }',
"key2": "no variables", "key2": "no variables",
"key3": "{ %int(3) }", "key3": "{ %int(3) }",
"key4": "{ %float(4.132) }", "key4": "{ %float(4.132) }",
"key5": "{ %bool(True) }", "key5": "{ %bool(True) }",
"key6": "{ { %concat( %string( variable ), %string( '''_key''' ) ): '''value''', '''static_key''': %concat( %string( variable ), %string( '''_value''' ) ) } }", "key6": '{ { %concat( %string( variable ), %string( "_key" ) ): "value", "static_key": %concat( %string( variable ), %string( "_value" ) ) } }',
"key7": "{ [ '''list_1''', %concat( %string( '''list_''' ), %string( variable_2 ) ) ] }", "key7": '{ [ "list_1", %concat( %string( "list_" ), %string( variable_2 ) ) ] }',
"key8": "{ %concat( %string( '''string ''' ), %string( variable1 ), %string( ''' with multiple ''' ), %string( variable2 ) ) }", "key8": '{ %concat( %string( "string " ), %string( variable1 ), %string( " with multiple " ), %string( variable2 ) ) }',
} }