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))
|
sys.exit(_('Configuration file not found: {}\n').format(config))
|
||||||
return configpath
|
return configpath
|
||||||
|
|
||||||
home = os.environ.get('HOME')
|
home = os.environ.get('HOME', None)
|
||||||
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')] + ((home and [
|
||||||
os.path.join(home, '.git-lint'),
|
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)]
|
matches = [p for p in possibles if os.path.isfile(p)]
|
||||||
if len(matches) == 0:
|
if len(matches) == 0:
|
||||||
|
@ -188,7 +188,12 @@ 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
|
||||||
|
|
||||||
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):
|
def get_working_linter_names(config):
|
||||||
|
@ -220,8 +225,8 @@ def get_filelist(options, extras):
|
||||||
if os.path.samefile(os.getcwd(), git_base):
|
if os.path.samefile(os.getcwd(), git_base):
|
||||||
return base_file_filter(filenames)
|
return base_file_filter(filenames)
|
||||||
gitcwd = os.path.join(os.path.relpath(os.getcwd(), git_base), '')
|
gitcwd = os.path.join(os.path.relpath(os.getcwd(), git_base), '')
|
||||||
return base_file_filter([file for file in files
|
return base_file_filter([filename for filename in filenames
|
||||||
if file.startswith(gitcwd)])
|
if filename.startswith(gitcwd)])
|
||||||
|
|
||||||
def check_for_conflicts(filesets):
|
def check_for_conflicts(filesets):
|
||||||
""" Scan list of porcelain files for merge conflic state. """
|
""" Scan list of porcelain files for merge conflic state. """
|
||||||
|
|
|
@ -15,6 +15,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import pprint
|
import pprint
|
||||||
|
import tempfile
|
||||||
from git_lint import git_lint
|
from git_lint import git_lint
|
||||||
|
|
||||||
environment = copy.copy(os.environ)
|
environment = copy.copy(os.environ)
|
||||||
|
@ -37,24 +38,70 @@ for key in ['XDF_CONFIG_HOME', 'GITPERLLIB', 'CDPATH',
|
||||||
environment.pop(key, None)
|
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
|
# Basic TOX settings aren't good enough: we need to have something more or less guaranteed
|
||||||
def setup_class(cls):
|
# to not have a '.git' directory somewhere lurking in a parent folder.
|
||||||
if os.path.exists('t'):
|
|
||||||
shutil.rmtree('t')
|
class gittemp:
|
||||||
os.mkdir('t')
|
def __enter__(self):
|
||||||
shutil.copy('.git-lint', 't')
|
self.cwd = os.getcwd()
|
||||||
os.chdir('t')
|
self.path = tempfile.mkdtemp()
|
||||||
subprocess.check_output('git init', shell=True, env=environment)
|
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)
|
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')
|
|
||||||
|
|
||||||
|
|
1
tox.ini
1
tox.ini
|
@ -8,7 +8,6 @@ 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