Esempio n. 1
0
def test_multiple_wrapper_suppored():
    class TwoMethods(Configurable):
        h1 = Method(required=True)
        h2 = Method(required=True)

    with inspect_node(TwoMethods) as ci:
        assert ci.type == TwoMethods
        assert not ci.instance
        assert len(ci.options) == 2
        assert not len(ci.processors)
        assert not ci.partial

    @TwoMethods
    def OneMethod():
        pass

    with inspect_node(OneMethod) as ci:
        assert ci.type == TwoMethods
        assert not ci.instance
        assert len(ci.options) == 2
        assert not len(ci.processors)
        assert ci.partial

    @OneMethod
    def transformation():
        pass

    with inspect_node(transformation) as ci:
        assert ci.type == TwoMethods
        assert ci.instance
        assert len(ci.options) == 2
        assert not len(ci.processors)
        assert not ci.partial
Esempio n. 2
0
def test_partial():
    C = Bobby

    # inspect the configurable class
    with inspect_node(C) as ci:
        assert ci.type == Bobby
        assert not ci.instance
        assert len(ci.options) == 4
        assert len(ci.processors) == 1
        assert not ci.partial

    # instanciate a partial instance ...
    f1 = MagicMock()
    C = C(f1)

    with inspect_node(C) as ci:
        assert ci.type == Bobby
        assert not ci.instance
        assert len(ci.options) == 4
        assert len(ci.processors) == 1
        assert ci.partial
        assert ci.partial[0] == (f1, )
        assert not len(ci.partial[1])

    # instanciate a more complete partial instance ...
    f2 = MagicMock()
    C = C(f2)

    with inspect_node(C) as ci:
        assert ci.type == Bobby
        assert not ci.instance
        assert len(ci.options) == 4
        assert len(ci.processors) == 1
        assert ci.partial
        assert ci.partial[0] == (
            f1,
            f2,
        )
        assert not len(ci.partial[1])

    c = C('foo')

    with inspect_node(c) as ci:
        assert ci.type == Bobby
        assert ci.instance
        assert len(ci.options) == 4
        assert len(ci.processors) == 1
        assert not ci.partial
def test_missing_required_options_error():
    with inspect_node(MyHarderConfigurable()) as ni:
        assert ni.partial

    with pytest.raises(TypeError) as exc:
        MyHarderConfigurable(_final=True)
    assert exc.match('missing 2 required options:')
Esempio n. 4
0
def test_missing_required_options_error():
    with inspect_node(MyHarderConfigurable()) as ni:
        assert ni.partial

    with pytest.raises(TypeError) as exc:
        MyHarderConfigurable(_final=True)
    assert exc.match("missing 2 required options:")
def test_int_type_factory():
    o = MyConfigurable(required_str='yo', default_str='bar', integer='42')

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == 'yo'
    assert o.default_str == 'bar'
    assert o.integer == 42
Esempio n. 6
0
def test_int_type_factory():
    o = MyConfigurable(required_str="yo", default_str="bar", integer="42")

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == "yo"
    assert o.default_str == "bar"
    assert o.integer == 42
def test_int_type_factory():
    o = MyConfigurable(required_str='yo', default_str='bar', integer='42')

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == 'yo'
    assert o.default_str == 'bar'
    assert o.integer == 42
def test_str_type_factory():
    o = MyConfigurable(required_str=42)

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == '42'
    assert o.default_str == 'foo'
    assert o.integer is None
def test_defaults():
    o = MyConfigurable(required_str='hello')

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == 'hello'
    assert o.default_str == 'foo'
    assert o.integer is None
Esempio n. 10
0
def test_option_resolution_order():
    o = MyBetterConfigurable()

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == 'kaboom'
    assert o.default_str == 'foo'
    assert o.integer is None
Esempio n. 11
0
def test_defaults():
    o = MyConfigurable(required_str='hello')

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == 'hello'
    assert o.default_str == 'foo'
    assert o.integer == None
Esempio n. 12
0
def test_str_type_factory():
    o = MyConfigurable(required_str=42)

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == "42"
    assert o.default_str == "foo"
    assert o.integer is None
Esempio n. 13
0
def test_option_resolution_order():
    o = MyBetterConfigurable()

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == "kaboom"
    assert o.default_str == "foo"
    assert o.integer is None
Esempio n. 14
0
def test_defaults():
    o = MyConfigurable(required_str="hello")

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == "hello"
    assert o.default_str == "foo"
    assert o.integer is None
Esempio n. 15
0
def test_bool_type_factory():
    o = MyHarderConfigurable(required_str='yes', also_required='True')

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == 'yes'
    assert o.default_str == 'foo'
    assert o.integer is None
    assert o.also_required is True
Esempio n. 16
0
def test_bool_type_factory():
    o = MyHarderConfigurable(required_str="yes", also_required="True")

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == "yes"
    assert o.default_str == "foo"
    assert o.integer is None
    assert o.also_required is True
Esempio n. 17
0
def test_bool_type_factory():
    o = MyHarderConfigurable(required_str='yes', also_required='True')

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.required_str == 'yes'
    assert o.default_str == 'foo'
    assert o.integer is None
    assert o.also_required is True
Esempio n. 18
0
def test_option_positional():
    o = MyConfigurableUsingPositionalOptions('1', '2', '3', required_str='hello')

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.first == '1'
    assert o.second == '2'
    assert o.third == '3'
    assert o.required_str == 'hello'
    assert o.default_str == 'foo'
    assert o.integer is None
Esempio n. 19
0
def test_option_positional():
    o = MyConfigurableUsingPositionalOptions('1', '2', '3', required_str='hello')

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.first == '1'
    assert o.second == '2'
    assert o.third == '3'
    assert o.required_str == 'hello'
    assert o.default_str == 'foo'
    assert o.integer is None
Esempio n. 20
0
def test_option_positional():
    o = MyConfigurableUsingPositionalOptions("1",
                                             "2",
                                             "3",
                                             required_str="hello")

    with inspect_node(o) as ni:
        assert not ni.partial

    assert o.first == "1"
    assert o.second == "2"
    assert o.third == "3"
    assert o.required_str == "hello"
    assert o.default_str == "foo"
    assert o.integer is None
Esempio n. 21
0
def test_define_with_decorator():
    calls = []

    def my_handler(*args, **kwargs):
        calls.append((args, kwargs, ))

    Concrete = MethodBasedConfigurable(my_handler)

    assert callable(Concrete.handler)
    assert Concrete.handler == my_handler

    with inspect_node(Concrete) as ci:
        assert ci.type == MethodBasedConfigurable
        assert ci.partial

    t = Concrete('foo', bar='baz')

    assert callable(t.handler)
    assert len(calls) == 0
    t()
    assert len(calls) == 1
Esempio n. 22
0
def test_define_with_decorator():
    calls = []

    def my_handler(*args, **kwargs):
        calls.append((
            args,
            kwargs,
        ))

    Concrete = MethodBasedConfigurable(my_handler)

    assert callable(Concrete.handler)
    assert Concrete.handler.__func__ == my_handler

    with inspect_node(Concrete) as ci:
        assert ci.type == MethodBasedConfigurable
        assert ci.partial

    t = Concrete('foo', bar='baz')

    assert callable(t.handler)
    assert len(calls) == 0
    t()
    assert len(calls) == 1
Esempio n. 23
0
def test_no_opt_configurable():
    o = NoOptConfigurable()

    with inspect_node(o) as ni:
        assert not ni.partial
Esempio n. 24
0
def test_no_opt_configurable():
    o = NoOptConfigurable()

    with inspect_node(o) as ni:
        assert not ni.partial