1- '''
1+ """
22A set of unit tests for the Bad Commit Message Blocker.
33
44The most interesting (and prone to fail) part is the imperative mood rule.
55This is why most tests are focused a round it. If you want to introduce
66improvements/changes to the script, make sure that there are no regressions
77and your newly introduced change is also covered by unit tests.
8- '''
8+ """
9+
910import unittest
1011import bad_commit_message_blocker as blocker
1112
@@ -16,64 +17,83 @@ def setUp(self):
1617 pass
1718
1819 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+ ]
2427 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+ )
2732
2833 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+ ]
3441 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+ )
3746
3847 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+ ]
4455 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+ )
4760
4861 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+ ]
5469 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+ )
5774
5875 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" ]
6177 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+ ):
6686 test_input = """Add this cool feature
6787
6888 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 ))
7190
72- def test_checkSubjectSeparateFromBody_WhenNoLineBetweenBodyAndSubject_WillReturnFalse (self ):
91+ def test_checkSubjectSeparateFromBody_WhenNoLineBetweenBodyAndSubject_WillReturnFalse (
92+ self ,
93+ ):
7394 test_input = """Add this cool feature
7495 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 ))
7797
7898 def test_checkSubjectNotTooLong_WhenSubjectTooLong_WillReturnFalse (self ):
7999 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):
83103 test_input = "Add this neat commit message"
84104 self .assertTrue (blocker .check_subject_is_not_too_long (test_input , 60 ))
85105
86- def test_checkSubjectIsCapitalized_WhenSubjectBeginsWithCapital_WillReturnTrue (self ):
106+ def test_checkSubjectIsCapitalized_WhenSubjectBeginsWithCapital_WillReturnTrue (
107+ self ,
108+ ):
87109 test_input = "Add this cool new feature"
88110 self .assertTrue (blocker .check_subject_is_capitalized (test_input ))
89111
90112 def test_checkSubjectIsCapitalized_WhenSubjectBeginsWithLower_WillReturnFalse (self ):
91113 test_input = "add this weird-looking commit message"
92114 self .assertFalse (blocker .check_subject_is_capitalized (test_input ))
93115
94- def test_checkSubjectDoesNotEndWithPeriod_WhenSubjectEndsWithPeriod_WillReturnFalse (self ):
116+ def test_checkSubjectDoesNotEndWithPeriod_WhenSubjectEndsWithPeriod_WillReturnFalse (
117+ self ,
118+ ):
95119 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 ))
98121
99- def test_checkSubjectDoesNotEndWithPeriod_WhenSubjectEndsWithoutPeriod_WillReturnTrue (self ):
122+ def test_checkSubjectDoesNotEndWithPeriod_WhenSubjectEndsWithoutPeriod_WillReturnTrue (
123+ self ,
124+ ):
100125 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 ))
103127
104128 def test_checkBodyLinesAreNotTooLong_WhenLinesTooLong_WillReturnFalse (self ):
105129 test_input = """Add this cool new feature
106130
107131 But damn...
108132 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 ))
111134
112135 def test_checkBodyLinesAreNotTooLong_WhenLinesNotTooLong_WillReturnTrue (self ):
113136 test_input = """Add this cool new feature
114137
115138 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 ))
118140
119141 def test_checkBodyExplainsWhatAndWhy_WhenCalled_WillReturnTrue (self ):
120142 # We cannot currently check this, so we always return true
@@ -123,5 +145,5 @@ def test_checkBodyExplainsWhatAndWhy_WhenCalled_WillReturnTrue(self):
123145 self .assertTrue (blocker .check_body_explains_what_and_why (test_input ))
124146
125147
126- if __name__ == ' __main__' :
148+ if __name__ == " __main__" :
127149 unittest .main ()
0 commit comments