Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if lower > upper:
# Should not happen
raise Exception("Cannot find imperative mood of {}".format(key))
mid = (lower + upper) // 2
imperative_form = words[mid]
if key[:3] == imperative_form[:3]:
return imperative_form
elif key < imperative_form:
upper = mid - 1
elif key > imperative_form:
lower = mid + 1
class ImperativeMood(LineRule):
""" This rule will enforce that the commit message title uses imperative
mood. This is done by checking if the first word is in `WORD_SET`, if so
show the word in the correct mood. """
name = "title-imperative-mood"
id = "Z1"
target = CommitMessageTitle
error_msg = ('The first word in commit title should be in imperative mood '
'("{word}" -> "{imperative}"): "{title}"')
def validate(self, line, commit):
# type: (Text, gitlint.commit) -> List[RuleViolation]
violations = []
# Ignore the section tag (ie `<section>: .`)</section>
def test_main_file_changed_and_still_valid_with_commit(self):
lint_response = {
self.filename: {
'comments': []
}
}
self.lint.return_value = lint_response
self.assertEqual(
0,
gitlint.main(
['git-lint', '--last-commit'], stdout=self.stdout, stderr=None))
self.assertIn('OK', self.stdout.getvalue())
self.assert_mocked_calls(commit='abcd' * 10)
def test_modified_files_with_commit(self):
output = os.linesep.join([
'M\ttest/e2etest/data/bash/error.sh',
'D\ttest/e2etest/data/ruby/error.rb',
'A\ttest/e2etest/data/rubylint/error.rb',
'',
]).encode('utf-8')
commit = '0a' * 20
with mock.patch('subprocess.check_output',
return_value=output) as git_call:
self.assertEqual(
{
'/home/user/repo/test/e2etest/data/bash/error.sh': 'M ',
'/home/user/repo/test/e2etest/data/rubylint/error.rb': 'A ',
},
git.modified_files('/home/user/repo', commit=commit))
git_call.assert_called_once_with(
['git', 'diff-tree', '-r', '--root', '--no-commit-id',
'--name-status', commit])
def test_get_vcs_git(self):
self.git_repository_root.return_value = self.root
self.assertEquals((gitlint.git, self.root), gitlint.get_vcs_root())
def test_last_commit(self):
with mock.patch('subprocess.check_output',
return_value=b'0a' * 20 + b'\n') as git_call:
self.assertEqual('0a' * 20, git.last_commit())
git_call.asser_called_once_with(
['git', 'rev-parse', 'HEAD'])
def test_filter_lines_one_group(self):
lines = ['1: foo', '12: bar', '', 'Debug: info']
self.assertEqual(
['1', '12'],
list(utils.filter_lines(lines,
r'(?P
def test_filter_lines_no_groups(self):
lines = ['a', 'b', 'c', 'ad']
self.assertEqual(lines, list(utils.filter_lines(lines, '.')))
self.assertEqual(['a', 'ad'], list(utils.filter_lines(lines, 'a')))
self.assertEqual(['ad'], list(utils.filter_lines(lines, '.d')))
self.assertEqual(['ad'], list(utils.filter_lines(lines, 'd')))
self.assertEqual([], list(utils.filter_lines(lines, '^d')))
self.assertEqual([], list(utils.filter_lines(lines, 'foo')))
def test_filter_lines_no_groups(self):
lines = ['a', 'b', 'c', 'ad']
self.assertEqual(lines, list(utils.filter_lines(lines, '.')))
self.assertEqual(['a', 'ad'], list(utils.filter_lines(lines, 'a')))
self.assertEqual(['ad'], list(utils.filter_lines(lines, '.d')))
self.assertEqual(['ad'], list(utils.filter_lines(lines, 'd')))
self.assertEqual([], list(utils.filter_lines(lines, '^d')))
self.assertEqual([], list(utils.filter_lines(lines, 'foo')))
def test_filter_lines_many_groups(self):
lines = ['1: foo', '12: bar', '', 'Debug: info']
self.assertEqual(
[('1', 'foo'), ('12', 'bar')],
list(utils.filter_lines(lines,
r'(?P
def test_main_file_with_skipped_and_error(self):
lint_response = {
self.filename: {
'skipped': ['skipped1'],
'error': ['error1'],
'comments': []
}
}
self.lint.return_value = lint_response
self.assertEqual(4,
gitlint.main([], stdout=self.stdout, stderr=None))
self.assertNotIn('OK', self.stdout.getvalue())
self.assertIn('skipped1', self.stdout.getvalue())
self.assertIn('error1', self.stdout.getvalue())
self.assert_mocked_calls()