Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_linter_checks(cls):
"""Add a test for each defined linter and extension."""
for extension, linter_list in gitlint.get_config(None).items():
for linter in linter_list:
cls.add_linter_check(linter.args[0], extension)
def test_get_config_not_in_a_repo(self):
# When not in a repo should return the default config.
self.git_repository_root.return_value = None
parsed_config = gitlint.get_config(None)
self.assertEquals(self.git_lint_config, parsed_config)
def test_get_config_from_default(self):
with mock.patch('os.path.exists', return_value=False):
parsed_config = gitlint.get_config(self.root)
self.assertEquals(self.git_lint_config, parsed_config)
git_config = os.path.join(self.root, '.gitlint.yaml')
config = """python:
extensions:
- .py
command: python
arguments:
- "-R"
- "-v"
filter: ".*"
installation: "Really?"
"""
with mock.patch('os.path.exists', return_value=True), \
mock.patch('gitlint.open',
mock.mock_open(read_data=config),
create=True) as mock_open:
parsed_config = gitlint.get_config(self.root)
mock_open.assert_called_once_with(git_config)
self.assertEqual(['.py'], list(parsed_config.keys()))
self.assertEqual(1, len(parsed_config['.py']))
def test_get_config_empty(self):
# When config file is empty return an empty dictionary.
with mock.patch('os.path.exists', return_value=True), \
mock.patch('gitlint.open',
mock.mock_open(read_data=''),
create=True) as mock_open:
parsed_config = gitlint.get_config(self.root)
self.assertEqual({}, parsed_config)
def setUpClass(cls):
cls._stderr = sys.stderr
sys.stderr = sys.stdout
cls.git_lint_config = gitlint.get_config(None)