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_a(self):
     filename = tempfile.mktemp()
     s = FileStorage2(filename)
     connection = Connection(s)
     root = connection.get_root()
     root['a'] = Persistent()
     root['a'].b = 1
     connection.commit()
     root['a'].b = 2
     connection.commit()
     s.close()
     hc = HistoryConnection(filename)
     a = hc.get_root()['a']
     assert len(hc.get_storage().index.history) == 4
     assert a.b == 2
     hc.previous()
     assert a.b == 1
     hc.next()
     assert a.b == 2
     hc.previous()
     assert a.b == 1
     hc.previous()
     assert a._p_is_ghost()
     assert not hasattr(a, '__dict__')
     assert isinstance(a, Persistent)
     assert raises(KeyError, getattr, a, 'b')
     assert hc.get(a._p_oid) is a
     hc.next()
     assert a.b == 1
     hc.get_storage().fp.close()
     os.unlink(filename)
Esempio n. 3
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>"
Esempio n. 4
0
 def test_check_connection(self):
     self.conn=conn=Connection(self._get_storage())
     self.root=root=conn.get_root()
     assert root._p_is_ghost() == True
     assert root is conn.get(p64(0))
     assert root is conn.get(0)
     assert conn is root._p_connection
     assert conn.get(p64(1)) == None
     conn.abort()
     conn.commit()
     assert root._p_is_ghost() == True
     root['a'] = Persistent()
     assert root._p_is_unsaved() == True
     assert root['a']._p_is_unsaved() == True
     root['a'].f=2
     assert conn.changed.values() == [root]
     conn.commit()
     assert root._p_is_saved()
     assert conn.changed.values() == []
     root['a'] = Persistent()
     assert conn.changed.values() == [root]
     root['b'] = Persistent()
     root['a'].a = 'a'
     root['b'].b = 'b'
     conn.commit()
     root['a'].a = 'a'
     root['b'].b = 'b'
     conn.abort()
     conn.shrink_cache()
     root['b'].b = 'b'
     del conn
Esempio n. 5
0
 def test_check_touch_every_reference(self):
     connection = Connection(self._get_storage())
     root = connection.get_root()
     root['a'] = Persistent()
     root['b'] = Persistent()
     from schevo.store.persistent_list import PersistentList
     root['b'].c = PersistentList()
     connection.commit()
     touch_every_reference(connection, 'PersistentList')
     assert root['b']._p_is_unsaved()
     assert root['b'].c._p_is_unsaved()
     assert not root._p_is_unsaved()
Esempio n. 6
0
 def test_b(self):
     filename = tempfile.mktemp()
     s = FileStorage2(filename)
     connection = Connection(s)
     root = connection.get_root()
     root['a'] = Persistent()
     root['a'].b = 1
     connection.commit()
     root['b'] = Persistent()
     connection.commit()
     root['b'].a = root['a']
     root['a'].b = 2
     connection.commit()
     root['a'].b = 3
     connection.commit()
     s.close()
     hc = HistoryConnection(filename)
     a = hc.get_root()['a']
     assert len(hc.get_storage().index.history) == 6
     hc.previous_instance(a)
     assert a.b == 2
     hc.previous_instance(a)
     assert a.b == 1
     hc.previous_instance(a)
     assert not hasattr(a, '__dict__')
     assert hc.get_root().keys() == []
     hc.get_storage().fp.close()
     os.unlink(filename)
Esempio n. 7
0
 def test_check_shrink(self):
     storage = self._get_storage()
     self.conn=conn=Connection(storage, cache_size=3)
     self.root=root=conn.get_root()
     root['a'] = Persistent()
     root['b'] = Persistent()
     root['c'] = Persistent()
     assert self.root._p_is_unsaved()
     conn.commit()
     root['a'].a = 1
     conn.commit()
     root['b'].b = 1
     root['c'].c = 1
     root['d'] = Persistent()
     root['e'] = Persistent()
     root['f'] = Persistent()
     conn.commit()
     root['f'].f = 1
     root['g'] = Persistent()
     conn.commit()
     conn.pack()
Esempio n. 8
0
 def test_check_change(self):
     p=Persistent()
     p._p_changed == 0
     p._p_note_change()
     assert p._p_changed == True
Esempio n. 9
0
 def test_check_setstate(self):
     p=Persistent()
     p.__setstate__({})
     p.__setstate__({'a':1})
     assert p.a == 1
Esempio n. 10
0
 def test_check_getstate(self):
     p=Persistent()
     assert p.__getstate__() == {}
     p.a = 1
     assert p.__getstate__() == {'a':1}