Commit c20bc635 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/*: Fix Python database generators to work with ZODB5 + preserve DB compatibility with ZODB3

Paralleling zodbtools@0b6f99da.

All test databases in */testdata/ stay as before bit-to-bit the same.
parent 84845c97
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Copyright (C) 2018 Nexedi SA and Contributors.
# Copyright (C) 2018-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
......@@ -23,6 +23,7 @@
from ZODB.DB import DB
from BTrees.LOBTree import LOBucket, LOBTree
from ZODB.utils import u64
from zodbtools.test.gen_testdata import run_with_zodb3py2_compat
import os, os.path, transaction
from golang.gcompat import qq
......@@ -31,7 +32,7 @@ def rm_f(path):
if os.path.exists(path):
os.remove(path)
def main():
def main2():
import zodbtools.test.gen_testdata # to make time predictable (XXX)
outfs = "testdata/1.fs"
......@@ -87,6 +88,9 @@ def main():
conn.close()
db.close()
def main():
run_with_zodb3py2_compat(main2)
if __name__ == '__main__':
main()
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Copyright (C) 2017-2018 Nexedi SA and Contributors.
# Copyright (C) 2017-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
......@@ -20,11 +20,14 @@
# See https://www.nexedi.com/licensing for rationale and options.
"""generate reference pickle objects encoding for tests"""
from ZODB.tests import testSerialize
from ZODB import serialize
from zodbtools.test.gen_testdata import run_with_zodb3py2_compat
from golang.gcompat import qq
def main():
def main2():
# import ZODB.tests at runtime after ZODB.X._protocol is patched
from ZODB.tests import testSerialize
# dump to go what to expect
with open("ztestdata_pydata_test.go", "w") as f:
def emit(v):
......@@ -52,5 +55,8 @@ def main():
emit('\t{"aaa", "?.?"},') # invalid
emit("}")
def main():
run_with_zodb3py2_compat(main2)
if __name__ == '__main__':
main()
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Copyright (C) 2017-2019 Nexedi SA and Contributors.
# Copyright (C) 2017-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
......@@ -22,7 +22,8 @@
from ZODB.FileStorage import FileStorage
from ZODB import DB
from zodbtools.test.gen_testdata import gen_testdb, precommit
from ZODB.Connection import TransactionMetaData
from zodbtools.test.gen_testdata import gen_testdb, precommit, run_with_zodb3py2_compat
from os import stat, remove
from shutil import copyfile
from golang.gcompat import qq
......@@ -142,6 +143,7 @@ def main():
# prepare file with voted (not fully committed) tail
voted = "testdata/1voted.fs"
copyfile(outfs, voted)
def _():
vstor = FileStorage(voted)
vdb = DB(vstor)
vconn = vdb.open()
......@@ -149,10 +151,12 @@ def main():
vroot._p_activate() # to know its current serial
txn = precommit(u"author", u"description", {'aaa': 'bbb'})
vstor.tpc_begin(txn)
vstor.store(vroot._p_oid, vroot._p_serial, '000 data 000', '', txn)
vstor.tpc_vote(txn)
txn_stormeta = TransactionMetaData(txn.user, txn.description, txn.extension)
vstor.tpc_begin(txn_stormeta)
vstor.store(vroot._p_oid, vroot._p_serial, '000 data 000', '', txn_stormeta)
vstor.tpc_vote(txn_stormeta)
# NO tpc_finish here so that status remain 'c' (voted) instead of ' ' (committed)
run_with_zodb3py2_compat(_)
st = stat(outfs)
l = st.st_size
......
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