diff --git a/calculate/templates/template_engine.py b/calculate/templates/template_engine.py index 0a17d90..4939428 100644 --- a/calculate/templates/template_engine.py +++ b/calculate/templates/template_engine.py @@ -1093,8 +1093,8 @@ class CalculateExtension(Extension): check_template.render(__datavars__=self._datavars) elif (self._is_variable_name(self.stream.current) - or self.stream.current.type == 'lparen' - or self.stream.current.type == 'integer' + or self.stream.current.type in {'lparen', 'integer', + 'float', 'string'} or self.stream.current.value in self.CONDITION_NAME_TOKENS): # разбираем условие. Если условие False -- кидаем исключение. # condition_result = self.get_condition_result() diff --git a/tests/templates/test_template_engine.py b/tests/templates/test_template_engine.py index 2964cb6..5be0bc5 100644 --- a/tests/templates/test_template_engine.py +++ b/tests/templates/test_template_engine.py @@ -6,7 +6,9 @@ from calculate.templates.template_engine import TemplateEngine, Variables,\ from calculate.templates.template_processor import TemplateExecutor -CHROOT_PATH = os.path.join(os.getcwd(), 'tests/templates/testfiles/test_template_engine_root') +CHROOT_PATH = os.path.join( + os.getcwd(), + 'tests/templates/testfiles/test_template_engine_root') APPENDS_SET = TemplateExecutor(cl_config_path=os.path.join( CHROOT_PATH, @@ -263,7 +265,23 @@ parameter_2 = {{ vars_1.var_1 }}''' text = template_engine.template_text assert text == output_text - @pytest.mark.parametrize('case', + def test_constant_value_in_the_begin_of_condition(self): + datavars_module = Variables({'vars_1': + Variables({'var_1': + ['a', 4.2, 'b', 'c']})}) + input_template = '''{% calculate name = 'filename', +'a' in vars_1.var_1, 4.2 in vars_1.var_1 -%} +Template completed''' + output_text = 'Template completed' + template_engine = TemplateEngine(appends_set=APPENDS_SET, + datavars_module=datavars_module, + chroot_path=CHROOT_PATH) + template_engine.process_template_from_string(input_template, FILE) + text = template_engine.template_text + assert text == output_text + + @pytest.mark.parametrize( + 'case', [ { "name": "pattern not found", @@ -300,8 +318,8 @@ parameter_2 = {{ vars_1.var_1 }}''' "grep": "'/test_grep', '^STATUSLINE=true'", "result": "" }, - ], - ids=lambda x:x["name"]) + ], + ids=lambda x: x["name"]) def test_grep(self, case): datavars_module = Variables({'vars_1': Variables({'var_1': @@ -318,7 +336,8 @@ parameter_2 = {{ vars_1.var_1 }}''' text = template_engine.template_text assert text == output_text - @pytest.mark.parametrize('case', + @pytest.mark.parametrize( + 'case', [ { "name": "exists directory", @@ -345,8 +364,8 @@ parameter_2 = {{ vars_1.var_1 }}''' "exists": "/test_exists_qwerty", "result": "" }, - ], - ids=lambda x:x["name"]) + ], + ids=lambda x: x["name"]) def test_exists(self, case): datavars_module = Variables({'vars_1': Variables({'var_1':