示例#1
0
def test_construct_arguments_completes_kwargs_from_options():
    s = Signature(bariza)
    args, kwargs = s.construct_arguments([2, 4], {}, {'c': 6})
    assert args == [2, 4]
    assert kwargs == {'c': 6}
    s = Signature(complex_function_name)
    args, kwargs = s.construct_arguments([], {'c': 6, 'b': 7}, {'a': 1})
    assert args == []
    assert kwargs == {'a': 1, 'c': 6, 'b': 7}
示例#2
0
def test_get_free_parameters():
    free = Signature(foo).get_free_parameters([], {})
    assert free == []
    free = Signature(bariza).get_free_parameters([], {'c': 3})
    assert free == ['a', 'b']
    free = Signature(complex_function_name).get_free_parameters([], {})
    assert free == ['a', 'b', 'c']
    free = Signature(_name_with_underscore_).get_free_parameters([], {})
    assert free == ['fo', 'bar']
    s = Signature(__double_underscore__)
    assert s.get_free_parameters([1, 2, 3], {}) == []
示例#3
0
def test_construct_arguments_without_duplicates_passes():
    s = Signature(bariza)
    s.construct_arguments([1, 2], {'c': 5}, {})

    s = Signature(complex_function_name)
    s.construct_arguments([1], {'b': 4}, {})

    s = Signature(FunCTIonWithCAPItals)
    s.construct_arguments([], {'a': 6, 'b': 6, 'c': 6}, {})
示例#4
0
def test_construct_arguments_with_duplicate_args_raises_typeerror():
    multiple_values = re.compile(".*multiple values.*")
    with pytest.raises(TypeError) as excinfo:
        s = Signature(bariza)
        s.construct_arguments([1, 2, 3], {'a': 4, 'b': 5}, {})
    assert multiple_values.match(excinfo.value.args[0])
    with pytest.raises(TypeError) as excinfo:
        s = Signature(complex_function_name)
        s.construct_arguments([1], {'a': 4}, {})
    assert multiple_values.match(excinfo.value.args[0])
    with pytest.raises(TypeError) as excinfo:
        s = Signature(FunCTIonWithCAPItals)
        s.construct_arguments([1, 2, 3], {'c': 6}, {})
    assert multiple_values.match(excinfo.value.args[0])
示例#5
0
def test_construct_arguments_raises_if_args_unfilled():
    s = Signature(bariza)
    missing = re.compile(".*missing.*")
    with pytest.raises(MissingConfigError) as excinfo:
        s.construct_arguments([], {}, {})
    assert missing.match(excinfo.value.args[0])
    with pytest.raises(MissingConfigError) as excinfo:
        s.construct_arguments([1, 2], {}, {})
    assert missing.match(excinfo.value.args[0])
    with pytest.raises(MissingConfigError) as excinfo:
        s.construct_arguments([1], {'b': 3}, {})
    assert missing.match(excinfo.value.args[0])
    with pytest.raises(MissingConfigError) as excinfo:
        s.construct_arguments([1], {'c': 5}, {})
    assert missing.match(excinfo.value.args[0])
示例#6
0
def test_construct_arguments_without_options_returns_same_args_kwargs():
    s = Signature(foo)
    args, kwargs = s.construct_arguments([], {}, {})
    assert args == []
    assert kwargs == {}

    s = Signature(bariza)
    args, kwargs = s.construct_arguments([2, 4, 6], {}, {})
    assert args == [2, 4, 6]
    assert kwargs == {}

    s = Signature(complex_function_name)
    args, kwargs = s.construct_arguments([2], {'c': 6, 'b': 7}, {})
    assert args == [2]
    assert kwargs == {'c': 6, 'b': 7}

    s = Signature(_name_with_underscore_)
    args, kwargs = s.construct_arguments([], {'fo': 7, 'bar': 6}, {})
    assert args == []
    assert kwargs == {'fo': 7, 'bar': 6}
示例#7
0
def test_construct_arguments_does_not_overwrite_args_and_kwargs():
    s = Signature(bariza)
    args, kwargs = s.construct_arguments([1, 2], {'c': 3},
                                         {'a': 6, 'b': 6, 'c': 6})
    assert args == [1, 2]
    assert kwargs == {'c': 3}
示例#8
0
def test_construct_arguments_with_duplicate_args_raises_typeerror():
    multiple_values = re.compile(".*multiple values.*")
    with pytest.raises(TypeError) as excinfo:
        s = Signature(bariza)
        s.construct_arguments([1, 2, 3], {'a': 4, 'b': 5}, {})
    assert multiple_values.match(excinfo.value.args[0])
    with pytest.raises(TypeError) as excinfo:
        s = Signature(complex_function_name)
        s.construct_arguments([1], {'a': 4}, {})
    assert multiple_values.match(excinfo.value.args[0])
    with pytest.raises(TypeError) as excinfo:
        s = Signature(FunCTIonWithCAPItals)
        s.construct_arguments([1, 2, 3], {'c': 6}, {})
    assert multiple_values.match(excinfo.value.args[0])
示例#9
0
def test_construct_arguments_with_expected_kwargs_does_not_raise():
    s = Signature(complex_function_name)
    s.construct_arguments([], {'a': 4, 'b': 3, 'c': 2}, {})
    s = Signature(FunCTIonWithCAPItals)
    s.construct_arguments([1, 2], {'c': 5}, {})
示例#10
0
def test_constructor_extract_positional_arguments(function, pos_args):
    s = Signature(function)
    assert s.positional_args == pos_args
示例#11
0
def test_constructor_extract_vararg_name(function, vararg):
    s = Signature(function)
    assert s.vararg_name == vararg
示例#12
0
def test_construct_arguments_with_unexpected_args_raises_typeerror(func, args):
    unexpected = re.compile(".*unexpected.*")
    with pytest.raises(TypeError) as excinfo:
        Signature(func).construct_arguments(args, {}, {})
    assert unexpected.match(excinfo.value.args[0])
示例#13
0
def test_construct_arguments_with_unexpected_kwargs_raises_typeerror(function):
    kwargs = {'zimbabwe': 23}
    unexpected = re.compile(".*unexpected.*zimbabwe.*")
    with pytest.raises(TypeError) as excinfo:
        Signature(function).construct_arguments([], kwargs, {})
    assert unexpected.match(excinfo.value.args[0])
def test_constructor_extract_kwargs(function, kwargs):
    s = Signature(function)
    assert s.kwargs == kwargs
示例#15
0
def test_unicode_special():
    assert re.match("complex_function_name\(a=1, b=u?'fo', c=9\)",
                    Signature(complex_function_name).__unicode__())
示例#16
0
def test_construct_arguments_without_options_returns_same_args_kwargs():
    s = Signature(foo)
    args, kwargs = s.construct_arguments([], {}, {})
    assert args == []
    assert kwargs == {}

    s = Signature(bariza)
    args, kwargs = s.construct_arguments([2, 4, 6], {}, {})
    assert args == [2, 4, 6]
    assert kwargs == {}

    s = Signature(complex_function_name)
    args, kwargs = s.construct_arguments([2], {'c': 6, 'b': 7}, {})
    assert args == [2]
    assert kwargs == {'c': 6, 'b': 7}

    s = Signature(_name_with_underscore_)
    args, kwargs = s.construct_arguments([], {'fo': 7, 'bar': 6}, {})
    assert args == []
    assert kwargs == {'fo': 7, 'bar': 6}
示例#17
0
def test_construct_arguments_without_duplicates_passes():
    s = Signature(bariza)
    s.construct_arguments([1, 2], {'c': 5}, {})

    s = Signature(complex_function_name)
    s.construct_arguments([1], {'b': 4}, {})

    s = Signature(FunCTIonWithCAPItals)
    s.construct_arguments([], {'a': 6, 'b': 6, 'c': 6}, {})
示例#18
0
def test_construct_arguments_does_not_raise_for_missing_defaults():
    s = Signature(complex_function_name)
    s.construct_arguments([], {}, {})
示例#19
0
def test_construct_arguments_with_kwargswildcard_doesnt_raise():
    kwargs = {'zimbabwe': 23}
    Signature(FunCTIonWithCAPItals).construct_arguments([1, 2, 3], kwargs, {})
    Signature(__double_underscore__).construct_arguments([1, 2], kwargs, {})
示例#20
0
def test_construct_arguments_without_duplicates_passes():
    s = Signature(bariza)
    s.construct_arguments([1, 2], {'c': 5}, {})

    s = Signature(complex_function_name)
    s.construct_arguments([1], {'b': 4}, {})
示例#21
0
def test_constructor_extract_kwargs_wildcard_name(function, kw_wc):
    s = Signature(function)
    assert s.kw_wildcard_name == kw_wc
示例#22
0
def test_construct_arguments_overwrites_defaults():
    s = Signature(complex_function_name)
    args, kwargs = s.construct_arguments([], {}, {'a': 11, 'b': 12, 'c': 7})
    assert args == []
    assert kwargs == {'a': 11, 'b': 12, 'c': 7}
