Exemplo n.º 1
0
def test_should_call_prompt_with_value_proc(mocker):
    """Test to make sure that create_value_proc is actually being used
    to generate a processer for the user input."""
    prompt = mocker.patch('click.prompt')

    def process_json(user_value):
        return user_value

    create_value_proc = mocker.patch(
        'cookiecutter.prompt.create_value_proc',
        return_value=process_json,
    )

    read_user_dict('name', {'project_slug': 'pytest-plugin'})

    assert create_value_proc.call_args == mocker.call(
        'default',
        {'project_slug': 'pytest-plugin'},
    )
    assert prompt.call_args == mocker.call(
        'name',
        type=click.STRING,
        default='default',
        value_proc=process_json,
    )
Exemplo n.º 2
0
def test_should_raise_type_error(mocker):
    prompt = mocker.patch('click.prompt')

    with pytest.raises(TypeError):
        read_user_dict('name', 'russell')

    assert not prompt.called
def test_should_raise_type_error(mocker):
    prompt = mocker.patch("click.prompt")

    with pytest.raises(TypeError):
        read_user_dict("name", "russell")

    assert not prompt.called
Exemplo n.º 4
0
def test_should_raise_type_error(mocker):
    prompt = mocker.patch('click.prompt')

    with pytest.raises(TypeError):
        read_user_dict('name', 'russell')

    assert not prompt.called
Exemplo n.º 5
0
def test_should_call_prompt_with_value_proc(mocker):
    """Test to make sure that create_value_proc is actually being used
    to generate a processer for the user input."""
    prompt = mocker.patch('click.prompt')

    def process_json(user_value):
        return user_value

    create_value_proc = mocker.patch(
        'cookiecutter.prompt.create_value_proc',
        return_value=process_json,
    )

    read_user_dict('name', {'project_slug': 'pytest-plugin'})

    assert create_value_proc.call_args == mocker.call(
        'default',
        {'project_slug': 'pytest-plugin'},
    )
    assert prompt.call_args == mocker.call(
        'name',
        type=click.STRING,
        default='default',
        value_proc=process_json,
    )
Exemplo n.º 6
0
def test_should_raise_type_error(mocker):
    """Test `default_value` arg verification in `read_user_dict` function."""
    prompt = mocker.patch('cookiecutter.prompt.click.prompt')

    with pytest.raises(TypeError):
        read_user_dict('name', 'russell')

    assert not prompt.called
Exemplo n.º 7
0
def test_should_not_call_process_json_default_value(mocker, monkeypatch):
    """Make sure that `process_json` is not called when using default value."""
    mock_process_json = mocker.patch('cookiecutter.prompt.process_json',
                                     autospec=True)

    runner = click.testing.CliRunner()
    with runner.isolation(input="\n"):
        read_user_dict('name', {'project_slug': 'pytest-plugin'})

    mock_process_json.assert_not_called()
Exemplo n.º 8
0
def test_should_not_load_json_from_sentinel(mocker):
    """Make sure that `json.loads` is not called when using default value."""
    mock_json_loads = mocker.patch('cookiecutter.prompt.json.loads',
                                   autospec=True,
                                   return_value={})

    runner = click.testing.CliRunner()
    with runner.isolation(input="\n"):
        read_user_dict('name', {'project_slug': 'pytest-plugin'})

    mock_json_loads.assert_not_called()
Exemplo n.º 9
0
def test_should_call_prompt_with_process_json(mocker):
    """Test to make sure that `process_json` is actually being used.

    Verifies generation of a processor for the user input.
    """
    mock_prompt = mocker.patch('cookiecutter.prompt.click.prompt', autospec=True)

    read_user_dict('name', {'project_slug': 'pytest-plugin'})

    assert mock_prompt.call_args == mocker.call(
        'name', type=click.STRING, default='default', value_proc=process_json,
    )
Exemplo n.º 10
0
def test_should_call_prompt_with_process_json(mocker):
    """Test to make sure that process_jon is actually being used
    to generate a processer for the user input."""

    mock_prompt = mocker.patch(
        'cookiecutter.prompt.click.prompt',
        autospec=True,
    )

    read_user_dict('name', {'project_slug': 'pytest-plugin'})

    assert mock_prompt.call_args == mocker.call(
        'name',
        type=click.STRING,
        default='default',
        value_proc=process_json,
    )
