Exemple #1
0
        class CacheTest(HasIPropsTester):
            caching_permissions = ('test1', 'test2')
            test1 = IProperty()
            test2 = IProperty()

            ss = CacheSS()
            ch = CacheChannel()
    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)
    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)
    def setup(self):
        p = IProperty()
        p.name = 'test'

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

        p.set = MethodType(setter, p)
        self.p = p
    def setup(self):
        p = IProperty()
        p.name = 'test'

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

        p.get = MethodType(getter, p)
        self.p = p
    def setup(self):
        p = IProperty()
        p.name = 'test'

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

        p.set = MethodType(setter, p)
        self.p = p
    def setup(self):
        p = IProperty()
        p.name = 'test'

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

        p.get = MethodType(getter, p)
        self.p = p
Exemple #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
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'
    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
Exemple #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'
Exemple #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
Exemple #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
Exemple #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>'
    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'
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
    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'
Exemple #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
    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
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__
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__
Exemple #22
0
    class DocTester(HasIPropsTester):

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

        def _get_test(self, iprop):
            return 'This is a test'
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
Exemple #27
0
    class OverrideSet(HasIPropsTester):
        test = IProperty(setter=True)

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