Ejemplo n.º 1
0
def test_cmdy_plugin_add_property_multi_override():

    class Base:
        def __init__(self):
            self.base = 1

        @property
        def base1(self):
            return self.base + 10

    _cmdy_hook_class(Base)

    @cmdy_plugin
    class Plugin:
        @cmdy_plugin_add_property(Base)
        def base1(self):
            return self._original('base1').fget(self) + 1

    @cmdy_plugin
    class Plugin2:
        @cmdy_plugin_add_property(Base)
        def base1(self):
            return self._original('base1').fget(self) * 2

    p = Plugin()
    p2 = Plugin2()
    b = Base()
    p.disable()
    assert b.base1 == 22
Ejemplo n.º 2
0
def test_cmdy_plugin_add_method_multi_override_disable():

    class Base:
        def __init__(self):
            self.base = 1

        def add(self):
            return self.base + 10

    _cmdy_hook_class(Base)

    @cmdy_plugin
    class Plugin:
        @cmdy_plugin_add_method(Base)
        def add(self):
            return self._original('add')(self) + 1

    @cmdy_plugin
    class Plugin2:
        @cmdy_plugin_add_method(Base)
        def add(self):
            return self._original('add')(self) * 2

    b = Base()
    p = Plugin()
    p2 = Plugin2()
    p.disable()
    assert b.add() == 22
Ejemplo n.º 3
0
def test_cmdy_plugin_add_property():

    class Base:
        def __init__(self):
            self.base = 1
    _cmdy_hook_class(Base)

    @cmdy_plugin
    class Plugin:
        @cmdy_plugin_add_property(Base)
        def base1(self):
            return self.base + 1

    p = Plugin()
    b = Base()
    assert b.base1 == 2

    p.disable()
    with pytest.raises(AttributeError):
        b.base1