def test_should_call_prompt_with_process_json(mocker):
    """Test to make sure that process_jon is actually being used

    Verifies generation of a processor for the user input.
    """
    mock_prompt = mocker.patch(
        "cookiecutter.prompt.click.prompt",
        autospec=True,
    )

    read_user_dict("name", {"project_slug": "pytest-plugin"})

    assert mock_prompt.call_args == mocker.call(
        "name",
        type=click.STRING,
        default="default",
        value_proc=process_json,
    )
Exemplo n.º 12
0
def test_read_user_dict_default_value(mocker, input):
    """Make sure that `read_user_dict` returns the default value.

    Verify return of a dict variable rather than the display value.
    """
    runner = click.testing.CliRunner()
    with runner.isolation(input=input):
        val = read_user_dict('name', {'project_slug': 'pytest-plugin'})

    assert val == {'project_slug': 'pytest-plugin'}
Exemplo n.º 13
0
def test_shallow_dict(mocker):
    prompt = mocker.patch('click.prompt')
    prompt.return_value = '{"key": 2}'

    VARIABLE = 'var'
    DEFAULT = {}

    assert read_user_dict(VARIABLE, DEFAULT) == {'key': 2}

    click.prompt.assert_called_once_with(VARIABLE, default='default')
Exemplo n.º 14
0
def test_use_empty_default_dict(mocker):
    prompt = mocker.patch('click.prompt')
    prompt.return_value = 'default'

    VARIABLE = 'var'
    DEFAULT = {}

    assert read_user_dict(VARIABLE, DEFAULT) == {}

    click.prompt.assert_called_once_with(VARIABLE, default='default')
Exemplo n.º 15
0
def test_read_user_dict_default_value(mocker):
    """Make sure that `read_user_dict` returns the default value.

    Verify return of a dict variable rather than the display value.
    """
    mock_prompt = mocker.patch(
        'cookiecutter.prompt.click.prompt', autospec=True, return_value='default',
    )

    val = read_user_dict('name', {'project_slug': 'pytest-plugin'})

    assert mock_prompt.call_args == mocker.call(
        'name', type=click.STRING, default='default', value_proc=process_json,
    )

    assert val == {'project_slug': 'pytest-plugin'}
Exemplo n.º 16
0
def test_deep_dict(mocker):
    prompt = mocker.patch('click.prompt')
    prompt.return_value = '''{
        "key": "value",
        "integer_key": 37,
        "dict_key": {
            "deep_key": "deep_value",
            "deep_integer": 42,
            "deep_list": [
                "deep value 1",
                "deep value 2",
                "deep value 3"
            ]
        },
        "list_key": [
            "value 1",
            "value 2",
            "value 3"
        ]
    }'''

    VARIABLE = 'var'
    DEFAULT = {}

    assert read_user_dict(VARIABLE, DEFAULT) == {
        "key": "value",
        "integer_key": 37,
        "dict_key": {
            "deep_key": "deep_value",
            "deep_integer": 42,
            "deep_list": [
                "deep value 1",
                "deep value 2",
                "deep value 3",
            ]
        },
        "list_key": [
            "value 1",
            "value 2",
            "value 3",
        ]
    }

    click.prompt.assert_called_once_with(VARIABLE, default='default')
Exemplo n.º 17
0
def test_read_user_dict_default_value(mocker):
    """Test to make sure that read_user_dict returns the default value for a
    dict variable rather than the display value.
    """
    mock_prompt = mocker.patch(
        'cookiecutter.prompt.click.prompt',
        autospec=True,
        return_value='default',
    )

    val = read_user_dict('name', {'project_slug': 'pytest-plugin'})

    assert mock_prompt.call_args == mocker.call(
        'name',
        type=click.STRING,
        default='default',
        value_proc=process_json,
    )

    assert val == {'project_slug': 'pytest-plugin'}
def test_read_user_dict_default_value(mocker):
    """Make sure that read_user_dict returns the default value

    Verify return of a dict variable rather than the display value.
    """
    mock_prompt = mocker.patch(
        "cookiecutter.prompt.click.prompt",
        autospec=True,
        return_value="default",
    )

    val = read_user_dict("name", {"project_slug": "pytest-plugin"})

    assert mock_prompt.call_args == mocker.call(
        "name",
        type=click.STRING,
        default="default",
        value_proc=process_json,
    )

    assert val == {"project_slug": "pytest-plugin"}
Exemplo n.º 19
0
def test_raise_if_value_not_valid_json(mocker):
    prompt = mocker.patch('click.prompt')
    prompt.return_value = '{'

    with pytest.raises(ValueError):
        read_user_dict('foo', {})
Exemplo n.º 20
0
def test_raise_if_value_is_not_dict():
    with pytest.raises(TypeError):
        read_user_dict('foo', 'NOT A LIST')