示例#23
0
def test_construct_arguments_without_duplicates_passes():
    s = Signature(bariza)
    s.construct_arguments([1, 2], {'c': 5}, {})

    s = Signature(complex_function_name)
    s.construct_arguments([1], {'b': 4}, {})
示例#24
0
def test_construct_arguments_with_expected_kwargs_does_not_raise():
    s = Signature(complex_function_name)
    s.construct_arguments([], {'a': 4, 'b': 3, 'c': 2}, {})
    s = Signature(FunCTIonWithCAPItals)
    s.construct_arguments([1, 2], {'c': 5}, {})
示例#25
0
def test_construct_arguments_does_not_raise_if_all_args_filled():
    s = Signature(bariza)
    s.construct_arguments([1, 2, 3], {}, {})
    s.construct_arguments([1, 2], {'c': 6}, {})
    s.construct_arguments([1], {'b': 6, 'c': 6}, {})
    s.construct_arguments([], {'a': 6, 'b': 6, 'c': 6}, {})
示例#26
0
def test_construct_arguments_with_kwargs_for_posargs_does_not_raise():
    Signature(bariza).construct_arguments([], {'a': 4, 'b': 3, 'c': 2}, {})
    s = Signature(FunCTIonWithCAPItals)
    s.construct_arguments([], {'a': 4, 'b': 3, 'c': 2, 'd': 6}, {})
示例#27
0
def test_construct_arguments_with_kwargs_for_posargs_does_not_raise():
    Signature(bariza).construct_arguments([], {'a': 4, 'b': 3, 'c': 2}, {})
    s = Signature(FunCTIonWithCAPItals)
    s.construct_arguments([], {'a': 4, 'b': 3, 'c': 2, 'd': 6}, {})
示例#28
0
def test_construct_arguments_does_not_raise_for_missing_defaults():
    s = Signature(complex_function_name)
    s.construct_arguments([], {}, {})
示例#29
0
def test_construct_arguments_for_bound_method():
    s = Signature(SomeClass.bla)
    args, kwargs = s.construct_arguments([1], {'b': 2}, {'c': 3}, bound=True)
    assert args == [1]
    assert kwargs == {'b': 2, 'c': 3}
示例#30
0
def test_unicode_(func, expected):
    assert Signature(func).__unicode__() == expected
示例#31
0
def test_construct_arguments_ignores_excess_options():
    s = Signature(bariza)
    args, kwargs = s.construct_arguments([2], {'b': 4},
                                         {'c': 6, 'foo': 9, 'bar': 0})
    assert args == [2]
    assert kwargs == {'b': 4, 'c': 6}
示例#32
0
def test_repr_(name, func):
    regex = "<Signature at 0x[0-9a-fA-F]+ for '%s'>"
    assert re.match(regex % name, Signature(func).__repr__())
示例#33
0
def test_construct_arguments_overwrites_defaults():
    s = Signature(complex_function_name)
    args, kwargs = s.construct_arguments([], {}, {'a': 11, 'b': 12, 'c': 7})
    assert args == []
    assert kwargs == {'a': 11, 'b': 12, 'c': 7}
示例#34
0
def test_constructor_extract_function_name(function, name):
    s = Signature(function)
    assert s.name == name
示例#35
0
def test_construct_arguments_does_not_raise_if_all_args_filled():
    s = Signature(bariza)
    s.construct_arguments([1, 2, 3], {}, {})
    s.construct_arguments([1, 2], {'c': 6}, {})
    s.construct_arguments([1], {'b': 6, 'c': 6}, {})
    s.construct_arguments([], {'a': 6, 'b': 6, 'c': 6}, {})
示例#36
0
def test_constructor_extracts_all_arguments(function, args):
    s = Signature(function)
    assert s.arguments == args
示例#37
0
def test_construct_arguments_for_bound_method():
    s = Signature(SomeClass.bla)
    args, kwargs = s.construct_arguments([1], {'b': 2}, {'c': 3}, bound=True)
    assert args == [1]
    assert kwargs == {'b': 2, 'c': 3}
示例#38
0
def test_construct_arguments_with_varargs_doesnt_raise():
    Signature(generic).construct_arguments([1, 2, 3], {}, {})
    Signature(__double_underscore__).construct_arguments([1, 2, 3, 4, 5], {},
                                                         {})
    Signature(_name_with_underscore_).construct_arguments([1, 2, 3, 4], {}, {})