Exemplo n.º 1
0
        class CacheTest(HasIPropsTester):
            caching_permissions = ('test1', 'test2')
            test1 = IProperty()
            test2 = IProperty()

            ss = CacheSS()
            ch = CacheChannel()
Exemplo n.º 2
0
    def test_wrapping_exception(self):
        p = IProperty(True, checks=('{t1} is True; {t2} == False', None))

        # Wrapping function
        f = lambda s, o, v: 'test'
        with raises(ValueError):
            p._wrap_with_checker(f, None)
Exemplo n.º 3
0
    def test_wrapping_exception(self):
        p = IProperty(True, checks=('{t1} is True; {t2} == False', None))

        # Wrapping function
        f = lambda s, o, v: 'test'
        with raises(ValueError):
            p._wrap_with_checker(f, None)
Exemplo n.º 4
0
    def setup(self):
        p = IProperty()
        p.name = 'test'

        def setter(self, obj, value):
            self.val = value

        p.set = MethodType(setter, p)
        self.p = p
Exemplo n.º 5
0
    def setup(self):
        p = IProperty()
        p.name = 'test'

        def getter(self, obj):
            return 'Test'

        p.get = MethodType(getter, p)
        self.p = p
Exemplo n.º 6
0
    def setup(self):
        p = IProperty()
        p.name = 'test'

        def setter(self, obj, value):
            self.val = value

        p.set = MethodType(setter, p)
        self.p = p
Exemplo n.º 7
0
    def setup(self):
        p = IProperty()
        p.name = 'test'

        def getter(self, obj):
            return 'Test'

        p.get = MethodType(getter, p)
        self.p = p
Exemplo n.º 8
0
def test_make_proxy_cache():
    ip = IProperty(getter=True)
    ip2 = IProperty(setter=True)

    pm = _ProxyManager()
    pm.make_proxy(ip, WeakRef(), {'get': lambda s, o: True, 'toto': 'test'})
    pm.make_proxy(ip2, WeakRef(), {'set': lambda s, o, v: None})

    assert len(pm._proxy_cache) == 1
Exemplo n.º 9
0
def test_unpatch():
    ip = IProperty(getter=True)
    ip.get = MethodType(lambda s, o: False, ip)

    pm = _ProxyManager()
    ip_p = pm.make_proxy(ip, WeakRef(),
                         {'get': lambda s, o: True, 'toto': 'test'})

    ip_p.unpatch(['get'])
    assert not ip_p.get(None)
    assert ip_p.toto == 'test'
Exemplo n.º 10
0
    def test_wrapping_set_no_checker(self):
        p = IProperty(True, checks=('{t1} is True; {t2} == False', None))

        # Wrapping function
        f = lambda s, o, v: 'test'
        p._wrap_with_checker(f, 'pre_set')
        assert p.pre_set.__func__ is f

        # Wrapping method
        f = MethodType(lambda s, o, v: 'test', p)
        p._wrap_with_checker(f, 'pre_set')
        assert p.pre_set is f
Exemplo n.º 11
0
def test_unpatch():
    ip = IProperty(getter=True)
    ip.get = MethodType(lambda s, o: False, ip)

    pm = _ProxyManager()
    ip_p = pm.make_proxy(ip, WeakRef(), {
        'get': lambda s, o: True,
        'toto': 'test'
    })

    ip_p.unpatch(['get'])
    assert not ip_p.get(None)
    assert ip_p.toto == 'test'
Exemplo n.º 12
0
    class OverridePreGet(HasIPropsTester):
        test = IProperty(getter=True)

        def _get_test(self, iprop):
            return 'this is a test'

        def _pre_get_test(self, iprop):
            assert False
Exemplo n.º 13
0
    class OverridePreSet(HasIPropsTester):
        test = IProperty(setter=True)

        def _set_test(self, iprop, value):
            self.val = value

        def _pre_set_test(self, iprop, value):
            return value / 2
Exemplo n.º 14
0
    class OverridePostGet(HasIPropsTester):
        test = IProperty(getter=True)

        def _get_test(self, iprop):
            return 'this is a test'

        def _post_get_test(self, iprop, val):
            return '<br>' + val + '<br>'
Exemplo n.º 15
0
    def test_wrapping_set_checker_exists(self):
        p = IProperty(True, checks='{t1} is True; {t2} == False')

        # Wrapping function
        f = lambda s, o, v: 'test'
        p._wrap_with_checker(f, 'pre_set')
        assert p.pre_set.__func__ is not f
        assert p.pre_set(self.t, None) == 'test'

        # Wrapping method
        f = MethodType(lambda s, o, v: 'test', p)
        p._wrap_with_checker(f, 'pre_set')
        assert p.pre_set is not f
        assert p.pre_set(self.t, None) == 'test'
