62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
# coding=utf-8
|
|
"""
|
|
Tasks for running various tests for Rookeries
|
|
|
|
:copyright: Copyright 2013-2017, Dorian Pula <dorian.pula@amber-penguin-software.ca>
|
|
:license: AGPL v3+
|
|
"""
|
|
|
|
import invoke as inv
|
|
|
|
|
|
@inv.task
|
|
def style(ctx):
|
|
"""
|
|
Test the coding style using Flake8.
|
|
|
|
:param ctx: Context of the invoke task.
|
|
"""
|
|
inv.run('flake8 --exclude=docs,node_modules --max-line-length=120 --max-complexity=10', echo=True, pty=True)
|
|
|
|
|
|
def _prepare_py_test_command(test_path, check_coverage_on='', verbosity=0, **extra_test_params):
|
|
verbose_flag = ''
|
|
if verbosity > 0:
|
|
verbose_flag = '-{}'.format('v' * verbosity)
|
|
|
|
if verbosity >= 3:
|
|
verbose_flag = f'{verbose_flag} -r a'
|
|
|
|
coverage_flag = ''
|
|
if check_coverage_on:
|
|
coverage_flag = f'--cov {check_coverage_on} --cov-report=term-missing --capture=no'
|
|
additional_test_params = ' '.join(
|
|
['--{}={}'.format(key.replace('_', '-'), value) for (key, value) in extra_test_params.items()])
|
|
return f'py.test {test_path} {coverage_flag} {verbose_flag} {additional_test_params}'
|
|
|
|
|
|
@inv.task
|
|
def server(ctx, server_host='rookeries:5000', verbosity=0, test_tag='', randomize=False):
|
|
"""
|
|
Test the API server using unit, and integration tests.
|
|
|
|
:param ctx: Context of the invoke task.
|
|
:param server_host: The host and port of the server to test.
|
|
:param verbosity: The amount of logging from the test. Default is 0 and is the lowest. 3 is the highest.
|
|
:param test_tag: Optional tag (pytest mark) to run individually decorated tests in suite.
|
|
:param randomize: Flag whether or not to randomize test order.
|
|
"""
|
|
|
|
test_command = _prepare_py_test_command(
|
|
'tests/server',
|
|
check_coverage_on='rookeries',
|
|
verbosity=verbosity,
|
|
server_host=server_host,
|
|
)
|
|
if test_tag:
|
|
test_command = f'{test_command} -m {test_tag}'
|
|
|
|
if randomize:
|
|
test_command = f'{test_command} --random'
|
|
inv.run(test_command, echo=True, pty=True)
|