[tests] trying to speed up the init test.
This commit is contained in:
@ -17,11 +17,15 @@ from bonobo.commands.run import DEFAULT_GRAPH_FILENAMES
|
|||||||
|
|
||||||
def runner(f):
|
def runner(f):
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
def wrapped_runner(*args):
|
def wrapped_runner(*args, catch_errors=False):
|
||||||
with redirect_stdout(io.StringIO()) as stdout, redirect_stderr(io.StringIO()) as stderr:
|
with redirect_stdout(io.StringIO()) as stdout, redirect_stderr(io.StringIO()) as stderr:
|
||||||
try:
|
try:
|
||||||
f(list(args))
|
f(list(args))
|
||||||
except BaseException as exc:
|
except BaseException as exc:
|
||||||
|
if not catch_errors:
|
||||||
|
raise
|
||||||
|
elif isinstance(catch_errors, BaseException) and not isinstance(exc, catch_errors):
|
||||||
|
raise
|
||||||
return stdout.getvalue(), stderr.getvalue(), exc
|
return stdout.getvalue(), stderr.getvalue(), exc
|
||||||
return stdout.getvalue(), stderr.getvalue()
|
return stdout.getvalue(), stderr.getvalue()
|
||||||
|
|
||||||
@ -42,6 +46,7 @@ def runner_module(args):
|
|||||||
|
|
||||||
|
|
||||||
all_runners = pytest.mark.parametrize('runner', [runner_entrypoint, runner_module])
|
all_runners = pytest.mark.parametrize('runner', [runner_entrypoint, runner_module])
|
||||||
|
single_runner = pytest.mark.parametrize('runner', [runner_module])
|
||||||
|
|
||||||
|
|
||||||
def test_entrypoint():
|
def test_entrypoint():
|
||||||
@ -61,7 +66,7 @@ def test_entrypoint():
|
|||||||
|
|
||||||
@all_runners
|
@all_runners
|
||||||
def test_no_command(runner):
|
def test_no_command(runner):
|
||||||
_, err, exc = runner()
|
_, err, exc = runner(catch_errors=True)
|
||||||
assert type(exc) == SystemExit
|
assert type(exc) == SystemExit
|
||||||
assert 'error: the following arguments are required: command' in err
|
assert 'error: the following arguments are required: command' in err
|
||||||
|
|
||||||
@ -74,26 +79,22 @@ def test_init(runner, tmpdir):
|
|||||||
assert os.path.isdir(name)
|
assert os.path.isdir(name)
|
||||||
assert set(os.listdir(name)) & set(DEFAULT_GRAPH_FILENAMES)
|
assert set(os.listdir(name)) & set(DEFAULT_GRAPH_FILENAMES)
|
||||||
|
|
||||||
|
@single_runner
|
||||||
@all_runners
|
def test_init_in_empty_then_nonempty_directory(runner, tmpdir):
|
||||||
def test_init_in_empty_directory(runner, tmpdir):
|
|
||||||
name = 'project'
|
name = 'project'
|
||||||
tmpdir.chdir()
|
tmpdir.chdir()
|
||||||
os.mkdir(name)
|
os.mkdir(name)
|
||||||
|
|
||||||
|
# run in empty dir
|
||||||
runner('init', name)
|
runner('init', name)
|
||||||
assert set(os.listdir(name)) & set(DEFAULT_GRAPH_FILENAMES)
|
assert set(os.listdir(name)) & set(DEFAULT_GRAPH_FILENAMES)
|
||||||
|
|
||||||
|
# run in non empty dir
|
||||||
@all_runners
|
|
||||||
def test_init_in_non_empty_directory(runner, tmpdir):
|
|
||||||
name = 'project'
|
|
||||||
tmpdir.chdir()
|
|
||||||
runner('init', name)
|
|
||||||
with pytest.raises(OutputDirExistsException):
|
with pytest.raises(OutputDirExistsException):
|
||||||
runner('init', name)
|
runner('init', name)
|
||||||
|
|
||||||
|
|
||||||
@all_runners
|
@single_runner
|
||||||
def test_init_within_empty_directory(runner, tmpdir):
|
def test_init_within_empty_directory(runner, tmpdir):
|
||||||
tmpdir.chdir()
|
tmpdir.chdir()
|
||||||
runner('init', '.')
|
runner('init', '.')
|
||||||
|
|||||||
Reference in New Issue
Block a user