From 1239a86abc67c85c62cd4c02eb45c973d61b40e9 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Wed, 17 Apr 2019 20:36:20 +0800 Subject: [PATCH] fix: replace $$ notation with $ and consider it as normal char. --- httprunner/parser.py | 4 +++- tests/test_parser.py | 27 +++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/httprunner/parser.py b/httprunner/parser.py index 7485127d..8faf1b5e 100644 --- a/httprunner/parser.py +++ b/httprunner/parser.py @@ -596,7 +596,9 @@ def prepare_lazy_data(content, functions_mapping=None, check_variables_set=None, # content is in string format here if not is_var_or_func_exist(content): # content is neither variable nor function - return content + # replace $$ notation with $ and consider it as normal char. + # e.g. abc => abc, abc$$def => abc$def, abc$$$$def$$h => abc$$def$h + return content.replace("$$", "$") functions_mapping = functions_mapping or {} check_variables_set = check_variables_set or set() diff --git a/tests/test_parser.py b/tests/test_parser.py index 3dfb7847..6ad569ce 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -730,8 +730,8 @@ class TestParserBasic(unittest.TestCase): } prepared_variables = parser.prepare_lazy_data(variables, functions, variables.keys()) parsed_testcase = parser.parse_variables_mapping(prepared_variables) - self.assertEqual(parsed_testcase["varB"], "456$$0") - self.assertEqual(parsed_testcase["varA"], "123456$$0") + self.assertEqual(parsed_testcase["varA"], "123456$0") + self.assertEqual(parsed_testcase["varB"], "456$0") self.assertEqual(parsed_testcase["varC"], 3) def test_prepare_lazy_data(self): @@ -770,6 +770,29 @@ class TestParserBasic(unittest.TestCase): variables.keys() ) + def test_prepare_lazy_data_dual_dollar(self): + variables = { + "num0": 123, + "var1": "abc$$num0", + "var2": "abc$$$num0", + "var3": "abc$$$$num0", + } + functions = { + "sum_two": sum_two + } + prepared_variables = parser.prepare_lazy_data( + variables, + functions, + variables.keys() + ) + self.assertEqual(prepared_variables["var1"], "abc$num0") + self.assertIsInstance(prepared_variables["var2"], parser.LazyString) + self.assertEqual(prepared_variables["var3"], "abc$$num0") + + parsed_variables = parser.parse_variables_mapping(prepared_variables) + self.assertEqual(parsed_variables["var1"], "abc$num0") + self.assertEqual(parsed_variables["var2"], "abc$123") + self.assertEqual(parsed_variables["var3"], "abc$$num0") class TestParser(unittest.TestCase):