Skip to content

Commit

Permalink
Merge pull request #3324 from pre-commit/migrate-config-purelib
Browse files Browse the repository at this point in the history
fix migrate-config for purelib yaml
  • Loading branch information
asottile authored Oct 8, 2024
2 parents 3d5548b + 222c62b commit 772d7d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pre_commit/commands/migrate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions tests/commands/migrate_config_test.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit 772d7d4

Please sign in to comment.