~ubuntu-branches/ubuntu/quantal/zodb/quantal

« back to all changes in this revision

Viewing changes to src/ZODB/tests/testFileStorage.py

  • Committer: Bazaar Package Importer
  • Author(s): Fabio Tranchitella, Brian Sutherland, Fabio Tranchitella
  • Date: 2010-01-05 22:22:35 UTC
  • mfrom: (6.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100105222235-z2xg4h60ru3e891t
Tags: 1:3.9.4-1
[ Brian Sutherland ]
* debian/tests/all: Test the correct python modules.

[ Fabio Tranchitella ]
* New upstream release.
* Convert to debhelper 7 and the pydeb dh7 extension.

Show diffs side-by-side

added added

removed removed

Lines of Context:
347
347
        import new, sys, pickle
348
348
        from BTrees.OOBTree import OOBTree
349
349
        from ZODB.scripts import analyze
350
 
        
 
350
 
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
355
 
        
 
355
 
356
356
        class Broken(MinPO):
357
357
            __module__ = module_name
358
358
        module.Broken = Broken
359
 
        
 
359
 
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)
364
 
            
 
364
 
365
365
            # sometimes data is in this format
366
366
            j = 0
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
370
 
            
 
371
 
371
372
            # and it could be from a broken module
372
373
            j = 1
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
376
 
            
 
378
 
377
379
            # but mostly it looks like this
378
380
            j = 2
379
381
            o = MinPO(j)
383
385
 
384
386
            self._storage.tpc_vote(t)
385
387
            self._storage.tpc_finish(t)
386
 
            
 
388
 
387
389
        # now break the import of the Broken class
388
390
        del sys.modules[module_name]
389
 
        
 
391
 
390
392
        # from ZODB.scripts.analyze.analyze
391
393
        fsi = self._storage.iterator()
392
394
        rep = analyze.Report()
393
395
        for txn in fsi:
394
396
            analyze.analyze_trans(rep, txn)
395
 
        
 
397
 
396
398
        # from ZODB.scripts.analyze.report
397
399
        typemap = rep.TYPEMAP.keys()
398
400
        typemap.sort()
400
402
        for t in typemap:
401
403
            pct = rep.TYPESIZE[t] * 100.0 / rep.DBYTES
402
404
            cumpct += pct
403
 
       
404
 
        self.assertAlmostEqual(cumpct, 100.0, 0, "Failed to analyze some records")
 
405
 
 
406
        self.assertAlmostEqual(cumpct, 100.0, 0,
 
407
                               "Failed to analyze some records")
405
408
 
406
409
# Raise an exception if the tids in FileStorage fs aren't
407
410
# strictly increasing.