Exemple #1
0
def test_query_user_raise_keyboard_interrupt(monkeypatch):
    monkeypatch.setattr(
        'builtins.input',
        lambda description: (_ for _ in ()).throw(KeyboardInterrupt),
    )
    with pytest.raises(KeyboardInterrupt):
        GetParams.query_user(d=DEFAULTS_DICT_GENERIC, )
Exemple #2
0
def test_query_user_defaults_dict_corrupt(monkeypatch):
    monkeypatch.setattr(
        'builtins.input',
        lambda description: USER_INPUT_GENERIC,
    )
    with pytest.raises(TypeError):
        GetParams.query_user(d=DEFAULTS_DICT_CORRUPT, )
Exemple #3
0
def test_query_user_no_args(monkeypatch):
    monkeypatch.setattr(
        'builtins.input',
        lambda description: USER_INPUT_GENERIC,
    )
    with pytest.raises(TypeError):
        GetParams.query_user()
Exemple #4
0
def test_query_user_defaults_dict_choices_multi_wrong_input(monkeypatch):
    monkeypatch.setattr(
        'builtins.input',
        lambda description: USER_INPUT_CHOICES_INVALID,
    )
    with pytest.raises(ValueError):
        GetParams.query_user(
            d=DEFAULTS_DICT_CHOICES_MULTI,
            retries=RETRIES,
        ) == USER_INPUT_CHOICES
Exemple #5
0
def test_get_params_no_user(monkeypatch):
    monkeypatch.setattr(
        'builtins.input',
        lambda description: USER_INPUT_GENERIC,
    )
    p = GetParams(
        defaults=DEFAULTS,
        params=PARAMS,
    )
    del p.params['user']
    assert p.get_params(retries=1) is None
Exemple #6
0
def test_get_params_popen_exception(monkeypatch):
    monkeypatch.setattr(
        'builtins.input',
        lambda description: USER_INPUT_GENERIC,
    )
    monkeypatch.setattr(
        'os.popen',
        lambda description: (_ for _ in ()).throw(Exception),
    )
    p = GetParams(
        defaults=DEFAULTS,
        params=PARAMS,
    )
    del p.params['user']
    assert p.get_params(retries=1) is None
Exemple #7
0
def test_query_user_defaults_dict_generic_no_input(monkeypatch):
    monkeypatch.setattr(
        'builtins.input',
        lambda description: "",
    )
    assert GetParams.query_user(
        d=DEFAULTS_DICT_GENERIC, ) == DEFAULTS_DICT_GENERIC['value']
Exemple #8
0
def test_query_user_defaults_dict_generic(monkeypatch):
    monkeypatch.setattr(
        'builtins.input',
        lambda description: USER_INPUT_GENERIC,
    )
    assert GetParams.query_user(
        d=DEFAULTS_DICT_GENERIC, ) == USER_INPUT_GENERIC
Exemple #9
0
def test_query_user_defaults_dict_choices_no_alt(monkeypatch):
    monkeypatch.setattr(
        'builtins.input',
        lambda description: USER_INPUT_CHOICES,
    )
    assert GetParams.query_user(
        d=DEFAULTS_DICT_CHOICES_NO_ALT) == USER_INPUT_CHOICES
Exemple #10
0
def test_slugify_keep_uppercase():
    assert GetParams.slugify(
        s=UNSANITIZED,
        allowed_start=ascii_uppercase + ascii_lowercase,
        allowed_end=ascii_uppercase + ascii_lowercase + digits,
        allowed_rest=ascii_uppercase + ascii_lowercase + digits + "_",
        lower=False,
    ) == SLUG_KEEP_UPPERCASE
Exemple #11
0
def test_init_args_all_params():
    p = GetParams(
        defaults=DEFAULTS,
        params=PARAMS,
    )
    assert p.params == PARAMS
Exemple #12
0
def test_split_choices_multi_items_multi_sep():
    assert GetParams.split_choices(
        s=CHOICES_MULTI,
        sep=SEP_MULTI,
    ) == CHOICES_MULTI_SPLIT_MULTI_SEP
Exemple #13
0
def test_init_no_args():
    with pytest.raises(TypeError):
        GetParams()
Exemple #14
0
def test_split_choices_wrong_type_sep_2():
    with pytest.raises(TypeError):
        GetParams.split_choices(
            s=UNSANITIZED,
            sep=LIST,
        )
Exemple #15
0
def test_split_choices_one_item():
    assert GetParams.split_choices(s=CHOICES, ) == CHOICES_SPLIT
Exemple #16
0
def test_slugify_wrong_type_s():
    with pytest.raises(TypeError):
        GetParams.slugify(s=LIST, )
Exemple #17
0
def test_split_choices_wrong_type_s():
    with pytest.raises(TypeError):
        GetParams.split_choices(s=LIST, )
Exemple #18
0
def test_slugify_no_args():
    with pytest.raises(TypeError):
        GetParams.slugify()
Exemple #19
0
def test_slugify_no_chars_allowed_at_end():
    assert GetParams.slugify(
        s=UNSANITIZED,
        allowed_end="",
    ) == ""
Exemple #20
0
def test_slugify_no_whitespace():
    assert GetParams.slugify(
        s=UNSANITIZED,
        whitespace_replace="",
    ) == SLUG_WHITESPACE_REMOVED
Exemple #21
0
def test_slugify_remove_uppercase():
    assert GetParams.slugify(
        s=UNSANITIZED,
        lower=False,
    ) == SLUG_UPPERCASE_REMOVED
Exemple #22
0
def test_query_user_wrong_type_d():
    with pytest.raises(TypeError):
        GetParams.query_user(d=LIST, )
Exemple #23
0
def test_slugify_wrong_type_lower():
    with pytest.raises(TypeError):
        GetParams.slugify(
            s=UNSANITIZED,
            lower=LIST,
        )
Exemple #24
0
def test_slugify_wrong_type_allowed_rest():
    with pytest.raises(TypeError):
        GetParams.slugify(
            s=UNSANITIZED,
            allowed_rest=LIST,
        )
Exemple #25
0
def test_query_user_wrong_type_retries():
    with pytest.raises(TypeError):
        GetParams.query_user(
            d=DEFAULTS_DICT_CORRUPT,
            retries=LIST,
        )
Exemple #26
0
def test_split_choices_no_args():
    with pytest.raises(TypeError):
        GetParams.split_choices()
Exemple #27
0
def test_slugify_wrong_type_whitespace_replace():
    with pytest.raises(TypeError):
        GetParams.slugify(
            s=UNSANITIZED,
            whitespace_replace=LIST,
        )
Exemple #28
0
def test_slugify_okay():
    assert GetParams.slugify(s=UNSANITIZED, ) == SLUG_DEFAULT