diff options
-rw-r--r-- | .pylintrc | 48 | ||||
-rw-r--r-- | gitlint/cli.py | 12 | ||||
-rw-r--r-- | gitlint/config.py | 17 | ||||
-rw-r--r-- | gitlint/display.py | 12 | ||||
-rw-r--r-- | gitlint/lint.py | 16 | ||||
-rw-r--r-- | gitlint/rules.py | 36 | ||||
-rw-r--r-- | gitlint/tests/base.py | 4 | ||||
-rw-r--r-- | gitlint/tests/test_cli.py | 20 | ||||
-rw-r--r-- | gitlint/tests/test_config.py | 20 | ||||
-rw-r--r-- | gitlint/tests/test_display.py | 11 | ||||
-rw-r--r-- | gitlint/tests/test_git.py | 9 | ||||
-rw-r--r-- | gitlint/tests/test_hooks.py | 14 | ||||
-rw-r--r-- | gitlint/tests/test_lint.py | 22 | ||||
-rw-r--r-- | gitlint/tests/test_options.py | 9 | ||||
-rw-r--r-- | qa/__init__.py | 0 | ||||
-rw-r--r-- | qa/base.py | 7 | ||||
-rw-r--r-- | qa/test_config.py | 4 | ||||
-rw-r--r-- | qa/test_gitlint.py | 4 | ||||
-rwxr-xr-x | run_tests.sh | 10 | ||||
-rw-r--r-- | setup.py | 1 | ||||
-rw-r--r-- | test-requirements.txt | 1 |
21 files changed, 173 insertions, 104 deletions
diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..cc707f3 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,48 @@ +# The format of this file isn't really documented; just use --generate-rcfile +[MASTER] + +[Messages Control] +# C0111: Don't require docstrings on every method +# W0511: TODOs in code comments are fine. +# W0142: *args and **kwargs are fine. +# W0223: abstract methods don't need to be overwritten (i.e. when overwriting a Django REST serializer) +# W0622: Redefining id is fine. +# R0901: Too many ancestors (i.e. when subclassing test classes) +# R0801: Similar lines in files +# I0011: Informational: locally disabled pylint +# I0013: Informational: Ignoring entire file +disable=C0111,W0511,W0142,W0622,W0223,W0212,R0901,R0801,I0011,I0013 + +[Format] +max-line-length=120 + +[Basic] +# Variable names can be 1 to 31 characters long, with lowercase and underscores +variable-rgx=[a-z_][a-z0-9_]{0,30}$ + +# Argument names can be 2 to 31 characters long, with lowercase and underscores +argument-rgx=[a-z_][a-z0-9_]{1,30}$ + +# Method names should be at least 3 characters long +# and be lowecased with underscores +method-rgx=([a-z_][a-z0-9_]{2,50}|setUp|tearDown)$ + +# Allow 'id' as variable name everywhere +good-names=id,c + +bad-names=__author__ + +# Ignore all variables that start with an underscore (e.g. unused _request variable in a view) +dummy-variables-rgx=_ + +[Design] +max-public-methods=100 +min-public-methods=0 +# Maximum number of attributes of a class +max-attributes=15 +max-args=10 +max-locals=20 + +[Typecheck] +# Allow the use of the Django 'objects' members +generated-members=sh.git diff --git a/gitlint/cli.py b/gitlint/cli.py index ad6d5fa..7a6bb08 100644 --- a/gitlint/cli.py +++ b/gitlint/cli.py @@ -1,11 +1,13 @@ +import os +import sys + +import click + import gitlint from gitlint.lint import GitLinter from gitlint.config import LintConfig, LintConfigError, LintConfigGenerator from gitlint.git import GitContext, GitContextError from gitlint import hooks -import os -import click -import sys DEFAULT_CONFIG_FILE = ".gitlint" @@ -72,7 +74,7 @@ def get_config(ctx, target, config_path, c, ignore, verbose, silent): help="Config file location [default: {0}]".format(DEFAULT_CONFIG_FILE)) @click.option('-c', multiple=True, help="Config flags in format <rule>.<option>=<value> (e.g.: -c T1.line-length=80). " + - "Flag can be used multiple times to set multiple config values.") + "Flag can be used multiple times to set multiple config values.") # pylint: disable=bad-continuation @click.option('--ignore', default="", help="Ignore rules (comma-separated by id or name).") @click.option('-v', '--verbose', count=True, default=0, help="Verbosity, more v's for more verbose output (e.g.: -v, -vv, -vvv). [default: -vvv]", ) @@ -170,4 +172,4 @@ def generate_config(ctx): if __name__ == "__main__": - cli() + cli() # pylint: disable=no-value-for-parameter diff --git a/gitlint/config.py b/gitlint/config.py index b11c33b..602ff00 100644 --- a/gitlint/config.py +++ b/gitlint/config.py @@ -1,21 +1,23 @@ -from gitlint import rules -from gitlint import options - try: # python 2.x from ConfigParser import ConfigParser, Error as ConfigParserError except ImportError: # pragma: no cover # python 3.x - from configparser import ConfigParser, Error as ConfigParserError # pragma: no cover + from configparser import ConfigParser, Error as ConfigParserError # pragma: no cover, pylint: disable=import-error + +import re +import os +import shutil + try: # python >= 2.7 from collections import OrderedDict except ImportError: # pragma: no cover # python 2.4-2.6 from ordereddict import OrderedDict # pragma: no cover -import re -import os -import shutil + +from gitlint import rules +from gitlint import options class LintConfigError(Exception): @@ -146,7 +148,6 @@ class LintConfig(object): matches = pattern.match(line) if matches and len(matches.groups()) == 1: self.set_general_option('ignore', matches.group(1)) - self.enabled = False def apply_config_options(self, config_options): """ Given a list of config options of the form "<rule>.<option>=<value>", parses out the correct rule and option diff --git a/gitlint/display.py b/gitlint/display.py index f84076a..3ab2419 100644 --- a/gitlint/display.py +++ b/gitlint/display.py @@ -17,20 +17,20 @@ class Display(object): if self.config.verbosity >= verbosity: stream.write(message + "\n") - def v(self, message, exact=False): + def v(self, message, exact=False): # pylint: disable=invalid-name self._output(message, 1, exact, stdout) - def vv(self, message, exact=False): + def vv(self, message, exact=False): # pylint: disable=invalid-name self._output(message, 2, exact, stdout) - def vvv(self, message, exact=False): + def vvv(self, message, exact=False): # pylint: disable=invalid-name self._output(message, 3, exact, stdout) - def e(self, message, exact=False): + def e(self, message, exact=False): # pylint: disable=invalid-name self._output(message, 1, exact, stderr) - def ee(self, message, exact=False): + def ee(self, message, exact=False): # pylint: disable=invalid-name self._output(message, 2, exact, stderr) - def eee(self, message, exact=False): + def eee(self, message, exact=False): # pylint: disable=invalid-name self._output(message, 3, exact, stderr) diff --git a/gitlint/lint.py b/gitlint/lint.py index e6fb653..80662a0 100644 --- a/gitlint/lint.py +++ b/gitlint/lint.py @@ -1,5 +1,5 @@ from __future__ import print_function -from gitlint import rules +from gitlint import rules as gitlint_rules from gitlint import display @@ -10,17 +10,18 @@ class GitLinter(object): @property def body_line_rules(self): - return [rule for rule in self.config.body_rules if isinstance(rule, rules.LineRule)] + return [rule for rule in self.config.body_rules if isinstance(rule, gitlint_rules.LineRule)] @property def body_multiline_rules(self): - return [rule for rule in self.config.body_rules if isinstance(rule, rules.MultiLineRule)] + return [rule for rule in self.config.body_rules if isinstance(rule, gitlint_rules.MultiLineRule)] @property def title_line_rules(self): - return [rule for rule in self.config.title_rules if isinstance(rule, rules.LineRule)] + return [rule for rule in self.config.title_rules if isinstance(rule, gitlint_rules.LineRule)] - def _apply_line_rules(self, lines, rules, line_nr_start, gitcontext): + @staticmethod + def _apply_line_rules(lines, rules, line_nr_start, gitcontext): """ Iterates over the lines in a given list of lines and validates a given list of rules against each line """ all_violations = [] line_nr = line_nr_start @@ -34,7 +35,8 @@ class GitLinter(object): line_nr += 1 return all_violations - def _apply_commit_rules(self, rules, commit, gitcontext): + @staticmethod + def _apply_commit_rules(rules, commit, gitcontext): """ Applies a set of rules against a given commit and gitcontext """ all_violations = [] for rule in rules: @@ -68,4 +70,4 @@ class GitLinter(object): if v.content: self.display.eee("{0}: {1} {2}: \"{3}\"".format(v.line_nr, v.rule_id, v.message, v.content), exact=True) else: - self.display.eee("{0}: {1} {2}".format(v.line_nr, v.rule_id, v.message, v.content), exact=True) + self.display.eee("{0}: {1} {2}".format(v.line_nr, v.rule_id, v.message), exact=True) diff --git a/gitlint/rules.py b/gitlint/rules.py index bd80228..3b32b1f 100644 --- a/gitlint/rules.py +++ b/gitlint/rules.py @@ -1,18 +1,18 @@ -from abc import abstractmethod, ABCMeta -from gitlint.options import IntOption, BoolOption, StrOption, ListOption - import copy import re +from gitlint.options import IntOption, BoolOption, StrOption, ListOption + class Rule(object): """ Class representing gitlint rules. """ options_spec = [] id = [] name = "" - __metaclass__ = ABCMeta - def __init__(self, opts={}): + def __init__(self, opts=None): + if not opts: + opts = {} self.options = {} for op_spec in self.options_spec: self.options[op_spec.name] = copy.deepcopy(op_spec) @@ -29,10 +29,6 @@ class Rule(object): def __repr__(self): return self.__str__() # pragma: no cover - @abstractmethod - def validate(self): - pass # pragma: no cover - class MultiLineRule(Rule): """ Class representing rules that act on multiple lines at once """ @@ -80,7 +76,7 @@ class MaxLineLength(LineRule): options_spec = [IntOption('line-length', 80, "Max line length")] violation_message = "Line exceeds max length ({0}>{1})" - def validate(self, line, gitcontext): + def validate(self, line, _gitcontext): max_length = self.options['line-length'].value if len(line) > max_length: return [RuleViolation(self.id, self.violation_message.format(len(line), max_length), line)] @@ -91,7 +87,7 @@ class TrailingWhiteSpace(LineRule): id = "R2" violation_message = "Line has trailing whitespace" - def validate(self, line, gitcontext): + def validate(self, line, _gitcontext): pattern = re.compile(r"\s$") if pattern.search(line): return [RuleViolation(self.id, self.violation_message, line)] @@ -102,7 +98,7 @@ class HardTab(LineRule): id = "R3" violation_message = "Line contains hard tab characters (\\t)" - def validate(self, line, gitcontext): + def validate(self, line, _gitcontext): if "\t" in line: return [RuleViolation(self.id, self.violation_message, line)] @@ -115,7 +111,7 @@ class LineMustNotContainWord(LineRule): options_spec = [ListOption('words', [], "Comma separated list of words that should not be found")] violation_message = "Line contains {0}" - def validate(self, line, gitcontext): + def validate(self, line, _gitcontext): strings = self.options['words'].value violations = [] for string in strings: @@ -131,7 +127,7 @@ class LeadingWhiteSpace(LineRule): id = "R6" violation_message = "Line has leading whitespace" - def validate(self, line, gitcontext): + def validate(self, line, _gitcontext): pattern = re.compile(r"^\s") if pattern.search(line): return [RuleViolation(self.id, self.violation_message, line)] @@ -154,7 +150,7 @@ class TitleTrailingPunctuation(CommitMessageTitleRule): name = "title-trailing-punctuation" id = "T3" - def validate(self, title, gitcontext): + def validate(self, title, _gitcontext): punctuation_marks = '?:!.,;' for punctuation_mark in punctuation_marks: if title.endswith(punctuation_mark): @@ -185,7 +181,7 @@ class TitleRegexMatches(CommitMessageTitleRule): id = "T7" options_spec = [StrOption('regex', ".*", "Regex the title should match")] - def validate(self, title, gitcontext): + def validate(self, title, _gitcontext): regex = self.options['regex'].value pattern = re.compile(regex) if not pattern.search(title): @@ -212,7 +208,7 @@ class BodyFirstLineEmpty(MultiLineRule, CommitMessageBodyRule): name = "body-first-line-empty" id = "B4" - def validate(self, commit, gitcontext): + def validate(self, commit, _gitcontext): if len(commit.message.body) >= 1: first_line = commit.message.body[0] if first_line != "": @@ -224,7 +220,7 @@ class BodyMinLength(MultiLineRule, CommitMessageBodyRule): id = "B5" options_spec = [IntOption('min-length', 20, "Minimum body length")] - def validate(self, commit, gitcontext): + def validate(self, commit, _gitcontext): min_length = self.options['min-length'].value lines = commit.message.body if len(lines) == 3: @@ -239,7 +235,7 @@ class BodyMissing(MultiLineRule, CommitMessageBodyRule): id = "B6" options_spec = [BoolOption('ignore-merge-commits', True, "Ignore merge commits")] - def validate(self, commit, gitcontext): + def validate(self, commit, _gitcontext): # ignore merges when option tells us to, which may have no body if self.options['ignore-merge-commits'].value and commit.is_merge_commit: return @@ -252,7 +248,7 @@ class BodyChangedFileMention(MultiLineRule, CommitMessageBodyRule): id = "B7" options_spec = [ListOption('files', [], "Files that need to be mentioned ")] - def validate(self, commit, gitcontext): + def validate(self, commit, _gitcontext): violations = [] for needs_mentioned_file in self.options['files'].value: # if a file that we need to look out for is actually changed, then check whether it occurs diff --git a/gitlint/tests/base.py b/gitlint/tests/base.py index dd48dcb..35e67e1 100644 --- a/gitlint/tests/base.py +++ b/gitlint/tests/base.py @@ -1,8 +1,8 @@ +import os + from unittest2 import TestCase from gitlint.git import GitContext -import os - class BaseTestCase(TestCase): # In case of assert failures, print the full error message diff --git a/gitlint/tests/test_cli.py b/gitlint/tests/test_cli.py index 402cd3a..c508cb1 100644 --- a/gitlint/tests/test_cli.py +++ b/gitlint/tests/test_cli.py @@ -1,11 +1,3 @@ -from gitlint.tests.base import BaseTestCase -from gitlint import cli -from gitlint import hooks -from gitlint import __version__ -from gitlint import config -from click.testing import CliRunner -from mock import patch -from sh import CommandNotFound import os try: @@ -15,6 +7,16 @@ except ImportError: # python 3.x from io import StringIO +from click.testing import CliRunner +from mock import patch +from sh import CommandNotFound + +from gitlint.tests.base import BaseTestCase +from gitlint import cli +from gitlint import hooks +from gitlint import __version__ +from gitlint import config + class CLITests(BaseTestCase): USAGE_ERROR_CODE = 253 @@ -33,7 +35,7 @@ class CLITests(BaseTestCase): self.assertEqual(result.output.split("\n")[0], "cli, version {0}".format(__version__)) @patch('gitlint.cli.GitLinter') - def test_config_file(self, git_linter): + def test_config_file(self, _git_linter): config_path = self.get_sample_path("config/gitlintconfig") result = self.cli.invoke(cli.cli, ["--config", config_path]) self.assertEqual(result.exit_code, 0) diff --git a/gitlint/tests/test_config.py b/gitlint/tests/test_config.py index 537298a..a56f5e3 100644 --- a/gitlint/tests/test_config.py +++ b/gitlint/tests/test_config.py @@ -1,8 +1,9 @@ -from gitlint.tests.base import BaseTestCase -from gitlint.config import LintConfig, LintConfigError, LintConfigGenerator, GITLINT_CONFIG_TEMPLATE_SRC_PATH -from gitlint import rules from mock import patch +from gitlint import rules +from gitlint.config import LintConfig, LintConfigError, LintConfigGenerator, GITLINT_CONFIG_TEMPLATE_SRC_PATH +from gitlint.tests.base import BaseTestCase + class LintConfigTests(BaseTestCase): def test_get_rule(self): @@ -14,7 +15,7 @@ class LintConfigTests(BaseTestCase): self.assertEqual(rule, expected) # get by name - expected = rules.TitleTrailingWhitespace() + expected = rules.TitleTrailingWhitespace() # pylint: disable=redefined-variable-type rule = config.get_rule('title-trailing-whitespace') self.assertEqual(rule, expected) @@ -47,7 +48,7 @@ class LintConfigTests(BaseTestCase): # invalid option value expected_error_msg = "'foo' is not a valid value for option 'title-max-length.line-length'. " + \ - "Option 'line-length' must be a positive integer \(current value: 'foo'\)." + r"Option 'line-length' must be a positive integer \(current value: 'foo'\)." with self.assertRaisesRegexp(LintConfigError, expected_error_msg): config.set_rule_option('title-max-length', 'line-length', "foo") @@ -85,7 +86,7 @@ class LintConfigTests(BaseTestCase): # invalid verbosity incorrect_values = [-1, "foo"] for value in incorrect_values: - expected_msg = "Option 'verbosity' must be a positive integer \(current value: '{0}'\)".format(value) + expected_msg = r"Option 'verbosity' must be a positive integer \(current value: '{0}'\)".format(value) with self.assertRaisesRegexp(LintConfigError, expected_msg): config.verbosity = value @@ -98,7 +99,7 @@ class LintConfigTests(BaseTestCase): incorrect_values = [-1, 4, "foo"] for value in incorrect_values: with self.assertRaisesRegexp(LintConfigError, - "Option 'ignore-merge-commits' must be either 'true' or 'false'"): + r"Option 'ignore-merge-commits' must be either 'true' or 'false'"): config.ignore_merge_commits = value def test_apply_config_options(self): @@ -192,7 +193,7 @@ class LintConfigTests(BaseTestCase): # invalid option value path = self.get_sample_path("config/invalid-option-value") expected_error_msg = "'foo' is not a valid value for option 'title-max-length.line-length'. " + \ - "Option 'line-length' must be a positive integer \(current value: 'foo'\)." + r"Option 'line-length' must be a positive integer \(current value: 'foo'\)." with self.assertRaisesRegexp(LintConfigError, expected_error_msg): LintConfig.load_from_file(path) @@ -232,7 +233,8 @@ class LintConfigTests(BaseTestCase): class LintConfigGeneratorTests(BaseTestCase): + @staticmethod @patch('gitlint.config.shutil.copyfile') - def test_install_commit_msg_hook_negative(self, copy): + def test_install_commit_msg_hook_negative(copy): LintConfigGenerator.generate_config("foo/bar/test") copy.assert_called_with(GITLINT_CONFIG_TEMPLATE_SRC_PATH, "foo/bar/test") diff --git a/gitlint/tests/test_display.py b/gitlint/tests/test_display.py index 2157a13..f7cf765 100644 --- a/gitlint/tests/test_display.py +++ b/gitlint/tests/test_display.py @@ -1,8 +1,3 @@ -from gitlint.display import Display -from gitlint.config import LintConfig -from gitlint.tests.base import BaseTestCase -from mock import patch - try: # python 2.x from StringIO import StringIO @@ -10,6 +5,12 @@ except ImportError: # python 3.x from io import StringIO +from mock import patch + +from gitlint.display import Display +from gitlint.config import LintConfig +from gitlint.tests.base import BaseTestCase + class DisplayTests(BaseTestCase): def test_v(self): diff --git a/gitlint/tests/test_git.py b/gitlint/tests/test_git.py index 7d83904..6fdbb59 100644 --- a/gitlint/tests/test_git.py +++ b/gitlint/tests/test_git.py @@ -1,13 +1,14 @@ +from mock import patch, call +from sh import ErrorReturnCode, CommandNotFound + from gitlint.tests.base import BaseTestCase from gitlint.git import GitContext, GitContextError -from sh import ErrorReturnCode, CommandNotFound -from mock import patch, call class GitTests(BaseTestCase): @patch('gitlint.git.sh') def test_get_latest_commit(self, sh): - def git_log_side_effect(*args, **kwargs): + def git_log_side_effect(*args, **_kwargs): return_values = {'--pretty=%B': "commit-title\n\ncommit-body", '--pretty=%aN': "test author", '--pretty=%aE': "test-email@foo.com", '--pretty=%aD': "Mon Feb 29 22:19:39 2016 +0100", '--pretty=%P': "abc"} @@ -45,7 +46,7 @@ class GitTests(BaseTestCase): @patch('gitlint.git.sh') def test_get_latest_commit_merge_commit(self, sh): - def git_log_side_effect(*args, **kwargs): + def git_log_side_effect(*args, **_kwargs): return_values = {'--pretty=%B': "Merge \"foo bar commit\"", '--pretty=%aN': "test author", '--pretty=%aE': "test-email@foo.com", '--pretty=%aD': "Mon Feb 29 22:19:39 2016 +0100", '--pretty=%P': "abc def"} diff --git a/gitlint/tests/test_hooks.py b/gitlint/tests/test_hooks.py index 2a5d7ac..393b795 100644 --- a/gitlint/tests/test_hooks.py +++ b/gitlint/tests/test_hooks.py @@ -1,9 +1,11 @@ +import os + +from mock import patch, ANY, mock_open + from gitlint.tests.base import BaseTestCase from gitlint.config import LintConfig from gitlint.hooks import GitHookInstaller, GitHookInstallerError, COMMIT_MSG_HOOK_SRC_PATH, COMMIT_MSG_HOOK_DST_PATH, \ GITLINT_HOOK_IDENTIFIER -from mock import patch, ANY, mock_open -import os class HookTests(BaseTestCase): @@ -13,12 +15,13 @@ class HookTests(BaseTestCase): path = GitHookInstaller.commit_msg_hook_path(lint_config) self.assertEqual(path, expected_path) + @staticmethod @patch('os.chmod') @patch('os.stat') @patch('gitlint.hooks.shutil.copy') @patch('os.path.exists', return_value=False) @patch('os.path.isdir', return_value=True) - def test_install_commit_msg_hook(self, isdir, path_exists, copy, stat, chmod): + def test_install_commit_msg_hook(isdir, path_exists, copy, stat, chmod): lint_config = LintConfig(target="/foo/bar") expected_dst = os.path.join("/foo/bar", COMMIT_MSG_HOOK_DST_PATH) GitHookInstaller.install_commit_msg_hook(lint_config) @@ -51,10 +54,11 @@ class HookTests(BaseTestCase): with self.assertRaisesRegexp(GitHookInstallerError, expected_msg): GitHookInstaller.install_commit_msg_hook(lint_config) + @staticmethod @patch('os.remove') @patch('os.path.exists', return_value=True) @patch('os.path.isdir', return_value=True) - def test_uninstall_commit_msg_hook(self, isdir, path_exists, remove): + def test_uninstall_commit_msg_hook(isdir, path_exists, remove): lint_config = LintConfig(target="/foo/bar") read_data = "#!/bin/sh\n" + GITLINT_HOOK_IDENTIFIER with patch('gitlint.hooks.open', mock_open(read_data=read_data), create=True): @@ -96,7 +100,7 @@ class HookTests(BaseTestCase): read_data = "#!/bin/sh\nfoo" expected_dst = os.path.join("/foo/bar", COMMIT_MSG_HOOK_DST_PATH) expected_msg = "The commit-msg hook in {0} was not installed by gitlint ".format(expected_dst) + \ - "\(or it was modified\).\nUninstallation of 3th party or modified gitlint hooks " + \ + r"\(or it was modified\).\nUninstallation of 3th party or modified gitlint hooks " + \ "is not supported." with patch('gitlint.hooks.open', mock_open(read_data=read_data), create=True): with self.assertRaisesRegexp(GitHookInstallerError, expected_msg): diff --git a/gitlint/tests/test_lint.py b/gitlint/tests/test_lint.py index 6e44276..bd6ff25 100644 --- a/gitlint/tests/test_lint.py +++ b/gitlint/tests/test_lint.py @@ -1,9 +1,3 @@ -from gitlint.tests.base import BaseTestCase -from gitlint.lint import GitLinter -from gitlint.rules import RuleViolation -from gitlint.config import LintConfig -from mock import patch - try: # python 2.x from StringIO import StringIO @@ -11,6 +5,13 @@ except ImportError: # python 3.x from io import StringIO +from mock import patch + +from gitlint.tests.base import BaseTestCase +from gitlint.lint import GitLinter +from gitlint.rules import RuleViolation +from gitlint.config import LintConfig + class RuleOptionTests(BaseTestCase): def test_lint_sample1(self): @@ -28,8 +29,7 @@ class RuleOptionTests(BaseTestCase): RuleViolation("B2", "Line has trailing whitespace", "This line has a trailing space. ", 4), RuleViolation("B2", "Line has trailing whitespace", "This line has a trailing tab.\t", 5), RuleViolation("B3", "Line contains hard tab characters (\\t)", - "This line has a trailing tab.\t", 5), - ] + "This line has a trailing tab.\t", 5)] self.assertListEqual(violations, expected_errors) @@ -63,8 +63,7 @@ class RuleOptionTests(BaseTestCase): RuleViolation("B2", "Line has trailing whitespace", "This line has a trailing tab.\t", 5), RuleViolation("B3", "Line contains hard tab characters (\\t)", - "This line has a trailing tab.\t", 5), - ] + "This line has a trailing tab.\t", 5)] self.assertListEqual(violations, expected) @@ -95,8 +94,7 @@ class RuleOptionTests(BaseTestCase): RuleViolation("B2", "Line has trailing whitespace", "This line has a trailing tab.\t", 5), RuleViolation("B3", "Line contains hard tab characters (\\t)", - "This line has a trailing tab.\t", 5), - ] + "This line has a trailing tab.\t", 5)] self.assertListEqual(violations, expected) def test_lint_merge_commit(self): diff --git a/gitlint/tests/test_options.py b/gitlint/tests/test_options.py index 1d07e48..57aee39 100644 --- a/gitlint/tests/test_options.py +++ b/gitlint/tests/test_options.py @@ -16,12 +16,12 @@ class RuleOptionTests(BaseTestCase): self.assertEqual(option.value, 456) # error on negative int when not allowed - expected_error = "Option 'test-name' must be a positive integer \(current value: '-123'\)" + expected_error = r"Option 'test-name' must be a positive integer \(current value: '-123'\)" with self.assertRaisesRegexp(RuleOptionError, expected_error): option.set(-123) # error on non-int value - expected_error = "Option 'test-name' must be a positive integer \(current value: 'foo'\)" + expected_error = r"Option 'test-name' must be a positive integer \(current value: 'foo'\)" with self.assertRaisesRegexp(RuleOptionError, expected_error): option.set("foo") @@ -31,7 +31,7 @@ class RuleOptionTests(BaseTestCase): self.assertEqual(option.value, -456) # error on non-int value when negative int is allowed - expected_error = "Option 'test-name' must be an integer \(current value: 'foo'\)" + expected_error = r"Option 'test-name' must be an integer \(current value: 'foo'\)" with self.assertRaisesRegexp(RuleOptionError, expected_error): option.set("foo") @@ -69,9 +69,8 @@ class RuleOptionTests(BaseTestCase): # error on incorrect value incorrect_values = [1, -1, "foo", ["foo"], {'foo': "bar"}] - expected_error = "Option 'test-name' must be either 'true' or 'false'" for value in incorrect_values: - with self.assertRaisesRegexp(RuleOptionError, expected_error): + with self.assertRaisesRegexp(RuleOptionError, "Option 'test-name' must be either 'true' or 'false'"): option.set(value) def test_list_option(self): diff --git a/qa/__init__.py b/qa/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/qa/__init__.py @@ -1,8 +1,9 @@ -from unittest2 import TestCase +import os from datetime import datetime from uuid import uuid4 -from sh import git, rm, touch -import os + +from unittest2 import TestCase +from sh import git, rm, touch # pylint: disable=no-name-in-module class BaseTestCase(TestCase): diff --git a/qa/test_config.py b/qa/test_config.py index 4652c03..f68884d 100644 --- a/qa/test_config.py +++ b/qa/test_config.py @@ -1,5 +1,5 @@ -from base import BaseTestCase -from sh import gitlint +from sh import gitlint # pylint: disable=no-name-in-module |