Commit c21c3730 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 4f7db880
#!/usr/bin/env python2 #!/usr/bin/env python2
"""generate reference index and database for tests""" """generate reference index and database for tests"""
import ZODB from ZODB.FileStorage import FileStorage
import persistent from ZODB import DB
from persistent import Persistent
import transaction import transaction
import struct
import random
import logging
# convert numeric oid to str
def oid(v):
return struct.pack('>Q', v)
def commit(user, description, extension): def commit(user, description, extension):
txn = transaction.get() txn = transaction.get()
txn.user = user txn.user = user
...@@ -12,22 +21,40 @@ def commit(user, description, extension): ...@@ -12,22 +21,40 @@ def commit(user, description, extension):
txn.extension = extension txn.extension = extension
txn.commit() txn.commit()
class Object(Persistent):
# .value
def __init__(self, value):
self.value = value
def __getstate__(self):
return self.value
def __setstate__(self, state):
self.value = state
def main(): def main():
logging.basicConfig()
stor = FileStorage("testdata/1.fs", create=True) stor = FileStorage("testdata/1.fs", create=True)
db = DB(stor) db = DB(stor)
conn = db.open() conn = db.open()
root = conn.root() root = conn.root()
commit(u"root", u"initial database creation", {"x-generator": "zodb/py2"}) assert root._p_oid == oid(0), `root._p_oid`
""" # generate random changes to objects hooked to top-level root by a/b/c/... key
root["..."] = obj random.seed(0)
namev = [_ for _ in "abcdefg"]
for i in range(50):
name = random.choice(namev)
if name in root:
obj = root[name]
else:
root[name] = obj = Object(None)
txn = transaction.get() obj.value = "%s%i" % (name, i)
txn.user = u"user1" # XXX
txn.description = u"description1" # XXX commit(u"user%i" % i, u"step %i" % i, {"x-generator": "zodb/py2 (%s)" % name})
txn.extension = {"key1": value1, "key2": value2) # XXX
txn.commit()
"""
conn.close() conn.close()
db.close() db.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment