Merge branch 'feature/bonobo-init-should-work-on-an-empty-existing-directory' of git://github.com/arimbr/bonobo into arimbr-feature/bonobo-init-should-work-on-an-empty-existing-directory
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
def execute(name, branch):
|
def execute(name, branch):
|
||||||
try:
|
try:
|
||||||
from cookiecutter.main import cookiecutter
|
from cookiecutter.main import cookiecutter
|
||||||
@ -6,11 +8,17 @@ def execute(name, branch):
|
|||||||
'You must install "cookiecutter" to use this command.\n\n $ pip install cookiecutter\n'
|
'You must install "cookiecutter" to use this command.\n\n $ pip install cookiecutter\n'
|
||||||
) from exc
|
) from exc
|
||||||
|
|
||||||
|
overwrite_if_exists = False
|
||||||
|
project_path = os.path.join(os.getcwd(), name)
|
||||||
|
if os.path.isdir(project_path) and not os.listdir(project_path):
|
||||||
|
overwrite_if_exists = True
|
||||||
|
|
||||||
return cookiecutter(
|
return cookiecutter(
|
||||||
'https://github.com/python-bonobo/cookiecutter-bonobo.git',
|
'https://github.com/python-bonobo/cookiecutter-bonobo.git',
|
||||||
extra_context={'name': name},
|
extra_context={'name': name},
|
||||||
no_input=True,
|
no_input=True,
|
||||||
checkout=branch
|
checkout=branch,
|
||||||
|
overwrite_if_exists=overwrite_if_exists
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,9 +8,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(f):
|
def runner(f):
|
||||||
@ -64,6 +66,40 @@ def test_no_command(runner):
|
|||||||
assert 'error: the following arguments are required: command' in err
|
assert 'error: the following arguments are required: command' in err
|
||||||
|
|
||||||
|
|
||||||
|
@all_runners
|
||||||
|
def test_init(runner, tmpdir):
|
||||||
|
name = 'project'
|
||||||
|
tmpdir.chdir()
|
||||||
|
runner('init', name)
|
||||||
|
assert os.path.isdir(name)
|
||||||
|
assert set(os.listdir(name)) & set(DEFAULT_GRAPH_FILENAMES)
|
||||||
|
|
||||||
|
|
||||||
|
@all_runners
|
||||||
|
def test_init_in_empty_directory(runner, tmpdir):
|
||||||
|
name = 'project'
|
||||||
|
tmpdir.chdir()
|
||||||
|
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'
|
||||||
|
tmpdir.chdir()
|
||||||
|
runner('init', name)
|
||||||
|
with pytest.raises(OutputDirExistsException):
|
||||||
|
runner('init', name)
|
||||||
|
|
||||||
|
|
||||||
|
@all_runners
|
||||||
|
def test_init_within_empty_directory(runner, tmpdir):
|
||||||
|
tmpdir.chdir()
|
||||||
|
runner('init', '.')
|
||||||
|
assert set(os.listdir()) & set(DEFAULT_GRAPH_FILENAMES)
|
||||||
|
|
||||||
|
|
||||||
@all_runners
|
@all_runners
|
||||||
def test_run(runner):
|
def test_run(runner):
|
||||||
out, err = runner('run', '--quiet', get_examples_path('types/strings.py'))
|
out, err = runner('run', '--quiet', get_examples_path('types/strings.py'))
|
||||||
|
|||||||
Reference in New Issue
Block a user