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_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_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()
class TestDurus(object): def setUp(self): self.connection = Connection(TempFileStorage()) def tearDown(self): del self.connection def test_a(self): bt = self.connection.get_root()['bt'] = BTree() t = bt.root.minimum_degree assert self.connection.get_cache_count() == 1 for x in range(2 * t - 1): bt.add(x) self.connection.commit() assert self.connection.get_cache_count() == 3 bt.add(2 * t - 1) self.connection.commit() assert self.connection.get_cache_count() == 5
def test_check_more(self): storage = TempFileStorage() connection = Connection(storage) root=connection.get_root() assert root._p_is_ghost() root['a'] = 1 assert root._p_is_unsaved() del root['a'] connection.abort() assert root._p_is_ghost() try: root['a'] assert 0 except KeyError: pass root._p_set_status_saved() assert root._p_is_saved() root._p_set_status_unsaved() assert root._p_is_unsaved() root._p_set_status_ghost() assert root._p_is_ghost() root._p_set_status_unsaved()
def test_check_storage_tools(self): connection = Connection(self._get_storage()) root = connection.get_root() root['a'] = Persistent() root['b'] = Persistent() connection.commit() index = get_reference_index(connection.get_storage()) assert index == {p64(1): [p64(0)], p64(2): [p64(0)]} census = get_census(connection.get_storage()) assert census == {'PersistentDict':1, 'PersistentTester':2} references = list(gen_referring_oid_record(connection.get_storage(), p64(1))) assert references == [(p64(0), connection.get_storage().load(p64(0)))] class Fake(object): pass s = Fake() s.__class__ = Storage assert raises(RuntimeError, s.__init__) assert raises(NotImplementedError, s.load, None) assert raises(NotImplementedError, s.begin) assert raises(NotImplementedError, s.store, None, None) assert raises(NotImplementedError, s.end) assert raises(NotImplementedError, s.sync) assert raises(NotImplementedError, s.gen_oid_record)