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)
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
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)
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()