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