From 9f1080816d6fd165ea870b5d1b446e67a38dc248 Mon Sep 17 00:00:00 2001 From: Boryana Goncharenko <3010723+boryanagoncharenko@users.noreply.github.com> Date: Fri, 7 Jun 2024 15:01:58 +0300 Subject: [PATCH] Fix broken color command #5597 --- hedy.py | 4 +++- tests/test_level/test_level_04.py | 8 ++++---- tests/test_level/test_level_15.py | 6 +++--- tests/test_level/test_level_17.py | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/hedy.py b/hedy.py index 080898a7c7c..92f35aed00c 100644 --- a/hedy.py +++ b/hedy.py @@ -2039,7 +2039,9 @@ def process_variable_for_fstring(self, name): if self.is_quoted(name): name = name[1:-1] return name.replace("'", "\\'") - name = name if self.is_bool(name) else escape_var(name.replace("'", "\\'")) + if not ConvertToPython.is_int(name) and not ConvertToPython.is_float(name): + name = name if self.is_bool(name) else escape_var(name.replace("'", "\\'")) + name = '"' + name + '"' return f'{{convert_numerals("{self.numerals_language}", {name})}}' def var_access(self, meta, args): diff --git a/tests/test_level/test_level_04.py b/tests/test_level/test_level_04.py index d1cfa9c98d0..6acbd9c81e9 100644 --- a/tests/test_level/test_level_04.py +++ b/tests/test_level/test_level_04.py @@ -1044,7 +1044,7 @@ def test_undefined_list_access(self): @parameterized.expand(hedy.english_colors) def test_all_colors(self, color): code = f'color {color}' - expected = HedyTester.turtle_color_command_transpiled(f'{{convert_numerals("Latin", {color})}}') + expected = HedyTester.turtle_color_command_transpiled(f'{{convert_numerals("Latin", "{color}")}}') self.multi_level_tester( code=code, @@ -1054,7 +1054,7 @@ def test_all_colors(self, color): def test_color_red(self): code = "color red" - expected = HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", red)}') + expected = HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", "red")}') self.multi_level_tester( code=code, @@ -1066,7 +1066,7 @@ def test_color_red(self): def test_color_translated(self): lang = 'nl' code = "kleur blauw" - expected = HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", blue)}', lang) + expected = HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", "blue")}', lang) self.multi_level_tester( code=code, @@ -1082,7 +1082,7 @@ def test_color_basic(self): forward 10""") expected = HedyTester.dedent( - HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", red)}', 'en'), + HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", "red")}', 'en'), HedyTester.forward_transpiled('10', self.level)) self.multi_level_tester( diff --git a/tests/test_level/test_level_15.py b/tests/test_level/test_level_15.py index 4b443398a3e..b9e984c400e 100644 --- a/tests/test_level/test_level_15.py +++ b/tests/test_level/test_level_15.py @@ -36,9 +36,9 @@ def test_assign_list_var_boolean(self): ) @parameterized.expand(HedyTester.booleans) - def test_print_boolean(self, value, expected): + def test_print_boolean(self, value, exp): code = f"print 'variable is ' {value}" - expected = f"print(f'''variable is {{convert_numerals(\"Latin\", {expected})}}''')" + expected = f"print(f'''variable is {{convert_numerals(\"Latin\", \"{exp}\")}}''')" self.multi_level_tester( code=code, @@ -50,7 +50,7 @@ def test_print_boolean(self, value, expected): @parameterized.expand([('вярно', True), ('Вярно', True), ('невярно', False), ('Невярно', False)]) def test_print_boolean_bulgarian(self, value, exp): code = f"принтирай 'Това е ' {value}" - expected = f"print(f'''Това е {{convert_numerals(\"Latin\", {exp})}}''')" + expected = f"print(f'''Това е {{convert_numerals(\"Latin\", \"{exp}\")}}''')" self.multi_level_tester( code=code, diff --git a/tests/test_level/test_level_17.py b/tests/test_level/test_level_17.py index ec71bccb178..fd0be7c40e0 100644 --- a/tests/test_level/test_level_17.py +++ b/tests/test_level/test_level_17.py @@ -548,7 +548,7 @@ def test_if_pressed_with_turtlecolor(self): if_pressed_mapping = {{"else": "if_pressed_default_else"}} if_pressed_mapping['x'] = 'if_pressed_x_' def if_pressed_x_(): - __trtl = f'{{convert_numerals("Latin", red)}}' + __trtl = f'{{convert_numerals("Latin", "red")}}' color_dict = {color_dict} if __trtl not in ['black', 'blue', 'brown', 'gray', 'green', 'orange', 'pink', 'purple', 'red', 'white', 'yellow']: raise Exception(f{self.value_exception_transpiled()})