fix tests
This commit is contained in:
parent
9745f6130d
commit
2eabb3ee62
2 changed files with 18 additions and 15 deletions
|
|
@ -105,6 +105,19 @@ class ScriptUtils:
|
|||
|
||||
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
|
||||
def _to_script_code(cls, arg: Argument, top_level: bool = False) -> str:
|
||||
if not top_level and isinstance(arg, (Integer, Boolean, Float)):
|
||||
|
|
@ -114,17 +127,7 @@ class ScriptUtils:
|
|||
if arg.native == "":
|
||||
return "" if top_level else "''"
|
||||
|
||||
contains_single_quote = "'" in 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 = "'''"
|
||||
quote = cls._get_quote_char(arg.native)
|
||||
|
||||
return arg.native if top_level else f"{quote}{arg.native}{quote}"
|
||||
|
||||
|
|
|
|||
|
|
@ -115,12 +115,12 @@ class TestUnstructuredDictFormatterValidator(object):
|
|||
assert len(validator.dict) == 8
|
||||
assert all(isinstance(val, expected_formatter_class) for val in validator.dict.values())
|
||||
assert validator.dict_with_format_strings == {
|
||||
"key1": "{ %concat( %string( '''string with ''' ), %string( variable ) ) }",
|
||||
"key1": '{ %concat( %string( "string with " ), %string( variable ) ) }',
|
||||
"key2": "no variables",
|
||||
"key3": "{ %int(3) }",
|
||||
"key4": "{ %float(4.132) }",
|
||||
"key5": "{ %bool(True) }",
|
||||
"key6": "{ { %concat( %string( variable ), %string( '''_key''' ) ): '''value''', '''static_key''': %concat( %string( variable ), %string( '''_value''' ) ) } }",
|
||||
"key7": "{ [ '''list_1''', %concat( %string( '''list_''' ), %string( variable_2 ) ) ] }",
|
||||
"key8": "{ %concat( %string( '''string ''' ), %string( variable1 ), %string( ''' with multiple ''' ), %string( variable2 ) ) }",
|
||||
"key6": '{ { %concat( %string( variable ), %string( "_key" ) ): "value", "static_key": %concat( %string( variable ), %string( "_value" ) ) } }',
|
||||
"key7": '{ [ "list_1", %concat( %string( "list_" ), %string( variable_2 ) ) ] }',
|
||||
"key8": '{ %concat( %string( "string " ), %string( variable1 ), %string( " with multiple " ), %string( variable2 ) ) }',
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue