Skip to content

test suite fails partially with ruyaml >= 0.92.0 #301

@tijuca

Description

@tijuca

Description

While working on packaging yamlfix 1.18.0 within Debian the internal testsuite is failing, but was successful with version 1.17.0.

Steps to reproduce

Run the test with the current version of ruyaml 0.92.1 installed.

Current behavior

============================= test session starts ==============================
platform linux -- Python 3.13.7, pytest-8.4.2, pluggy-1.6.0
rootdir: /build/python-yamlfix-1.18.0/.pybuild/cpython3_3.13_yamlfix/build
configfile: pyproject.toml
plugins: xdist-3.8.0, cov-5.0.0
created: 12/12 workers
12 workers [152 items]

..........................................F...............F............. [ 47%]
......................................................................F. [ 94%]
F.F.....                                                                 [100%]
=================================== FAILURES ===================================
_________________ TestYamlAdapter.test_if_line_length_expands __________________
[gw8] linux -- Python 3.13.7 /usr/bin/python3.13

self = <tests.unit.test_adapter_yaml.TestYamlAdapter object at 0x7f3bb9ee3890>

    def test_if_line_length_expands(self) -> None:
        """Test if configurable line-length expands string value."""
        source = dedent(
            """\
            key: value value value value value value
              value value value value value value
              value value value value value value
              value value value value value value
              value value value value value value
              value value value value value value
            """
        )
        fixed_source = dedent(
            """\
            ---
            key: value value value value value value value value value value value value value value value value value
              value value value value value value value value value value value value value value value value value
              value value
            """  # noqa: E501
        )
        config = YamlfixConfig()
        config.line_length = 100
    
        result = fix_code(source, config)
    
>       assert result == fixed_source
E       AssertionError: assert '---\nkey: va...value value\n' == '---\nkey: va...value value\n'
E         
E         Skipping 94 identical leading characters in diff, use -v to show
E         - alue value value
E         ?     ------
E         + alue value
E         -   value value value value value value value value value value value value value value value value value
E         ?                                                                                                   -----...
E         
E         ...Full output truncated (3 lines hidden), use '-vv' to show

tests/unit/test_adapter_yaml.py:146: AssertionError
________________ TestYamlAdapter.test_if_line_length_contracts _________________
[gw8] linux -- Python 3.13.7 /usr/bin/python3.13

self = <tests.unit.test_adapter_yaml.TestYamlAdapter object at 0x7f3bb9ff5f20>

    def test_if_line_length_contracts(self) -> None:
        """Test if configurable line-length contracts string value."""
        source = dedent(
            """\
            key: value value value value value value
              value value value value value value
              value value value value value value
              value value value value value value
              value value value value value value
              value value value value value value
            """
        )
        fixed_source = dedent(
            """\
            ---
            key: value value value
              value value value value
              value value value value
              value value value value
              value value value value
              value value value value
              value value value value
              value value value value
              value value value value
              value
            """
        )
        config = YamlfixConfig()
        config.line_length = 20
    
        result = fix_code(source, config)
    
>       assert result == fixed_source
E       AssertionError: assert '---\nkey: va...e \n  value\n' == '---\nkey: va...ue\n  value\n'
E         
E           ---
E         - key: value value value
E         ?                  -----
E         + key: value value 
E         -   value value value value
E         ?                     -----...
E         
E         ...Full output truncated (26 lines hidden), use '-vv' to show

tests/unit/test_adapter_yaml.py:180: AssertionError
______ TestFixCode.test_fix_code_respects_jinja_variables_with_operations ______
[gw8] linux -- Python 3.13.7 /usr/bin/python3.13

self = <tests.unit.test_services.TestFixCode object at 0x7f3bb9d12bc0>

    def test_fix_code_respects_jinja_variables_with_operations(
        self,
    ) -> None:
        """
        Given: Code with a long string that contains a jinja variable with operations
        When: fix_code is run
        Then: The jinja string is not broken
        """
        source = (
            "---\n"
            "project: This is a long long long long line that should not be split on "
            "the jinja {{ variable that contains different words }}"
        )
        desired_source = (
            "---\n"
            "project: This is a long long long long line that should not be split on "
            "the jinja\n"
            "  {{ variable that contains different words }}\n"
        )
    
        result = fix_code(source)
    
