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
Exemple #2
0
 def _write_index(self, fp, index):
     index_offset = fp.tell()
     compressed = compress(dumps(index))
     fp.write(p64(len(compressed)))
     fp.write(compressed)
     fp.seek(len(self.MAGIC))
     fp.write(p64(index_offset))
     assert fp.tell() == len(self.MAGIC) + 8
 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>"
 def _check_file_storage(self, storage):
     b = storage
     assert b.new_oid() == p64(1)
     assert b.new_oid() == p64(2)
     try:
         b.load(p64(0))
         assert 0
     except KeyError: pass
     record = pack_record(p64(0), 'ok', '')
     b.store(p64(0), record)
     b.begin()
     b.end()
     b.sync()
     b.begin()
     b.store(p64(1), pack_record(p64(1), 'no', ''))
     b.end()
     assert len(list(b.gen_oid_record())) == 2
     b.pack()
     import schevo.store.file_storage
     if schevo.store.file_storage.RENAME_OPEN_FILE:
         schevo.store.file_storage.RENAME_OPEN_FILE = False
         b.pack()
         c = FileStorage(b.get_filename(), readonly=True)
         try:
             c.pack()
             assert 0
         except IOError: # read-only storage
             pass
     b.close()
     try:
         b.pack()
         assert 0
     except IOError: # storage closed
         pass
     try:
         b.load(0)
         assert 0
     except IOError: # storage closed
         pass
 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)
Exemple #6
0
 def new_oid(self):
     self.oid += 1
     return p64(self.oid)
Exemple #7
0
 def test_check_p64_u64(self):
     for x in range(3):
         assert len(p64(x)) == 8
         assert u64(p64(x)) == x
Exemple #8
0
 def test_check_memory_storage(self):
     b = MemoryStorage()
     assert b.new_oid() == p64(1)
     assert b.new_oid() == p64(2)
     assert raises(KeyError, b.load, p64(0))
     record = pack_record(p64(0), 'ok', '')
     b.begin()
     b.store(p64(0), record)
     b.end()
     b.sync()
     b.begin()
     b.store(p64(1), pack_record(p64(1), 'no', ''))
     b.end()
     assert len(list(b.gen_oid_record())) == 2
     assert record == b.load(p64(0))
     records = b.bulk_load([p64(0), p64(1)])
     assert len(list(records)) == 2
     records = b.bulk_load([p64(0), p64(1), p64(2)])
     assert raises(KeyError, list, records)
Exemple #9
0
 def _write_header(self, fp):
     FileStorage._write_header(self, fp)
     fp.write(p64(0)) # index offset
Exemple #10
0
 def _disk_format(self, record):
     return p64(self.tid) + record