1
- '''
1
+ """
2
2
A set of unit tests for the Bad Commit Message Blocker.
3
3
4
4
The most interesting (and prone to fail) part is the imperative mood rule.
5
5
This is why most tests are focused a round it. If you want to introduce
6
6
improvements/changes to the script, make sure that there are no regressions
7
7
and your newly introduced change is also covered by unit tests.
8
- '''
8
+ """
9
+
9
10
import unittest
10
11
import bad_commit_message_blocker as blocker
11
12
@@ -16,64 +17,83 @@ def setUp(self):
16
17
pass
17
18
18
19
def test_checkSubjectUsesImperative_WhenImperative_WillReturnTrue (self ):
19
- test_input = ["Refactor subsystem X for readability" ,
20
- "Update getting started documentation" ,
21
- "Remove deprecated methods" ,
22
- "Release version 1.0.0" ,
23
- "Add cool method to class" ]
20
+ test_input = [
21
+ "Refactor subsystem X for readability" ,
22
+ "Update getting started documentation" ,
23
+ "Remove deprecated methods" ,
24
+ "Release version 1.0.0" ,
25
+ "Add cool method to class" ,
26
+ ]
24
27
for input in test_input :
25
- self .assertTrue (blocker .check_subject_uses_imperative (
26
- input ), "\" " + input + "\" did not produce the expected result" )
28
+ self .assertTrue (
29
+ blocker .check_subject_uses_imperative (input ),
30
+ '"' + input + '" did not produce the expected result' ,
31
+ )
27
32
28
33
def test_checkSubjectUsesImperative_WhenThirdPerson_WillReturnFalse (self ):
29
- test_input = ["Refactors subsystem X for readability" ,
30
- "Updates getting started documentation" ,
31
- "Removes deprecated methods" ,
32
- "Releases version 1.0.0" ,
33
- "Adds cool method to class" ]
34
+ test_input = [
35
+ "Refactors subsystem X for readability" ,
36
+ "Updates getting started documentation" ,
37
+ "Removes deprecated methods" ,
38
+ "Releases version 1.0.0" ,
39
+ "Adds cool method to class" ,
40
+ ]
34
41
for input in test_input :
35
- self .assertFalse (blocker .check_subject_uses_imperative (
36
- input ), "\" " + input + "\" did not produce the expected result" )
42
+ self .assertFalse (
43
+ blocker .check_subject_uses_imperative (input ),
44
+ '"' + input + '" did not produce the expected result' ,
45
+ )
37
46
38
47
def test_checkSubjectUsesImperative_WhenPresentContinuous_WillReturnFalse (self ):
39
- test_input = ["Refactoring subsystem X for readability" ,
40
- "Updating getting started documentation" ,
41
- "Removing deprecated methods" ,
42
- "Releasing version 1.0.0" ,
43
- "Adding cool method to class" ]
48
+ test_input = [
49
+ "Refactoring subsystem X for readability" ,
50
+ "Updating getting started documentation" ,
51
+ "Removing deprecated methods" ,
52
+ "Releasing version 1.0.0" ,
53
+ "Adding cool method to class" ,
54
+ ]
44
55
for input in test_input :
45
- self .assertFalse (blocker .check_subject_uses_imperative (
46
- input ), "\" " + input + "\" did not produce the expected result" )
56
+ self .assertFalse (
57
+ blocker .check_subject_uses_imperative (input ),
58
+ '"' + input + '" did not produce the expected result' ,
59
+ )
47
60
48
61
def test_checkSubjectUsesImperative_WhenSimplePast_WillReturnFalse (self ):
49
- test_input = ["Refactored subsystem X for readability" ,
50
- "Updated getting started documentation" ,
51
- "Removed deprecated methods" ,
52
- "Released version 1.0.0" ,
53
- "Added cool method to class" ]
62
+ test_input = [
63
+ "Refactored subsystem X for readability" ,
64
+ "Updated getting started documentation" ,
65
+ "Removed deprecated methods" ,
66
+ "Released version 1.0.0" ,
67
+ "Added cool method to class" ,
68
+ ]
54
69
for input in test_input :
55
- self .assertFalse (blocker .check_subject_uses_imperative (
56
- input ), "\" " + input + "\" did not produce the expected result" )
70
+ self .assertFalse (
71
+ blocker .check_subject_uses_imperative (input ),
72
+ '"' + input + '" did not produce the expected result' ,
73
+ )
57
74
58
75
def test_checkSubjectUsesImperative_WhenRandom_WillReturnFalse (self ):
59
- test_input = ["Documentation is updated" ,
60
- "Addition of new class" ]
76
+ test_input = ["Documentation is updated" , "Addition of new class" ]
61
77
for input in test_input :
62
- self .assertFalse (blocker .check_subject_uses_imperative (
63
- input ), "\" " + input + "\" did not produce the expected result" )
64
-
65
- def test_checkSubjectSeparateFromBody_WhenLineBetweenBodyAndSubject_WillReturnTrue (self ):
78
+ self .assertFalse (
79
+ blocker .check_subject_uses_imperative (input ),
80
+ '"' + input + '" did not produce the expected result' ,
81
+ )
82
+
83
+ def test_checkSubjectSeparateFromBody_WhenLineBetweenBodyAndSubject_WillReturnTrue (
84
+ self ,
85
+ ):
66
86
test_input = """Add this cool feature
67
87
68
88
This cool feature is implemented because X and Y."""
69
- self .assertTrue (
70
- blocker .check_subject_is_separated_from_body (test_input ))
89
+ self .assertTrue (blocker .check_subject_is_separated_from_body (test_input ))
71
90
72
- def test_checkSubjectSeparateFromBody_WhenNoLineBetweenBodyAndSubject_WillReturnFalse (self ):
91
+ def test_checkSubjectSeparateFromBody_WhenNoLineBetweenBodyAndSubject_WillReturnFalse (
92
+ self ,
93
+ ):
73
94
test_input = """Add this cool feature
74
95
This cool feature is implemented because X and Y."""
75
- self .assertFalse (
76
- blocker .check_subject_is_separated_from_body (test_input ))
96
+ self .assertFalse (blocker .check_subject_is_separated_from_body (test_input ))
77
97
78
98
def test_checkSubjectNotTooLong_WhenSubjectTooLong_WillReturnFalse (self ):
79
99
test_input = "This is a very very very, really long, humongous subject for a commit message"
@@ -83,38 +103,40 @@ def test_checkSubjectTooLong_WhenSubjectNotTooLong_WillReturnTrue(self):
83
103
test_input = "Add this neat commit message"
84
104
self .assertTrue (blocker .check_subject_is_not_too_long (test_input , 60 ))
85
105
86
- def test_checkSubjectIsCapitalized_WhenSubjectBeginsWithCapital_WillReturnTrue (self ):
106
+ def test_checkSubjectIsCapitalized_WhenSubjectBeginsWithCapital_WillReturnTrue (
107
+ self ,
108
+ ):
87
109
test_input = "Add this cool new feature"
88
110
self .assertTrue (blocker .check_subject_is_capitalized (test_input ))
89
111
90
112
def test_checkSubjectIsCapitalized_WhenSubjectBeginsWithLower_WillReturnFalse (self ):
91
113
test_input = "add this weird-looking commit message"
92
114
self .assertFalse (blocker .check_subject_is_capitalized (test_input ))
93
115
94
- def test_checkSubjectDoesNotEndWithPeriod_WhenSubjectEndsWithPeriod_WillReturnFalse (self ):
116
+ def test_checkSubjectDoesNotEndWithPeriod_WhenSubjectEndsWithPeriod_WillReturnFalse (
117
+ self ,
118
+ ):
95
119
test_input = "I am a strange person and do such things."
96
- self .assertFalse (
97
- blocker .check_subject_does_not_end_with_period (test_input ))
120
+ self .assertFalse (blocker .check_subject_does_not_end_with_period (test_input ))
98
121
99
- def test_checkSubjectDoesNotEndWithPeriod_WhenSubjectEndsWithoutPeriod_WillReturnTrue (self ):
122
+ def test_checkSubjectDoesNotEndWithPeriod_WhenSubjectEndsWithoutPeriod_WillReturnTrue (
123
+ self ,
124
+ ):
100
125
test_input = "I am a strange person and don't end commit messages with a period"
101
- self .assertTrue (
102
- blocker .check_subject_does_not_end_with_period (test_input ))
126
+ self .assertTrue (blocker .check_subject_does_not_end_with_period (test_input ))
103
127
104
128
def test_checkBodyLinesAreNotTooLong_WhenLinesTooLong_WillReturnFalse (self ):
105
129
test_input = """Add this cool new feature
106
130
107
131
But damn...
108
132
I feel like adding some pretty huge lines and forget to insert \\ n's. This is just sad!"""
109
- self .assertFalse (
110
- blocker .check_body_lines_are_not_too_long (test_input , 72 ))
133
+ self .assertFalse (blocker .check_body_lines_are_not_too_long (test_input , 72 ))
111
134
112
135
def test_checkBodyLinesAreNotTooLong_WhenLinesNotTooLong_WillReturnTrue (self ):
113
136
test_input = """Add this cool new feature
114
137
115
138
And nicely explain why it was added."""
116
- self .assertTrue (
117
- blocker .check_body_lines_are_not_too_long (test_input , 72 ))
139
+ self .assertTrue (blocker .check_body_lines_are_not_too_long (test_input , 72 ))
118
140
119
141
def test_checkBodyExplainsWhatAndWhy_WhenCalled_WillReturnTrue (self ):
120
142
# We cannot currently check this, so we always return true
@@ -123,5 +145,5 @@ def test_checkBodyExplainsWhatAndWhy_WhenCalled_WillReturnTrue(self):
123
145
self .assertTrue (blocker .check_body_explains_what_and_why (test_input ))
124
146
125
147
126
- if __name__ == ' __main__' :
148
+ if __name__ == " __main__" :
127
149
unittest .main ()
0 commit comments