コード例 #1
0
    def test_convert_to_str_complex_variables(self, raw_var, rendered_var):
        """Verify tree items correctly rendered."""
        env = environment.StrictEnvironment()
        context = {'project': 'foobar'}

        result = prompt.render_variable(env, raw_var, context)
        assert result == rendered_var
コード例 #2
0
    def test_should_read_userchoice(self, mocker, choices, context):
        read_choice = mocker.patch('cookiecutter.prompt.read_user_choice')
        read_choice.return_value = 'all'

        expected_choice = 'all'

        actual_choice = prompt.prompt_choice_for_config(
            context,
            environment.StrictEnvironment(),
            'orientation',
            choices,
            False  # Ask the user for input
        )
        read_choice.assert_called_once_with('orientation', choices)
        assert expected_choice == actual_choice
コード例 #3
0
    def test_should_return_first_option_if_no_input(self, mocker, choices,
                                                    context):
        read_choice = mocker.patch('cookiecutter.prompt.read_user_choice')

        expected_choice = choices[0]

        actual_choice = prompt.prompt_choice_for_config(
            context,
            environment.StrictEnvironment(),
            'orientation',
            choices,
            True  # Suppress user input
        )
        assert not read_choice.called
        assert expected_choice == actual_choice
コード例 #4
0
    def test_should_read_user_choice(self, mocker, choices, context):
        """Verify prompt_choice_for_config return user selection on no_input=False."""
        read_user_choice = mocker.patch('cookiecutter.prompt.read_user_choice')
        read_user_choice.return_value = 'all'

        expected_choice = 'all'

        actual_choice = prompt.prompt_choice_for_config(
            cookiecutter_dict=context,
            env=environment.StrictEnvironment(),
            key='orientation',
            options=choices,
            no_input=False,  # Ask the user for input
        )
        read_user_choice.assert_called_once_with('orientation', choices)
        assert expected_choice == actual_choice
コード例 #5
0
ファイル: test_prompt.py プロジェクト: stungkit/cookiecutter
    def test_should_return_first_option_if_no_input(self, mocker, choices, context):
        """Verify prompt_choice_for_config return first list option on no_input=True."""
        read_user_choice = mocker.patch('cookiecutter.prompt.read_user_choice')

        expected_choice = choices[0]

        actual_choice = prompt.prompt_choice_for_config(
            cookiecutter_dict=context,
            env=environment.StrictEnvironment(),
            key='orientation',
            options=choices,
            no_input=True,  # Suppress user input
        )

        assert not read_user_choice.called
        assert expected_choice == actual_choice
コード例 #6
0
def test_convert_to_str(mocker, raw_var, rendered_var):
    env = environment.StrictEnvironment()
    from_string = mocker.patch(
        'cookiecutter.prompt.StrictEnvironment.from_string',
        wraps=env.from_string)
    context = {'project': 'foobar'}

    result = prompt.render_variable(env, raw_var, context)
    assert result == rendered_var

    # Make sure that non None non str variables are converted beforehand
    if raw_var is not None:
        if not isinstance(raw_var, basestring):
            raw_var = str(raw_var)
        from_string.assert_called_once_with(raw_var)
    else:
        assert not from_string.called
コード例 #7
0
ファイル: test_prompt.py プロジェクト: bendhouseart/nuki-tmp
    def test_convert_to_str(self, mocker, raw_var, rendered_var):
        """Verify simple items correctly rendered to strings."""
        env = environment.StrictEnvironment()
        from_string = mocker.patch(
            'cookiecutter.prompt.StrictEnvironment.from_string',
            wraps=env.from_string)
        context = {'project': 'foobar'}

        result = cookiecutter.render.render_variable(
            env, raw_var, context, context_key='cookiecutter')
        assert result == rendered_var

        # Make sure that non None non str variables are converted beforehand
        if raw_var is not None:
            if not isinstance(raw_var, str):
                raw_var = str(raw_var)
            from_string.assert_called_once_with(raw_var)
        else:
            assert not from_string.called
コード例 #8
0
def test_find_template(repo_dir):
    env = environment.StrictEnvironment()
    template = find.find_template(repo_dir=repo_dir, env=env)

    test_dir = os.path.join(repo_dir, '{{cookiecutter.repo_name}}')
    assert template == test_dir
コード例 #9
0
def test_ensure_dir_is_templated_raises_by_env(invalid_dirname):
    env = environment.StrictEnvironment(variable_start_string='[[',
                                        variable_end_string=']]')

    with pytest.raises(exceptions.NonTemplatedInputDirException):
        generate.ensure_dir_is_templated(invalid_dirname, env)
コード例 #10
0
def test_ensure_dir_is_templated_raises(invalid_dirname):
    env = environment.StrictEnvironment()

    with pytest.raises(exceptions.NonTemplatedInputDirException):
        generate.ensure_dir_is_templated(invalid_dirname, env)