W00t! Working unit tests to assert things, like "That kind works"
and "It doesn't die pathetically," and "It shows stuff." Fix TOX to not include you home directory, so now git_lint will only include your home directory if one exists. It turns out that shutils doesn't have 'which()' prior to Python3. Buggeration.
This commit is contained in:
parent
d21607ed6f
commit
b28b437fb2
|
@ -44,11 +44,11 @@ def find_config_file(options, base):
|
|||
sys.exit(_('Configuration file not found: {}\n').format(config))
|
||||
return configpath
|
||||
|
||||
home = os.environ.get('HOME')
|
||||
possibles = (os.path.join(base, '.git-lint'),
|
||||
os.path.join(base, '.git-lint/config'),
|
||||
home = os.environ.get('HOME', None)
|
||||
possibles = [os.path.join(base, '.git-lint'),
|
||||
os.path.join(base, '.git-lint/config')] + ((home and [
|
||||
os.path.join(home, '.git-lint'),
|
||||
os.path.join(home, '.git-lint/config'))
|
||||
os.path.join(home, '.git-lint/config')]) or [])
|
||||
|
||||
matches = [p for p in possibles if os.path.isfile(p)]
|
||||
if len(matches) == 0:
|
||||
|
@ -188,7 +188,12 @@ def executable_exists(script, label):
|
|||
if scriptname.startswith('/'):
|
||||
return (is_executable(scriptname) and scriptname) or None
|
||||
|
||||
return shutil.which(scriptname)
|
||||
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
|
||||
|
||||
|
||||
def get_working_linter_names(config):
|
||||
|
@ -220,8 +225,8 @@ def get_filelist(options, extras):
|
|||
if os.path.samefile(os.getcwd(), git_base):
|
||||
return base_file_filter(filenames)
|
||||
gitcwd = os.path.join(os.path.relpath(os.getcwd(), git_base), '')
|
||||
return base_file_filter([file for file in files
|
||||
if file.startswith(gitcwd)])
|
||||
return base_file_filter([filename for filename in filenames
|
||||
if filename.startswith(gitcwd)])
|
||||
|
||||
def check_for_conflicts(filesets):
|
||||
""" Scan list of porcelain files for merge conflic state. """
|
||||
|
|
|
@ -15,6 +15,7 @@ import os
|
|||
import shutil
|
||||
import subprocess
|
||||
import pprint
|
||||
import tempfile
|
||||
from git_lint import git_lint
|
||||
|
||||
environment = copy.copy(os.environ)
|
||||
|
@ -37,24 +38,70 @@ for key in ['XDF_CONFIG_HOME', 'GITPERLLIB', 'CDPATH',
|
|||
environment.pop(key, None)
|
||||
|
||||
|
||||
class TestGit_lint(object):
|
||||
git_lint_src = """
|
||||
[pep8]
|
||||
comment = PEP8 with some white space and line length checking turned off
|
||||
output = Running pep8...
|
||||
command = pep8 -r --ignore=E501,W293,W391
|
||||
match = .py
|
||||
print = False
|
||||
condition = error
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
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)
|
||||
# Basic TOX settings aren't good enough: we need to have something more or less guaranteed
|
||||
# to not have a '.git' directory somewhere lurking in a parent folder.
|
||||
|
||||
class gittemp:
|
||||
def __enter__(self):
|
||||
self.cwd = os.getcwd()
|
||||
self.path = tempfile.mkdtemp()
|
||||
return self.path
|
||||
|
||||
def __exit__(self, *args):
|
||||
os.chdir(self.cwd)
|
||||
shutil.rmtree(self.path)
|
||||
|
||||
|
||||
def test_itruns(self):
|
||||
def test_01_not_a_repository():
|
||||
with gittemp() as path:
|
||||
os.chdir(path)
|
||||
p = subprocess.Popen('git lint', shell=True, env=environment,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(stdout, stderr) = p.communicate()
|
||||
assert stderr.startswith('A git repository was not found')
|
||||
|
||||
|
||||
def test_02_empty_repository():
|
||||
with gittemp() as path:
|
||||
os.chdir(path)
|
||||
subprocess.check_call('git init', shell=True, env=environment)
|
||||
p = subprocess.Popen('git lint -l', shell=True, env=environment,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(stdout, stderr) = p.communicate()
|
||||
assert stderr.startswith('No configuration file found,')
|
||||
|
||||
|
||||
def test_03_simple_repository():
|
||||
with gittemp() as path:
|
||||
os.chdir(path)
|
||||
with open(".git-lint", "w") as f:
|
||||
f.write(git_lint_src)
|
||||
subprocess.check_call('git init', shell=True, env=environment)
|
||||
subprocess.check_call('git add .', shell=True, env=environment)
|
||||
subprocess.check_call('git commit -m "Test."', shell=True, env=environment)
|
||||
ret = subprocess.check_output('git lint -v', shell=True, env=environment)
|
||||
assert ret.startswith('git-lint')
|
||||
assert ret.index('Copyright') > 0
|
||||
|
||||
def test_04_linters_present():
|
||||
with gittemp() as path:
|
||||
os.chdir(path)
|
||||
with open(".git-lint", "w") as f:
|
||||
f.write(git_lint_src)
|
||||
subprocess.check_call('git init', shell=True, env=environment)
|
||||
subprocess.check_call('git add .', shell=True, env=environment)
|
||||
subprocess.check_call('git commit -m "Test."', shell=True, env=environment)
|
||||
ret = subprocess.check_output('git lint -l', shell=True, env=environment)
|
||||
assert len(ret.split("\n")) == 3
|
||||
assert ret.index('pep8') > 0
|
||||
|
||||
@classmethod
|
||||
def teardown_class(cls):
|
||||
os.chdir('..')
|
||||
shutil.rmtree('t')
|
||||
|
||||
|
|
Loading…
Reference in New Issue