예제 #1
0
    def test(self):
        storage = Storage({})

        t = storage.makeRef(Person('Tom', 3))
        d = storage.makeRef(Person('Dick', 3))

        storage['c'] = c = Collection(storage)

        c.add(t)
        c.add(d)

        self.assertEqual(len(c.values()), 2)

        del c
        self.assertEqual(storage.cache.values(), [])

        t.setAge(4)

        c = storage['c']

        # The info for Tom in c has been updated.
        self.assertEqual(c.count(QTerm(':age', 'eq', 4)), 1)

        ti = c.values(QTerm(':name', 'eq', 'Tom'))[0]
        self.assertEqual(ti['age'], 4)

        c.discard(t)

        self.assertEqual(c.count(), 1)
        self.assertEqual(len(t.subscribers('*')), 0)

        d = c.open(QTerm(':name', 'eq', 'Dick'))

        self.assertEqual(d.age, 3)
예제 #2
0
파일: ref_test.py 프로젝트: ogoodman/serf
    def testFacetRef(self):
        vat = Storage({})
        main_ref = vat.makeRef(TestData(24))
        public = vat.makeRef(main_ref._getFacet('public'))

        self.assertEqual(public.get(), 24)
        self.assertRaises(AttributeError, getattr, public, 'set')

        # main_ref references a TestData instance
        self.assertEqual(type(main_ref._get()), TestData)

        # public references a facet Ref
        self.assertEqual(type(public._get()), Ref)
        self.assertEqual(public._get()._facet, 'public')

        # the facet Ref references an obj instance
        self.assertEqual(type(public._get()._get()), obj)

        # check facet is not lost in serialization.
        public._close()
        self.assertEqual(public._get()._facet, 'public')
예제 #3
0
파일: ref_test.py 프로젝트: ogoodman/serf
    def testFacetRef(self):
        vat = Storage({})
        main_ref = vat.makeRef(TestData(24))
        public = vat.makeRef(main_ref._getFacet('public'))

        self.assertEqual(public.get(), 24)
        self.assertRaises(AttributeError, getattr, public, 'set')

        # main_ref references a TestData instance
        self.assertEqual(type(main_ref._get()), TestData)

        # public references a facet Ref
        self.assertEqual(type(public._get()), Ref)
        self.assertEqual(public._get()._facet, 'public')

        # the facet Ref references an obj instance
        self.assertEqual(type(public._get()._get()), obj)

        # check facet is not lost in serialization.
        public._close()
        self.assertEqual(public._get()._facet, 'public')
예제 #4
0
    def testSubscribe(self):
        storage = Storage({})

        t = storage.makeRef(Person('Tom', 3))
        storage['c'] = c = Collection(storage)
        c.add(t)

        storage['s'] = s = Subscriber([])

        c.subscribe('change', s.on)
        t.setAge(4)

        self.assertEqual(len(s.events), 1)
예제 #5
0
    def testNames(self):
        vat = Storage({})
        foo = vat.makeRef(Obj({}))

        ns = NameStore(vat, {})

        foo['x'] = 'bar'
        ns.setn('foo', foo)

        foo1 = ns.getn('foo')
        self.assertEqual(foo1['x'], 'bar')

        # Can do it all in one..
        ns.setn('time', Time())
        self.assertEqual(ns.getn('time').time(), 'Tea-time')
        ns.getn('time')._erase()
        ns.deln('time')
예제 #6
0
    def testNames(self):
        vat = Storage({})
        foo = vat.makeRef(Obj({}))

        ns = NameStore(vat, {})

        foo['x'] = 'bar'
        ns.setn('foo', foo)

        foo1 = ns.getn('foo')
        self.assertEqual(foo1['x'], 'bar')

        # Can do it all in one..
        ns.setn('time', Time())
        self.assertEqual(ns.getn('time').time(), 'Tea-time')
        ns.getn('time')._erase()
        ns.deln('time')