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