>       assert result == desired_source
E       AssertionError: assert '---\nproject...nt words }}\n' == '---\nproject...nt words }}\n'
E         
E         Skipping 70 identical leading characters in diff, use -v to show
E         - it on the jinja
E         ?           -----
E         + it on the 
E         -   {{ variable that contains different words }}
E         +   jinja {{ variable that contains different words }}
E         ?  ++++++

tests/unit/test_services.py:687: AssertionError
________ TestFixCode.test_anchors_and_aliases_with_duplicate_merge_keys ________
[gw1] linux -- Python 3.13.7 /usr/bin/python3.13

self = <tests.unit.test_services.TestFixCode object at 0x7f1481a16a80>

    def test_anchors_and_aliases_with_duplicate_merge_keys(self) -> None:
        """All anchors and aliases should be preserved even with multiple merge keys
        and merge keys should be formatted as a list in a single line.
        """
        source = dedent(
            """\
            ---
            x-node-volumes: &node-volumes
              node3_data:
            x-vault-volumes: &vault-volumes
              vault_data:
            x-mongo-volumes: &mongo-volumes
              mongo_data:
            x-certmgr-volumes: &certmgr-volumes
              cert_data:
            volumes:
              <<: *node-volumes
              <<: *vault-volumes
              <<: *mongo-volumes
              <<: *certmgr-volumes
            """
        )
        desired_source = dedent(
            """\
            ---
            x-node-volumes: &node-volumes
              node3_data:
            x-vault-volumes: &vault-volumes
              vault_data:
            x-mongo-volumes: &mongo-volumes
              mongo_data:
            x-certmgr-volumes: &certmgr-volumes
              cert_data:
            volumes:
              <<:
                - *node-volumes
                - *vault-volumes
                - *mongo-volumes
                - *certmgr-volumes
            """
        )
        config = YamlfixConfig()
        config.allow_duplicate_keys = True
    
        result = fix_code(source, config)
    
>       assert result == desired_source
E       AssertionError: assert '---\nx-node-...ode-volumes\n' == '---\nx-node-...mgr-volumes\n'
E         
E         Skipping 54 identical leading characters in diff, use -v to show
E         - t-volumes: &vault-volumes
E         + t-volumes:
E             vault_data:
E         - x-mongo-volumes: &mongo-volumes
E         + x-mongo-volumes:...
E         
E         ...Full output truncated (13 lines hidden), use '-vv' to show

tests/unit/test_services.py:576: AssertionError
___________ TestFixCode.test_fix_code_respects_many_jinja_variables ____________
[gw4] linux -- Python 3.13.7 /usr/bin/python3.13

self = <tests.unit.test_services.TestFixCode object at 0x7f09f571ab70>

    def test_fix_code_respects_many_jinja_variables(
        self,
    ) -> None:
        """
        Given: Code with a long string that contains two jinja variables
        When: fix_code is run
        Then: The jinja string is not broken
        """
        source = (
            "---\n"
            "project: This is a long long {{ variable_1 }} line that should not be "
            "split on the jinja {{ variable_2 }}"
        )
        desired_source = (
            "---\n"
            "project: This is a long long {{ variable_1 }} line that should not be "
            "split on the\n"
            "  jinja {{ variable_2 }}\n"
        )
    
        result = fix_code(source)
    
>       assert result == desired_source
E       AssertionError: assert '---\nproject...riable_2 }}\n' == '---\nproject...riable_2 }}\n'
E         
E         Skipping 73 identical leading characters in diff, use -v to show
E         -  split on the
E         ?           ---
E         +  split on 
E         -   jinja {{ variable_2 }}
E         +   the jinja {{ variable_2 }}
E         ?  ++++

tests/unit/test_services.py:663: AssertionError
=========================== short test summary info ============================
FAILED tests/unit/test_adapter_yaml.py::TestYamlAdapter::test_if_line_length_expands
FAILED tests/unit/test_adapter_yaml.py::TestYamlAdapter::test_if_line_length_contracts
FAILED tests/unit/test_services.py::TestFixCode::test_fix_code_respects_jinja_variables_with_operations
FAILED tests/unit/test_services.py::TestFixCode::test_anchors_and_aliases_with_duplicate_merge_keys
FAILED tests/unit/test_services.py::TestFixCode::test_fix_code_respects_many_jinja_variables
======================== 5 failed, 147 passed in 10.13s ========================```

My guess is that ruyaml internally has changed and is provoking this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions