If I'm going to use a linter, then by Thoth's eyes I ought to use it on this code, ne?
This commit is contained in:
parent
3155209c68
commit
917389b836
|
@ -18,6 +18,8 @@ import pprint
|
||||||
import tempfile
|
import tempfile
|
||||||
from git_lint import git_lint
|
from git_lint import git_lint
|
||||||
|
|
||||||
|
# Set up the environment to closely match the one cgit uses for its own unit testing.
|
||||||
|
|
||||||
environment = copy.copy(os.environ)
|
environment = copy.copy(os.environ)
|
||||||
environment.update({
|
environment.update({
|
||||||
'LANG': 'C',
|
'LANG': 'C',
|
||||||
|
@ -48,21 +50,25 @@ print = False
|
||||||
condition = error
|
condition = error
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# Basic TOX settings aren't good enough: we need to have something more or less guaranteed
|
# 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.
|
# to not have a '.git' directory somewhere lurking in a parent folder.
|
||||||
|
|
||||||
def shell(cmd, environment=environment):
|
def shell(cmd, environment=environment):
|
||||||
return subprocess.check_call(cmd, shell=True, env=environment)
|
return subprocess.check_call(cmd, shell=True, env=environment)
|
||||||
|
|
||||||
|
|
||||||
def outshell(cmd, environment=environment):
|
def outshell(cmd, environment=environment):
|
||||||
return subprocess.check_output(cmd, shell=True, env=environment)
|
return subprocess.check_output(cmd, shell=True, env=environment)
|
||||||
|
|
||||||
|
|
||||||
def fullshell(cmd, environment=environment):
|
def fullshell(cmd, environment=environment):
|
||||||
process = subprocess.Popen(cmd, shell=True, env=environment,
|
process = subprocess.Popen(cmd, shell=True, env=environment,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
(stdout, stderr) = process.communicate()
|
(stdout, stderr) = process.communicate()
|
||||||
return (stdout, stderr, process.returncode)
|
return (stdout, stderr, process.returncode)
|
||||||
|
|
||||||
|
|
||||||
class gittemp:
|
class gittemp:
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.cwd = os.getcwd()
|
self.cwd = os.getcwd()
|
||||||
|
@ -81,11 +87,15 @@ def test_01_not_a_repository():
|
||||||
assert stderr.startswith('A git repository was not found')
|
assert stderr.startswith('A git repository was not found')
|
||||||
|
|
||||||
|
|
||||||
|
# The important aspect here is that it SHOULD NOT CRASH even though
|
||||||
|
# there is no HEAD repository and no configuration file. It should
|
||||||
|
# report the lack of a configuration file without blinking.
|
||||||
|
|
||||||
def test_02_empty_repository():
|
def test_02_empty_repository():
|
||||||
with gittemp() as path:
|
with gittemp() as path:
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
shell('git init')
|
shell('git init')
|
||||||
(stdout, stderr, rc) = fullshell('git lint -l')
|
(stdout, stderr, rc) = fullshell('git lint')
|
||||||
assert stderr.startswith('No configuration file found,')
|
assert stderr.startswith('No configuration file found,')
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,6 +108,7 @@ def test_03_simple_repository():
|
||||||
ret = outshell('git lint -v')
|
ret = outshell('git lint -v')
|
||||||
assert ret.index('Copyright') > 0
|
assert ret.index('Copyright') > 0
|
||||||
|
|
||||||
|
|
||||||
def test_04_linters_present():
|
def test_04_linters_present():
|
||||||
with gittemp() as path:
|
with gittemp() as path:
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
|
|
Loading…
Reference in New Issue