347
347
import new, sys, pickle
348
348
from BTrees.OOBTree import OOBTree
349
349
from ZODB.scripts import analyze
351
351
# Set up a module to act as a broken import
352
352
module_name = 'brokenmodule'
353
353
module = new.module(module_name)
354
354
sys.modules[module_name] = module
356
356
class Broken(MinPO):
357
357
__module__ = module_name
358
358
module.Broken = Broken
360
360
oids = [[self._storage.new_oid(), None] for i in range(3)]
361
361
for i in range(2):
362
362
t = transaction.Transaction()
363
363
self._storage.tpc_begin(t)
365
365
# sometimes data is in this format
367
367
oid, revid = oids[j]
368
serial = self._storage.store(oid, revid, pickle.dumps(OOBTree, 1), "", t)
368
serial = self._storage.store(
369
oid, revid, pickle.dumps(OOBTree, 1), "", t)
369
370
oids[j][1] = serial
371
372
# and it could be from a broken module
373
374
oid, revid = oids[j]
374
serial = self._storage.store(oid, revid, pickle.dumps(Broken, 1), "", t)
375
serial = self._storage.store(
376
oid, revid, pickle.dumps(Broken, 1), "", t)
375
377
oids[j][1] = serial
377
379
# but mostly it looks like this
384
386
self._storage.tpc_vote(t)
385
387
self._storage.tpc_finish(t)
387
389
# now break the import of the Broken class
388
390
del sys.modules[module_name]
390
392
# from ZODB.scripts.analyze.analyze
391
393
fsi = self._storage.iterator()
392
394
rep = analyze.Report()
394
396
analyze.analyze_trans(rep, txn)
396
398
# from ZODB.scripts.analyze.report
397
399
typemap = rep.TYPEMAP.keys()
400
402
for t in typemap:
401
403
pct = rep.TYPESIZE[t] * 100.0 / rep.DBYTES
404
self.assertAlmostEqual(cumpct, 100.0, 0, "Failed to analyze some records")
406
self.assertAlmostEqual(cumpct, 100.0, 0,
407
"Failed to analyze some records")
406
409
# Raise an exception if the tids in FileStorage fs aren't
407
410
# strictly increasing.