From 2eabb3ee6220dca2898b78e91b6633fe6219ef12 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Sat, 3 Jan 2026 21:09:22 -0800 Subject: [PATCH] fix tests --- src/ytdl_sub/utils/script.py | 25 +++++++++++-------- .../test_string_formatter_validator.py | 8 +++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/ytdl_sub/utils/script.py b/src/ytdl_sub/utils/script.py index 753916f4..8a1fc1b1 100644 --- a/src/ytdl_sub/utils/script.py +++ b/src/ytdl_sub/utils/script.py @@ -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}" diff --git a/tests/unit/validators/test_string_formatter_validator.py b/tests/unit/validators/test_string_formatter_validator.py index 4b2baef6..9bb4d1e0 100644 --- a/tests/unit/validators/test_string_formatter_validator.py +++ b/tests/unit/validators/test_string_formatter_validator.py @@ -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 ) ) }', }