diff --git a/manati/create.py b/manati/create.py index 67e01a4..bdadc0b 100644 --- a/manati/create.py +++ b/manati/create.py @@ -32,7 +32,7 @@ def create_project(name, no_git, no_install, author, description, license): path = pathlib.Path.cwd() / name if os.path.exists(path): - raise Exception('ERROR: Path already exists.') + raise click.BadParameter('ERROR: Path already exists.') templates = pathlib.Path(__file__).parent / 'templates' subs = { diff --git a/manati/manati.py b/manati/manati.py index 9fae3b4..38bcb13 100644 --- a/manati/manati.py +++ b/manati/manati.py @@ -47,10 +47,8 @@ def create_project_command(name, no_git, no_install, author, description, licens By default, the project is also pip-installed for development in editable mode, and a local git repository is also created. """ - try: - create_project(name, no_git, no_install, author, description, license) - except Exception as e: - click.echo(e) + + create_project(name, no_git, no_install, author, description, license) @cli.group('deploy') diff --git a/tests/test_create.py b/tests/test_create.py index 1494cbd..0042921 100644 --- a/tests/test_create.py +++ b/tests/test_create.py @@ -1,4 +1,5 @@ import unittest +import os from os.path import exists import pathlib @@ -24,3 +25,10 @@ def test_create_project(self): assert exists(path / 'docs' / 'conf.py') assert exists(path / 'docs' / '_build' / 'html' / 'index.html') + def test_create_project_do_not_overwrite(self): + runner = CliRunner() + with runner.isolated_filesystem(): + os.mkdir('tee') + with self.assertRaises(Exception): + result = runner.invoke(cli, ['create', '-n' , 'tee'], input='\n\n\n') + diff --git a/tests/test_run.py b/tests/test_run.py index 671466a..329d148 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -50,3 +50,21 @@ def test_run_docs(self, mock_launch): result = runner.invoke(cli, ['run', 'docs']) assert result.exit_code == 0 assert os.path.exists(Path.cwd() / 'docs' / '_build' / 'html' / 'index.html') + + @unittest.mock.patch('manati.manati.find_project_data') + def test_run_flake8_guess(self, mock_fpd): + runner = CliRunner() + mock_fpd.return_value = {'package': 'test_project'} + with runner.isolated_filesystem(): + create_project_structure('test_project', Path('test_project'), {'PROJECT_NAME': 'test_project', + 'MODULE_NAME': 'test_project'}) + result = runner.invoke(cli, ['run', 'flake8'], input='\n') + assert result.exit_code == 0 + + def test_run_flake8(self): + runner = CliRunner() + with runner.isolated_filesystem(): + create_project_structure('test_project', Path('test_project'), {'PROJECT_NAME': 'test_project', + 'MODULE_NAME': 'test_project'}) + result = runner.invoke(cli, ['run', 'flake8', 'test_project']) + assert result.exit_code == 0 diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..6929e7c --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,35 @@ +import unittest +import unittest.mock +from pathlib import Path +import shutil +import os +import subprocess + +from click.testing import CliRunner + +from manati.utils import find_project_data, task + + +class TestUtils(unittest.TestCase): + + @unittest.mock.patch('manati.utils.shell') + @unittest.mock.patch('manati.utils.os.environ.get') + def test_find_project_data_author_from_env(self, mock_env, mock_shell): + mock_shell.return_value = subprocess.run('blabla1234', shell=True) + + runner = CliRunner() + with runner.isolated_filesystem(): + mock_env.return_value = 'test_user' + info = find_project_data() + assert info.get('author') == 'test_user' + + @unittest.mock.patch('manati.utils.click.secho') + def test_task(self, mock_secho): + + @task('Before', 'After') + def func(): + raise Exception + + with self.assertRaises(Exception): + func() + mock_secho.assert_called_with('ERROR')