Esempio n. 1
0
 def test_check_object_writer(self):
     class FakeConnection(ConnectionBase):
         def new_oid(self):
             return ROOT_OID
         def note_access(self, obj):
             pass
     connection = FakeConnection()
     self.s=s=ObjectWriter(connection)
     x = Persistent()
     assert x._p_connection == None
     x._p_oid = ROOT_OID
     x._p_connection = connection
     assert s._persistent_id(x) == (ROOT_OID, Persistent)
     x._p_connection = FakeConnection()
     # connection of x no longer matches connection of s.
     try:
         s._persistent_id(x)
         assert 0
     except InvalidObjectReference: pass
     x.a = Persistent()
     assert s.get_state(x), (
         '\x80\x02cschevo.store.persistent\nPersistent\nq\x01.\x80\x02}q'
         '\x02U\x01aU\x08\x00\x00\x00\x00\x00\x00\x00\x00q\x03h\x01\x86Qs.',
         '\x00\x00\x00\x00\x00\x00\x00\x00')
     assert list(s.gen_new_objects(x)) == [x, x.a]
     # gen_new_objects() can only be called once.
     try:
         s.gen_new_objects(3)
         assert 0
     except RuntimeError: pass
     s.close()
Esempio n. 2
0
 def test_check_accessors(self):
     p=Persistent()
     p._p_oid
     assert p._p_format_oid() == 'None'
     p._p_oid = p64(1)
     assert p._p_format_oid() == '1'
     assert repr(p) == "<PersistentTester 1>"