2014-12-18 23:12:14 +00:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
REPO_ROOT = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
TESTS_DIR = os.path.join(REPO_ROOT, 'tests')
|
|
|
|
|
|
|
|
|
|
|
|
def get_untracked_files():
|
|
|
|
output = subprocess.check_output(
|
|
|
|
['git', 'ls-files', '--other', '--directory', '--exclude-standard',
|
|
|
|
'-z'],
|
|
|
|
cwd=REPO_ROOT)
|
|
|
|
return set(f for f in output.split(b'\0') if f)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
# Unset any PERU environment variables to make sure test runs don't get
|
|
|
|
# thrown off by anything in your bashrc.
|
|
|
|
for var in os.environ:
|
|
|
|
if var.startswith('PERU_'):
|
|
|
|
del os.environ[var]
|
|
|
|
|
|
|
|
# Turn debugging features on for the asyncio library.
|
|
|
|
os.environ['PYTHONASYNCIODEBUG'] = '1'
|
|
|
|
|
|
|
|
# Make sure the tests don't create any garbage files in the repo. That
|
|
|
|
# tends to happen when we accidentally run something in the current dir
|
|
|
|
# that should be in a temp dir, and it's hard to track down when it does.
|
|
|
|
old_untracked = get_untracked_files()
|
|
|
|
|
|
|
|
# Run the actual tests.
|
|
|
|
env = os.environ.copy()
|
2014-12-21 05:06:36 +00:00
|
|
|
env['PYTHONPATH'] = REPO_ROOT
|
2014-12-18 23:12:14 +00:00
|
|
|
args = sys.argv[1:]
|
2015-01-27 00:20:08 +00:00
|
|
|
if len(args) > 0 and '--with-coverage' in args:
|
|
|
|
args.remove('--with-coverage')
|
2014-12-18 23:12:14 +00:00
|
|
|
command_start = ['coverage', 'run']
|
|
|
|
else:
|
2015-04-26 02:35:22 +00:00
|
|
|
command_start = [sys.executable, '-W', 'all']
|
2014-12-18 23:12:14 +00:00
|
|
|
command = command_start + ['-m', 'unittest'] + args
|
|
|
|
try:
|
|
|
|
subprocess.check_call(command, env=env, cwd=TESTS_DIR)
|
2015-05-06 17:43:40 +00:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print('ERROR: unit tests returned an error code', file=sys.stderr)
|
2014-12-18 23:12:14 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
new_untracked = get_untracked_files()
|
|
|
|
if old_untracked != new_untracked:
|
|
|
|
print('Tests created untracked files:\n' +
|
|
|
|
'\n'.join(f.decode() for f in new_untracked - old_untracked),
|
|
|
|
file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Run the linter.
|
|
|
|
try:
|
|
|
|
subprocess.check_call(['flake8', 'peru', 'tests'], cwd=REPO_ROOT)
|
2015-05-06 17:43:40 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
print('ERROR: flake8 not found', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print('ERROR: flake8 returned an error code', file=sys.stderr)
|
2014-12-18 23:12:14 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|