How to use the cookiecutter.exceptions function in cookiecutter

To help you get started, we’ve selected a few cookiecutter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cookiecutter / cookiecutter / tests / test_exceptions.py View on Github external
def test_undefined_variable_to_str():
    undefined_var_error = exceptions.UndefinedVariableInTemplate(
        'Beautiful is better than ugly',
        UndefinedError('Errors should never pass silently'),
        {'cookiecutter': {'foo': 'bar'}}
    )

    expected_str = (
        "Beautiful is better than ugly. "
        "Error message: Errors should never pass silently. "
        "Context: {'cookiecutter': {'foo': 'bar'}}"
    )

    assert str(undefined_var_error) == expected_str
github cookiecutter / cookiecutter / tests / test_cleanup.py View on Github external
def test_remove_repo_bad(self):
        self.assertRaises(
            exceptions.MissingProjectDir,
            cleanup.remove_repo,
            repo_dir='tests/fake-repo-bad',
            generated_project='fake-project'
        )
github cookiecutter / cookiecutter / tests / vcs / test_identify_repo.py View on Github external
def test_identify_raise_on_unknown_repo(unknown_repo_type_url):
    with pytest.raises(exceptions.UnknownRepoType):
        vcs.identify_repo(unknown_repo_type_url)
github cookiecutter / cookiecutter / tests / test_output_folder.py View on Github external
def test_exception_when_output_folder_exists():
    context = generate.generate_context(
        context_file='tests/test-output-folder/cookiecutter.json'
    )
    output_folder = context['cookiecutter']['test_name']

    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
    with pytest.raises(exceptions.OutputDirExistsException):
        generate.generate_files(
            context=context,
            repo_dir='tests/test-output-folder'
        )
github cookiecutter / cookiecutter / tests / vcs / test_clone.py View on Github external
def test_clone_should_raise_if_vcs_not_installed(mocker, clone_dir):
    """In `clone()`, a `VCSNotInstalled` exception should be raised if no VCS
    is installed.
    """
    mocker.patch(
        'cookiecutter.vcs.is_vcs_installed',
        autospec=True,
        return_value=False
    )

    repo_url = 'https://github.com/pytest-dev/cookiecutter-pytest-plugin.git'

    with pytest.raises(exceptions.VCSNotInstalled):
        vcs.clone(repo_url, clone_to_dir=clone_dir)
github beeware / briefcase / tests / commands / create / test_generate_app_template.py View on Github external
def test_invalid_repo_template(create_command, myapp):
    "If the provided template URL isn't valid, an error is raised"
    myapp.template = 'https://example.com/somewhere/not-a-repo.git'

    # There won't be a cookiecutter cache, so there won't be
    # a repo path (yet).
    create_command.git.Repo.side_effect = git_exceptions.NoSuchPathError

    # Calling cookiecutter on a URL that isn't a valid repository causes an error
    create_command.cookiecutter.side_effect = cookiecutter_exceptions.RepositoryNotFound

    # Generating the template under there conditions raises an error
    with pytest.raises(InvalidTemplateRepository):
        create_command.generate_app_template(myapp)

    # App's template is unchanged
    assert myapp.template == 'https://example.com/somewhere/not-a-repo.git'

    # Cookiecutter was invoked with the expected template name and context.
    create_command.cookiecutter.assert_called_once_with(
        'https://example.com/somewhere/not-a-repo.git',
        no_input=True,
        checkout=create_command.python_version_tag,
        output_dir=str(create_command.platform_path),
        extra_context=full_context({
            'template': 'https://example.com/somewhere/not-a-repo.git',
github cookiecutter / cookiecutter / tests / test_prompt.py View on Github external
def test_undefined_variable_in_cookiecutter_dict():
    context = {
        'cookiecutter': {
            'hello': 'world',
            'foo': '{{cookiecutter.nope}}'
        }
    }
    with pytest.raises(exceptions.UndefinedVariableInTemplate) as err:
        prompt.prompt_for_config(context, no_input=True)

    error = err.value
    assert error.message == "Unable to render variable 'foo'"
    assert error.context == context