def check_connection(self): self.conn=conn=Connection(self._get_storage()) self.root=root=conn.get_root() assert root._p_is_ghost() == False assert root is conn.get(int8_to_str(0)) assert root is conn.get(0) assert conn is root._p_connection assert conn.get(int8_to_str(1)) == None conn.abort() conn.commit() assert root._p_is_ghost() == False root['a'] = Persistent() assert root._p_is_unsaved() == True assert root['a']._p_is_unsaved() == True root['a'].f=2 assert list(conn.changed.values()) == [root] conn.commit() assert root._p_is_saved() assert list(conn.changed.values()) == [] root['a'] = Persistent() assert list(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
def check_connection(self): self.conn = conn = Connection(self._get_storage()) self.root = root = conn.get_root() assert root._p_is_ghost() == False assert root is conn.get(int8_to_str(0)) assert root is conn.get(0) assert conn is root._p_connection assert conn.get(int8_to_str(1)) == None conn.abort() conn.commit() assert root._p_is_ghost() == False root['a'] = Persistent() assert root._p_is_unsaved() == True assert root['a']._p_is_unsaved() == True root['a'].f = 2 assert list(conn.changed.values()) == [root] conn.commit() assert root._p_is_saved() assert list(conn.changed.values()) == [] root['a'] = Persistent() assert list(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
def 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. raises(ValueError, s._persistent_id, x) x.a = Persistent() assert s.get_state(x), ( '\x80\x02cdurus.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. raises(RuntimeError, s.gen_new_objects, 3) s.close()
def 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()
def 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()
def check_getstate(self): p=Persistent() assert p.__getstate__() == {} p.a = 1 assert p.__getstate__() == {'a':1}
def check_getstate(self): p=Persistent() assert p.__getstate__() == {} p.a = 1 assert p.__getstate__() == {'a':1}