Use pytest tmpdir fixture and add more init tests
This commit is contained in:
@ -6,9 +6,11 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import pytest
|
import pytest
|
||||||
|
from cookiecutter.exceptions import OutputDirExistsException
|
||||||
|
|
||||||
from bonobo import __main__, __version__, get_examples_path
|
from bonobo import __main__, __version__, get_examples_path
|
||||||
from bonobo.commands import entrypoint
|
from bonobo.commands import entrypoint
|
||||||
|
from bonobo.commands.run import DEFAULT_GRAPH_FILENAMES
|
||||||
|
|
||||||
|
|
||||||
def runner_entrypoint(*args):
|
def runner_entrypoint(*args):
|
||||||
@ -45,24 +47,37 @@ def test_no_command(runner, capsys):
|
|||||||
|
|
||||||
|
|
||||||
@all_runners
|
@all_runners
|
||||||
def test_init(runner, capsys):
|
def test_init(runner, tmpdir):
|
||||||
runner('init', 'project-name')
|
name = 'project'
|
||||||
out, err = capsys.readouterr()
|
os.chdir(tmpdir)
|
||||||
out = out.strip()
|
runner('init', name)
|
||||||
shutil.rmtree('project-name')
|
assert os.path.isdir(name)
|
||||||
assert out == ''
|
assert set(os.listdir(name)) & set(DEFAULT_GRAPH_FILENAMES)
|
||||||
|
|
||||||
|
|
||||||
@all_runners
|
@all_runners
|
||||||
def test_init_within_empty_directory(runner, capsys):
|
def test_init_in_empty_directory(runner, tmpdir):
|
||||||
os.mkdir('empty-directory')
|
name = 'project'
|
||||||
os.chdir('empty-directory')
|
os.chdir(tmpdir)
|
||||||
|
os.mkdir(name)
|
||||||
|
runner('init', name)
|
||||||
|
assert set(os.listdir(name)) & set(DEFAULT_GRAPH_FILENAMES)
|
||||||
|
|
||||||
|
|
||||||
|
@all_runners
|
||||||
|
def test_init_in_non_empty_directory(runner, tmpdir):
|
||||||
|
name = 'project'
|
||||||
|
os.chdir(tmpdir)
|
||||||
|
runner('init', name)
|
||||||
|
with pytest.raises(OutputDirExistsException):
|
||||||
|
runner('init', name)
|
||||||
|
|
||||||
|
|
||||||
|
@all_runners
|
||||||
|
def test_init_within_empty_directory(runner, tmpdir):
|
||||||
|
os.chdir(tmpdir)
|
||||||
runner('init', '.')
|
runner('init', '.')
|
||||||
out, err = capsys.readouterr()
|
assert set(os.listdir()) & set(DEFAULT_GRAPH_FILENAMES)
|
||||||
out = out.strip()
|
|
||||||
os.chdir('..')
|
|
||||||
shutil.rmtree('empty-directory')
|
|
||||||
assert out == ''
|
|
||||||
|
|
||||||
|
|
||||||
@all_runners
|
@all_runners
|
||||||
|
|||||||
Reference in New Issue
Block a user