Пример #1
0
 def b(self):
     f = File(prefix='shelftest')
     name = f.get_name()
     f.close()
     s = FileStorage(name)
     c = Connection(s)
     r = c.get_root()
     for x in range(10):
         r["a%s" % x] = Persistent()
         c.commit()
     deleted_oid = r['a9']._p_oid
     del r['a9']
     c.commit()
     c.pack()
     c.abort()
     assert len([repr(oid) for oid, record in s.gen_oid_record()]) == 10
     new_oid = s.new_oid()
     assert new_oid == deleted_oid
     new_oid = s.new_oid()
     assert new_oid == int8_to_str(11)
Пример #2
0
 def b(self):
     f = File(prefix='shelftest')
     name = f.get_name()
     f.close()
     s = FileStorage(name)
     c = Connection(s)
     r = c.get_root()
     for x in range(10):
         r["a%s" % x] = Persistent()
         c.commit()
     deleted_oid = r['a9']._p_oid
     del r['a9']
     c.commit()
     c.pack()
     c.abort()
     assert len([repr(oid) for oid, record in s.gen_oid_record()]) == 10
     new_oid = s.new_oid()
     assert new_oid == deleted_oid
     new_oid = s.new_oid()
     assert new_oid == int8_to_str(11)
Пример #3
0
 def a(self):
     f = File()
     f.rename(f.get_name())
     assert f.is_temporary()
     raises(AssertionError, f.rename, f.get_name() + '.renamed')
     test_name = f.get_name() + '.test'
     assert not exists(test_name)
     tmp = open(test_name, 'w+b')
     tmp.close()
     g = File(test_name)
     assert not g.is_temporary()
     g.rename(g.get_name() + '.renamed')
     assert g.get_name() == test_name + '.renamed'
     f.write(as_bytes('abc'))
     f.seek(0)
     assert len(f) == 3
     assert as_bytes('a') == f.read(1)
     assert as_bytes('bc') == f.read()
     f.close()
     assert not exists(f.get_name())
     raises(OSError, f.__len__) # tmpfile removed on close
     h = File(g.get_name())
     g.write(as_bytes('a'))
     g.seek(0)
     assert g.tell() == 0
     g.seek_end()
     assert g.tell() == 1
     assert g.has_lock
     assert not h.has_lock
     raises(IOError, h.write, as_bytes('b'))
     g.flush()
     g.fsync()
     g.seek(0)
     g.truncate()
     g.close()
     h.close()
     unlink(g.get_name())
Пример #4
0
 def a(self):
     f = File()
     f.rename(f.get_name())
     assert f.is_temporary()
     raises(AssertionError, f.rename, f.get_name() + '.renamed')
     test_name = f.get_name() + '.test'
     assert not exists(test_name)
     tmp = open(test_name, 'w+b')
     tmp.close()
     g = File(test_name)
     assert not g.is_temporary()
     g.rename(g.get_name() + '.renamed')
     assert g.get_name() == test_name + '.renamed'
     f.write(as_bytes('abc'))
     f.seek(0)
     assert len(f) == 3
     assert as_bytes('a') == f.read(1)
     assert as_bytes('bc') == f.read()
     f.close()
     assert not exists(f.get_name())
     raises(OSError, f.__len__)  # tmpfile removed on close
     h = File(g.get_name())
     g.write(as_bytes('a'))
     g.seek(0)
     assert g.tell() == 0
     g.seek_end()
     assert g.tell() == 1
     assert g.has_lock
     assert not h.has_lock
     raises(IOError, h.write, as_bytes('b'))
     g.flush()
     g.fsync()
     g.seek(0)
     g.truncate()
     g.close()
     h.close()
     unlink(g.get_name())
