@@ -628,9 +628,6 @@ def test_jinja_spacing_vars() -> None:
628628 ),
629629 pytest .param ("{{foo(123)}}" , "{{ foo(123) }}" , "spacing" , id = "11" ),
630630 pytest .param ("{{ foo(a.b.c) }}" , "{{ foo(a.b.c) }}" , "spacing" , id = "12" ),
631- # pytest.param(
632- # "spacing",
633- # ),
634631 pytest .param (
635632 "{{foo(x =['server_options'])}}" ,
636633 "{{ foo(x=['server_options']) }}" ,
@@ -912,12 +909,11 @@ def test_jinja_transform(
912909
913910 orig_content = playbook .read_text (encoding = "utf-8" )
914911 expected_content = playbook .with_suffix (
915- f".transformed{ playbook .suffix } " ,
912+ f".transformed{ playbook .suffix } "
916913 ).read_text (encoding = "utf-8" )
917914 transformed_content = playbook .with_suffix (f".tmp{ playbook .suffix } " ).read_text (
918- encoding = "utf-8" ,
915+ encoding = "utf-8"
919916 )
920-
921917 assert orig_content != transformed_content
922918 assert expected_content == transformed_content
923919 playbook .with_suffix (f".tmp{ playbook .suffix } " ).unlink ()
@@ -964,35 +960,24 @@ def test_filter_import_failure(
964960 results = Runner (lintable , rules = collection ).run ()
965961 assert len (results ) == expected_results
966962
967- def test_ansible_core_2_19_supported_version () -> None :
968- """Test that ansible-core 2.19 is in the supported versions list."""
969- from ansiblelint .config import Options
970-
971- options = Options ()
972- supported_versions = options .supported_ansible
963+ def test_jinja_template_generates_ansible_tagged_str_error () -> None :
964+ """Test that demonstrates ansible-core generating _AnsibleTaggedStr errors and us ignoring them."""
965+ # Test the ignore pattern directly without full RulesCollection setup
966+ from ansiblelint .rules .jinja import ignored_re
973967
974- # Check that 2.19 is in the supported versions
975- assert any ("2.19" in version for version in supported_versions ), (
976- f"ansible-core 2.19 not found in supported versions: { supported_versions } "
968+ # Test _AnsibleTaggedStr error is ignored
969+ tagged_error_msg = 'can only concatenate list (not "_AnsibleTaggedStr") to list'
970+ assert ignored_re .search (tagged_error_msg ), (
971+ f"_AnsibleTaggedStr error should be ignored: { tagged_error_msg } "
977972 )
978973
979- @pytest .mark .parametrize (
980- ("error_message" , "should_be_ignored" ),
981- (
982- ('can only concatenate list (not "_AnsibleTaggedStr") to list' , True ),
983- ('can only concatenate str (not "_AnsibleTaggedStr") to str' , True ),
984- ("Unexpected templating type error occurred on (var): details" , True ),
985- ("Object of type method is not JSON serializable" , True ),
986- ('can only concatenate list (not "int") to list' , False ),
987- ("TemplateSyntaxError: unexpected token" , False ),
988- ("UndefinedError: variable not defined" , False ),
989- ("can only concatenate list (not AnsibleTaggedStr) to list" , False ),
990- ),
991- )
992- def test_jinja_ignore_patterns (error_message : str , should_be_ignored : bool ) -> None :
993- """Test that ignore patterns correctly handle ansible-core 2.19 _AnsibleTaggedStr errors."""
994- matches = bool (ignored_re .search (error_message ))
995- assert matches == should_be_ignored , (
996- f"Error message '{ error_message } ' should { 'be ignored' if should_be_ignored else 'not be ignored' } "
997- f"but { 'was' if matches else 'was not' } matched by ignore pattern"
974+ # Test similar error without _AnsibleTaggedStr is NOT ignored
975+ normal_error_msg = 'can only concatenate list (not "int") to list'
976+ assert not ignored_re .search (normal_error_msg ), (
977+ f"Normal error should not be ignored: { normal_error_msg } "
998978 )
979+
980+ # Test that the ignore pattern works for the specific error we're testing
981+ assert ignored_re .search (
982+ 'can only concatenate str (not "_AnsibleTaggedStr") to str'
983+ ), "String concatenation with _AnsibleTaggedStr should also be ignored"
0 commit comments