We have a working test harness.

This commit is contained in:
Elf M. Sternberg 2016-09-29 12:38:23 -07:00
parent 3f6fec6ba3
commit d21607ed6f
5 changed files with 48 additions and 58 deletions

View File

@ -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))

View File

@ -1,18 +1,17 @@
#!/usr/bin/env python
import git_lint
from git_lint import load_config, run_linters, git_base
def main(*args):
if git_lint.git_base is None:
if git_base is None:
sys.exit(_('A git repository was not found.'))
pre_commit_config = {
'staging': True,
'base': True,
'all': True
'base': True
}
config = git_lint.get_config(pre_commit_config, git_lint.git_base)
return git_lint.run_gitlint(pre_commit_config, config, [])
config = load_config(pre_commit_config, git_base)
return run_linters(pre_commit_config, config, [])
if __name__ == '__main__':

View File

@ -4,6 +4,7 @@ import getopt
import gettext
import operator
import os
import shutil
import re
import subprocess
import sys
@ -43,7 +44,7 @@ def find_config_file(options, base):
sys.exit(_('Configuration file not found: {}\n').format(config))
return configpath
home = os.path.join(os.environ.get('HOME'))
home = os.environ.get('HOME')
possibles = (os.path.join(base, '.git-lint'),
os.path.join(base, '.git-lint/config'),
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)]
if len(matches) == 0:
sys.exit(_('No configuration file found'))
sys.exit(_('No configuration file found, tried: {}').format(':'.join(possibles)))
return matches[0]
@ -187,11 +188,7 @@ def executable_exists(script, label):
if scriptname.startswith('/'):
return (is_executable(scriptname) and scriptname) or None
possibles = [path for path in
[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
return shutil.which(scriptname)
def get_working_linter_names(config):

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
"""
test_git_lint
@ -9,20 +10,51 @@ Tests for `git_lint` module.
"""
import pytest
import copy
import os
import shutil
import subprocess
import pprint
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):
@classmethod
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
def teardown_class(cls):
pass
os.chdir('..')
shutil.rmtree('t')

View File

@ -8,6 +8,7 @@ deps =
-r{toxinidir}/requirements_dev.txt
commands =
py.test --basetemp={envtmpdir}
passenv = HOME
; If you want to make tox run the tests with the same versions, create a