Merge pull request #3324 from pre-commit/migrate-config-purelib

fix migrate-config for purelib yaml
This commit is contained in:
Anthony Sottile 2024-10-08 12:01:05 -04:00 committed by GitHub
commit 772d7d45d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -47,7 +47,8 @@ def _migrate_map(contents: str) -> str:
def _preserve_style(n: ScalarNode, *, s: str) -> str:
return f'{n.style}{s}{n.style}'
style = n.style or ''
return f'{style}{s}{style}'
def _fix_stage(n: ScalarNode) -> str:

View file

@ -1,10 +1,26 @@
from __future__ import annotations
from unittest import mock
import pytest
import yaml
import pre_commit.constants as C
from pre_commit.clientlib import InvalidConfigError
from pre_commit.commands.migrate_config import migrate_config
from pre_commit.yaml import yaml_compose
@pytest.fixture(autouse=True, params=['c', 'pure'])
def switch_pyyaml_impl(request):
if request.param == 'c':
yield
else:
with mock.patch.dict(
yaml_compose.keywords,
{'Loader': yaml.SafeLoader},
):
yield
def test_migrate_config_normal_format(tmpdir, capsys):