Exemplo n.º 16
0
def test_get_check():

    class Tester(FalseDriver):
        t1 = True
        t2 = False

    p = IProperty(True, checks=('{t1} is True; {t2} == False', None))
    p.name = 'test'
    p.get = MethodType(lambda s, o: None, p)
    p.set = MethodType(lambda s, o, v: v, p)
    t = Tester()

    assert hasattr(p, 'get_check')
    assert not hasattr(p, 'set_check')

    p._get(t)
    t.t2 = True
    with raises(AssertionError):
        p._get(t)
    try:
        p._get(t)
    except AssertionError as e:
        m = 'Getting test assertion t2 == False failed, values are : t2=True'
        assert e.message == m
Exemplo n.º 17
0
    def test_wrapping_set_checker_exists(self):
        p = IProperty(True, checks='{t1} is True; {t2} == False')

        # Wrapping function
        f = lambda s, o, v: 'test'
        p._wrap_with_checker(f, 'pre_set')
        assert p.pre_set.__func__ is not f
        assert p.pre_set(self.t, None) == 'test'

        # Wrapping method
        f = MethodType(lambda s, o, v: 'test', p)
        p._wrap_with_checker(f, 'pre_set')
        assert p.pre_set is not f
        assert p.pre_set(self.t, None) == 'test'
Exemplo n.º 18
0
def test_clone_if_needed():

    prop = IProperty(getter=True)

    class Overriding(HasIPropsTester):
        test = prop

        def _get_test(self, iprop):
            return 1

    assert Overriding.test is prop

    class OverridingParent(Overriding):
        def _get_test(self):
            return 2

    assert OverridingParent.test is not prop
Exemplo n.º 19
0
    def test_wrapping_set_no_checker(self):
        p = IProperty(True, checks=('{t1} is True; {t2} == False', None))

        # Wrapping function
        f = lambda s, o, v: 'test'
        p._wrap_with_checker(f, 'pre_set')
        assert p.pre_set.__func__ is f

        # Wrapping method
        f = MethodType(lambda s, o, v: 'test', p)
        p._wrap_with_checker(f, 'pre_set')
        assert p.pre_set is f
Exemplo n.º 20
0
def test_cloning():
    p = IProperty(True, True)

    def aux(self, obj):
        return self

    m = MethodType(aux, p)
    p.get = m
    p.val = 1
    p.__doc__ = 'test'

    p2 = p.clone()
    assert p2 is not p
    assert p2.val == 1
    assert p2.get.__func__ == aux
    assert p2.get(None) != p.get(None)
    assert p2.__doc__ == p.__doc__
Exemplo n.º 21
0
def test_cloning():
    p = IProperty(True, True)

    def aux(self, obj):
        return self
    m = MethodType(aux, p)
    p.get = m
    p.val = 1
    p.__doc__ = 'test'

    p2 = p.clone()
    assert p2 is not p
    assert p2.val == 1
    assert p2.get.__func__ == aux
    assert p2.get(None) != p.get(None)
    assert p2.__doc__ == p.__doc__
Exemplo n.º 22
0
    class DocTester(HasIPropsTester):

        #: This is the docstring for
        #: the IProperty test.
        test = IProperty()
Exemplo n.º 23
0
 class CacheSS(SubSystem):
     caching_permissions = ('test', )
     test = IProperty()
Exemplo n.º 24
0
 class CacheChannel(Channel):
     caching_permissions = ('aux', )
     aux = IProperty()
Exemplo n.º 25
0
    class OverrideGet(HasIPropsTester):
        test = IProperty(getter=True)

        def _get_test(self, iprop):
            return 'This is a test'
Exemplo n.º 26
0
def test_set_check():
    class Tester(FalseDriver):
        t1 = True
        t2 = False

    p = IProperty(True, checks=(None, '{t1} is True; {t2} == False'))
    p.name = 'test'
    p.get = MethodType(lambda s, o: None, p)
    p.set = MethodType(lambda s, o, v: v, p)
    t = Tester()

    assert not hasattr(p, 'get_check')
    assert hasattr(p, 'set_check')

    p._get(t)
    p._set(t, 1)
    t.t2 = True

    with raises(AssertionError):
        p._set(t, 1)
    try:
        p._set(t, 1)
    except AssertionError as e:
        m = 'Setting test assertion t2 == False failed, values are : t2=True'
        assert e.message == m
Exemplo n.º 27
0
    class OverrideSet(HasIPropsTester):
        test = IProperty(setter=True)

        def _set_test(self, iprop, value):
            self.val = value
Exemplo n.º 28
0
 class NoOverrideSet(HasIPropsTester):
     test = IProperty(setter=True)