Пример #5
0
 def a(self):
     f = File(prefix='shelftest')
     name = f.get_name()
     f.close()
     s = FileStorage(name)
     c = Connection(s)
     r = c.get_root()
     for x in range(10):
         r["a%s" % x] = Persistent()
         c.commit()
     deleted_oids = [
         r['a0']._p_oid, r['a2']._p_oid, r['a7']._p_oid, r['a8']._p_oid
     ]
     del r['a0']
     del r['a2']
     del r['a7']
     del r['a8']
     c.commit()
     c.pack()
     c.abort()
     assert c.get(deleted_oids[0])._p_is_ghost()
     assert c.get(deleted_oids[1])._p_is_ghost()
     raises(KeyError, getattr, c.get(deleted_oids[0]), 'a')
     assert len([repr(oid) for oid, record in s.gen_oid_record()]) == 7
     c.commit()
     c.pack()
     new_oid = s.new_oid()
     assert new_oid == deleted_oids[-1], (new_oid, deleted_oids)
     new_oid = s.new_oid()
     assert new_oid == deleted_oids[-2], (new_oid, deleted_oids)
     new_oid = s.new_oid()
     assert new_oid == deleted_oids[-3], (new_oid, deleted_oids)
     new_oid = s.new_oid()
     assert new_oid == deleted_oids[-4], (new_oid, deleted_oids)
     new_oid = s.new_oid()
     assert new_oid == int8_to_str(11), repr(new_oid)
     new_oid = s.new_oid()
     assert new_oid == int8_to_str(12), repr(new_oid)
Пример #6
0
 def c(self):
     f = File(prefix='shelftest')
     name = f.get_name()
     f.close()
     s = FileStorage(name)
     c = Connection(s)
     r = c.get_root()
     for x in range(10):
         r["a%s" % x] = Persistent()
         c.commit()
     deleted_oid = r['a9']._p_oid
     del r['a9']
     c.commit()
     c.pack()
     c.abort()
     r.clear()
     c.commit()
     c.pack()
     c.abort()
     new_oid = s.new_oid()
     assert new_oid == int8_to_str(1), repr(new_oid)
     new_oid = s.new_oid()
     assert new_oid == int8_to_str(2), repr(new_oid)
Пример #7
0
 def c(self):
     f = File(prefix='shelftest')
     name = f.get_name()
     f.close()
     s = FileStorage(name)
     c = Connection(s)
     r = c.get_root()
     for x in range(10):
         r["a%s" % x] = Persistent()
         c.commit()
     deleted_oid = r['a9']._p_oid
     del r['a9']
     c.commit()
     c.pack()
     c.abort()
     r.clear()
     c.commit()
     c.pack()
     c.abort()
     new_oid = s.new_oid()
     assert new_oid == int8_to_str(1), repr(new_oid)
     new_oid = s.new_oid()
     assert new_oid == int8_to_str(2), repr(new_oid)
Пример #8
0
 def a(self):
     f = File(prefix='shelftest')
     name = f.get_name()
     f.close()
     s = FileStorage(name)
     c = Connection(s)
     r = c.get_root()
     for x in range(10):
         r["a%s" % x] = Persistent()
         c.commit()
     deleted_oids = [
         r['a0']._p_oid, r['a2']._p_oid, r['a7']._p_oid, r['a8']._p_oid]
     del r['a0']
     del r['a2']
     del r['a7']
     del r['a8']
     c.commit()
     c.pack()
     c.abort()
     assert c.get(deleted_oids[0])._p_is_ghost()
     assert c.get(deleted_oids[1])._p_is_ghost()
     raises(ReadConflictError, getattr, c.get(deleted_oids[0]), 'a')
     assert len([repr(oid) for oid, record in s.gen_oid_record()]) == 7
     c.commit()
     c.pack()
     new_oid = s.new_oid()
     assert new_oid == deleted_oids[-1], (new_oid, deleted_oids)
     new_oid = s.new_oid()
     assert new_oid == deleted_oids[-2], (new_oid, deleted_oids)
     new_oid = s.new_oid()
     assert new_oid == deleted_oids[-3], (new_oid, deleted_oids)
     new_oid = s.new_oid()
     assert new_oid == deleted_oids[-4], (new_oid, deleted_oids)
     new_oid = s.new_oid()
     assert new_oid == int8_to_str(11), repr(new_oid)
     new_oid = s.new_oid()
     assert new_oid == int8_to_str(12), repr(new_oid)
Пример #9
0
def random_filename():
    f = File(prefix='schevodurus')
    n = f.get_name()
    f.close()
    return n