|
1 | 1 | import os |
2 | | -from conventional_pre_commit.output import fail, fail_verbose, unicode_decode_error |
| 2 | +from conventional_pre_commit.output import Colors, fail, fail_verbose, unicode_decode_error |
| 3 | + |
| 4 | + |
| 5 | +def test_colors(): |
| 6 | + colors = Colors() |
| 7 | + |
| 8 | + assert colors.blue == colors.LBLUE |
| 9 | + assert colors.red == colors.LRED |
| 10 | + assert colors.restore == colors.RESTORE |
| 11 | + assert colors.yellow == colors.YELLOW |
| 12 | + |
| 13 | + colors = Colors(enabled=False) |
| 14 | + |
| 15 | + assert colors.blue == "" |
| 16 | + assert colors.red == "" |
| 17 | + assert colors.restore == "" |
| 18 | + assert colors.yellow == "" |
3 | 19 |
|
4 | 20 |
|
5 | 21 | def test_fail(): |
6 | 22 | output = fail("commit msg") |
7 | 23 |
|
| 24 | + assert Colors.LRED in output |
| 25 | + assert Colors.YELLOW in output |
| 26 | + assert Colors.LBLUE in output |
| 27 | + assert Colors.RESTORE in output |
| 28 | + |
8 | 29 | assert "Bad commit message" in output |
9 | 30 | assert "commit msg" in output |
10 | 31 | assert "Conventional Commits formatting" in output |
11 | 32 | assert "https://www.conventionalcommits.org/" in output |
12 | 33 |
|
13 | 34 |
|
| 35 | +def test_fail__no_color(): |
| 36 | + output = fail("commit msg", use_color=False) |
| 37 | + |
| 38 | + assert Colors.LRED not in output |
| 39 | + assert Colors.YELLOW not in output |
| 40 | + assert Colors.LBLUE not in output |
| 41 | + assert Colors.RESTORE not in output |
| 42 | + |
| 43 | + |
14 | 44 | def test_fail_verbose(): |
15 | 45 | output = fail_verbose("commit msg", optional_scope=False) |
16 | 46 |
|
| 47 | + assert Colors.YELLOW in output |
| 48 | + assert Colors.RESTORE in output |
| 49 | + |
| 50 | + output = output.replace(Colors.YELLOW, Colors.RESTORE).replace(Colors.RESTORE, "") |
| 51 | + |
17 | 52 | assert "Conventional Commit messages follow a pattern like" in output |
18 | 53 | assert f"type(scope): subject{os.linesep}{os.linesep} extended body" in output |
19 | | - assert "Expected value for 'type' but found none." in output |
20 | | - assert "Expected value for 'delim' but found none." in output |
21 | | - assert "Expected value for 'scope' but found none." in output |
22 | | - assert "Expected value for 'subject' but found none." in output |
| 54 | + assert "Expected value for type but found none." in output |
| 55 | + assert "Expected value for delim but found none." in output |
| 56 | + assert "Expected value for scope but found none." in output |
| 57 | + assert "Expected value for subject but found none." in output |
23 | 58 | assert "git commit --edit --file=.git/COMMIT_EDITMSG" in output |
24 | 59 | assert "edit the commit message and retry the commit" in output |
25 | 60 |
|
26 | 61 |
|
| 62 | +def test_fail_verbose__no_color(): |
| 63 | + output = fail_verbose("commit msg", use_color=False) |
| 64 | + |
| 65 | + assert Colors.LRED not in output |
| 66 | + assert Colors.YELLOW not in output |
| 67 | + assert Colors.LBLUE not in output |
| 68 | + assert Colors.RESTORE not in output |
| 69 | + |
| 70 | + |
27 | 71 | def test_fail_verbose__optional_scope(): |
28 | | - output = fail_verbose("commit msg", optional_scope=True) |
| 72 | + output = fail_verbose("commit msg", optional_scope=True, use_color=False) |
29 | 73 |
|
30 | | - assert "Expected value for 'scope' but found none." not in output |
| 74 | + assert "Expected value for scope but found none." not in output |
31 | 75 |
|
32 | 76 |
|
33 | 77 | def test_fail_verbose__missing_subject(): |
34 | | - output = fail_verbose("feat(scope):", optional_scope=False) |
| 78 | + output = fail_verbose("feat(scope):", optional_scope=False, use_color=False) |
35 | 79 |
|
36 | | - assert "Expected value for 'subject' but found none." in output |
37 | | - assert "Expected value for 'type' but found none." not in output |
38 | | - assert "Expected value for 'scope' but found none." not in output |
| 80 | + assert "Expected value for subject but found none." in output |
| 81 | + assert "Expected value for type but found none." not in output |
| 82 | + assert "Expected value for scope but found none." not in output |
39 | 83 |
|
40 | 84 |
|
41 | | -def test_fail_verbose_no_body_sep(): |
| 85 | +def test_fail_verbose__no_body_sep(): |
42 | 86 | output = fail_verbose( |
43 | 87 | """feat(scope): subject |
44 | 88 | body without blank line |
45 | 89 | """, |
46 | 90 | optional_scope=False, |
| 91 | + use_color=False, |
47 | 92 | ) |
48 | 93 |
|
49 | | - assert "Expected value for 'sep' but found none." in output |
50 | | - assert "Expected value for 'multi' but found none." not in output |
| 94 | + assert "Expected value for sep but found none." in output |
| 95 | + assert "Expected value for multi but found none." not in output |
51 | 96 |
|
52 | | - assert "Expected value for 'subject' but found none." not in output |
53 | | - assert "Expected value for 'type' but found none." not in output |
54 | | - assert "Expected value for 'scope' but found none." not in output |
| 97 | + assert "Expected value for subject but found none." not in output |
| 98 | + assert "Expected value for type but found none." not in output |
| 99 | + assert "Expected value for scope but found none." not in output |
55 | 100 |
|
56 | 101 |
|
57 | 102 | def test_unicode_decode_error(): |
58 | 103 | output = unicode_decode_error() |
59 | 104 |
|
| 105 | + assert Colors.LRED in output |
| 106 | + assert Colors.YELLOW in output |
| 107 | + assert Colors.LBLUE in output |
| 108 | + assert Colors.RESTORE in output |
| 109 | + |
60 | 110 | assert "Bad commit message encoding" in output |
61 | 111 | assert "UTF-8 encoding is assumed" in output |
62 | 112 | assert "https://git-scm.com/docs/git-commit/#_discussion" in output |
| 113 | + |
| 114 | + |
| 115 | +def test_unicode_decode_error__no_color(): |
| 116 | + output = unicode_decode_error(use_color=False) |
| 117 | + |
| 118 | + assert Colors.LRED not in output |
| 119 | + assert Colors.YELLOW not in output |
| 120 | + assert Colors.LBLUE not in output |
| 121 | + assert Colors.RESTORE not in output |
0 commit comments