We have a working test harness.
This commit is contained in:
parent
3f6fec6ba3
commit
d21607ed6f
39
bin/git-lint
39
bin/git-lint
|
@ -1,39 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
import git_lint
|
|
||||||
|
|
||||||
def main(*args):
|
|
||||||
if git_lint.git_base is None:
|
|
||||||
sys.exit(_('A git repository was not found.'))
|
|
||||||
|
|
||||||
(cmdline, filenames, excluded_commands) = git_lint.make_rational_options(git_lint.OPTIONS_LIST, args)
|
|
||||||
|
|
||||||
if len(excluded_commands) > 0:
|
|
||||||
print(_('These command line options were ignored due to option precedence.'))
|
|
||||||
for exc in excluded_commands:
|
|
||||||
print("\t{}".format(exc))
|
|
||||||
|
|
||||||
try:
|
|
||||||
config = git_lint.get_config(cmdline, git_lint.git_base)
|
|
||||||
|
|
||||||
if 'help' in cmdline:
|
|
||||||
git_lint.print_help(OPTIONS_LIST, NAME)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if 'version' in cmdline:
|
|
||||||
git_lint.print_version(NAME, VERSION)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if 'linters' in cmdline:
|
|
||||||
git_lint.print_linters(config)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
return git_lint.run_gitlint(cmdline, config, filenames)
|
|
||||||
|
|
||||||
except getopt.GetoptError as err:
|
|
||||||
git_lint.print_help(OPTIONS_LIST)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
import sys
|
|
||||||
sys.exit(main(*sys.argv))
|
|
|
@ -1,18 +1,17 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import git_lint
|
from git_lint import load_config, run_linters, git_base
|
||||||
|
|
||||||
def main(*args):
|
def main(*args):
|
||||||
if git_lint.git_base is None:
|
if git_base is None:
|
||||||
sys.exit(_('A git repository was not found.'))
|
sys.exit(_('A git repository was not found.'))
|
||||||
|
|
||||||
pre_commit_config = {
|
pre_commit_config = {
|
||||||
'staging': True,
|
'staging': True,
|
||||||
'base': True,
|
'base': True
|
||||||
'all': True
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config = git_lint.get_config(pre_commit_config, git_lint.git_base)
|
config = load_config(pre_commit_config, git_base)
|
||||||
return git_lint.run_gitlint(pre_commit_config, config, [])
|
return run_linters(pre_commit_config, config, [])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -4,6 +4,7 @@ import getopt
|
||||||
import gettext
|
import gettext
|
||||||
import operator
|
import operator
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -43,7 +44,7 @@ def find_config_file(options, base):
|
||||||
sys.exit(_('Configuration file not found: {}\n').format(config))
|
sys.exit(_('Configuration file not found: {}\n').format(config))
|
||||||
return configpath
|
return configpath
|
||||||
|
|
||||||
home = os.path.join(os.environ.get('HOME'))
|
home = os.environ.get('HOME')
|
||||||
possibles = (os.path.join(base, '.git-lint'),
|
possibles = (os.path.join(base, '.git-lint'),
|
||||||
os.path.join(base, '.git-lint/config'),
|
os.path.join(base, '.git-lint/config'),
|
||||||
os.path.join(home, '.git-lint'),
|
os.path.join(home, '.git-lint'),
|
||||||
|
@ -51,7 +52,7 @@ def find_config_file(options, base):
|
||||||
|
|
||||||
matches = [p for p in possibles if os.path.isfile(p)]
|
matches = [p for p in possibles if os.path.isfile(p)]
|
||||||
if len(matches) == 0:
|
if len(matches) == 0:
|
||||||
sys.exit(_('No configuration file found'))
|
sys.exit(_('No configuration file found, tried: {}').format(':'.join(possibles)))
|
||||||
|
|
||||||
return matches[0]
|
return matches[0]
|
||||||
|
|
||||||
|
@ -187,11 +188,7 @@ def executable_exists(script, label):
|
||||||
if scriptname.startswith('/'):
|
if scriptname.startswith('/'):
|
||||||
return (is_executable(scriptname) and scriptname) or None
|
return (is_executable(scriptname) and scriptname) or None
|
||||||
|
|
||||||
possibles = [path for path in
|
return shutil.which(scriptname)
|
||||||
[os.path.join(path, scriptname)
|
|
||||||
for path in os.environ.get('PATH').split(':')]
|
|
||||||
if is_executable(path)]
|
|
||||||
return (len(possibles) and possibles.pop(0)) or False
|
|
||||||
|
|
||||||
|
|
||||||
def get_working_linter_names(config):
|
def get_working_linter_names(config):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
"""
|
"""
|
||||||
test_git_lint
|
test_git_lint
|
||||||
|
@ -9,20 +10,51 @@ Tests for `git_lint` module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import copy
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import pprint
|
||||||
from git_lint import git_lint
|
from git_lint import git_lint
|
||||||
|
|
||||||
|
environment = copy.copy(os.environ)
|
||||||
|
environment.update({
|
||||||
|
'LANG': 'C',
|
||||||
|
'LC_ALL': 'C',
|
||||||
|
'PAGER': 'cat',
|
||||||
|
'TZ': 'UTC',
|
||||||
|
'EDITOR': ':',
|
||||||
|
'GIT_AUTHOR_EMAIL': 'author@example.com',
|
||||||
|
'GIT_AUTHOR_NAME': '"A U Thor"',
|
||||||
|
'GIT_COMMITTER_EMAIL': 'committer@example.com',
|
||||||
|
'GIT_COMMITTER_NAME': '"C O Mitter"',
|
||||||
|
'GIT_MERGE_VERBOSITY': '5',
|
||||||
|
'GIT_MERGE_AUTOEDIT': 'no'
|
||||||
|
})
|
||||||
|
|
||||||
|
for key in ['XDF_CONFIG_HOME', 'GITPERLLIB', 'CDPATH',
|
||||||
|
'GREP_OPTIONS', 'UNZIP']:
|
||||||
|
environment.pop(key, None)
|
||||||
|
|
||||||
|
|
||||||
class TestGit_lint(object):
|
class TestGit_lint(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_class(cls):
|
def setup_class(cls):
|
||||||
pass
|
if os.path.exists('t'):
|
||||||
|
shutil.rmtree('t')
|
||||||
|
os.mkdir('t')
|
||||||
|
shutil.copy('.git-lint', 't')
|
||||||
|
os.chdir('t')
|
||||||
|
subprocess.check_output('git init', shell=True, env=environment)
|
||||||
|
|
||||||
def test_something(self):
|
|
||||||
pass
|
def test_itruns(self):
|
||||||
|
ret = subprocess.check_output('git lint -v', shell=True, env=environment)
|
||||||
|
assert ret.startswith('git-lint')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def teardown_class(cls):
|
def teardown_class(cls):
|
||||||
pass
|
os.chdir('..')
|
||||||
|
shutil.rmtree('t')
|
||||||
|
|
||||||
|
|
1
tox.ini
1
tox.ini
|
@ -8,6 +8,7 @@ deps =
|
||||||
-r{toxinidir}/requirements_dev.txt
|
-r{toxinidir}/requirements_dev.txt
|
||||||
commands =
|
commands =
|
||||||
py.test --basetemp={envtmpdir}
|
py.test --basetemp={envtmpdir}
|
||||||
|
passenv = HOME
|
||||||
|
|
||||||
|
|
||||||
; If you want to make tox run the tests with the same versions, create a
|
; If you want to make tox run the tests with the same versions, create a
|
||||||
|
|
Loading…
Reference in New Issue