1
- import os
2
1
import sys
3
2
from pathlib import Path
4
3
from textwrap import dedent
@@ -29,20 +28,19 @@ def test_create_tag(test_input, expected):
29
28
30
29
31
30
@pytest .mark .parametrize ("retry" , (True , False ))
32
- def test_bump_pre_commit_changelog (
33
- tmp_commitizen_project , mocker : MockFixture , freezer , retry
34
- ):
31
+ @pytest .mark .usefixtures ("tmp_commitizen_project" )
32
+ def test_bump_pre_commit_changelog (mocker : MockFixture , freezer , retry ):
35
33
freezer .move_to ("2022-04-01" )
36
34
testargs = ["cz" , "bump" , "--changelog" , "--yes" ]
37
35
if retry :
38
36
testargs .append ("--retry" )
39
37
else :
40
38
pytest .xfail ("it will fail because pre-commit will reformat CHANGELOG.md" )
41
39
mocker .patch .object (sys , "argv" , testargs )
42
- with tmp_commitizen_project . as_cwd ():
43
- # Configure prettier as a pre-commit hook
44
- Path ( ".pre-commit-config.yaml" ). write_text (
45
- """
40
+ # Configure prettier as a pre-commit hook
41
+ Path ( ". pre-commit-config.yaml" ). write_text (
42
+ dedent (
43
+ """\
46
44
repos:
47
45
- repo: https://github.com/pre-commit/mirrors-prettier
48
46
rev: v2.6.2
@@ -51,44 +49,43 @@ def test_bump_pre_commit_changelog(
51
49
stages: [commit]
52
50
"""
53
51
)
54
- # Prettier inherits editorconfig
55
- Path (".editorconfig" ).write_text (
56
- """
52
+ )
53
+ # Prettier inherits editorconfig
54
+ Path (".editorconfig" ).write_text (
55
+ dedent (
56
+ """\
57
57
[*]
58
58
indent_size = 4
59
59
"""
60
60
)
61
- cmd .run ("git add -A" )
62
- if os .name == "nt" :
63
- cmd .run ('git commit -m "fix: _test"' )
64
- else :
65
- cmd .run ("git commit -m 'fix: _test'" )
66
- cmd .run ("pre-commit install" )
67
- cli .main ()
68
- # Pre-commit fixed last line adding extra indent and "\" char
69
- assert Path ("CHANGELOG.md" ).read_text () == dedent (
70
- """\
71
- ## 0.1.1 (2022-04-01)
61
+ )
62
+ cmd .run ("git add -A" )
63
+ cmd .run ('git commit -m "fix: _test"' )
64
+ cmd .run ("pre-commit install" )
65
+ cli .main ()
66
+ # Pre-commit fixed last line adding extra indent and "\" char
67
+ assert Path ("CHANGELOG.md" ).read_text () == dedent (
68
+ """\
69
+ ## 0.1.1 (2022-04-01)
72
70
73
- ### Fix
71
+ ### Fix
74
72
75
- - \\ _test
76
- """
77
- )
73
+ - \\ _test
74
+ """
75
+ )
78
76
79
77
80
78
@pytest .mark .parametrize ("retry" , (True , False ))
81
- def test_bump_pre_commit_changelog_fails_always (
82
- tmp_commitizen_project , mocker : MockFixture , freezer , retry
83
- ):
79
+ @pytest .mark .usefixtures ("tmp_commitizen_project" )
80
+ def test_bump_pre_commit_changelog_fails_always (mocker : MockFixture , freezer , retry ):
84
81
freezer .move_to ("2022-04-01" )
85
82
testargs = ["cz" , "bump" , "--changelog" , "--yes" ]
86
83
if retry :
87
84
testargs .append ("--retry" )
88
85
mocker .patch .object (sys , "argv" , testargs )
89
- with tmp_commitizen_project . as_cwd ():
90
- Path ( ".pre-commit-config.yaml" ). write_text (
91
- """
86
+ Path ( ".pre-commit-config.yaml" ). write_text (
87
+ dedent (
88
+ """\
92
89
repos:
93
90
- repo: local
94
91
hooks:
@@ -99,11 +96,9 @@ def test_bump_pre_commit_changelog_fails_always(
99
96
files: CHANGELOG.md
100
97
"""
101
98
)
102
- cmd .run ("git add -A" )
103
- if os .name == "nt" :
104
- cmd .run ('git commit -m "feat: forbid changelogs"' )
105
- else :
106
- cmd .run ("git commit -m 'feat: forbid changelogs'" )
107
- cmd .run ("pre-commit install" )
108
- with pytest .raises (exceptions .BumpCommitFailedError ):
109
- cli .main ()
99
+ )
100
+ cmd .run ("git add -A" )
101
+ cmd .run ('git commit -m "feat: forbid changelogs"' )
102
+ cmd .run ("pre-commit install" )
103
+ with pytest .raises (exceptions .BumpCommitFailedError ):
104
+ cli .main ()
0 commit comments