mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-18 02:40:07 +00:00
tests: don't let bench_dirnode.py do stuff and have side-effects at import time (unless __name__ == '__main__')
This commit is contained in:
parent
a48979516e
commit
35efdf04ca
@ -1,6 +1,6 @@
|
|||||||
import hotshot.stats, os, random, sys
|
import hotshot.stats, os, random, sys
|
||||||
|
|
||||||
from pyutil import benchutil, randutil # http://allmydata.org/trac/pyutil
|
from pyutil import benchutil, randutil # http://tahoe-lafs.org/trac/pyutil
|
||||||
|
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
from allmydata import dirnode, uri
|
from allmydata import dirnode, uri
|
||||||
@ -8,9 +8,6 @@ from allmydata.interfaces import IFileNode
|
|||||||
from allmydata.mutable.filenode import MutableFileNode
|
from allmydata.mutable.filenode import MutableFileNode
|
||||||
from allmydata.immutable.filenode import ImmutableFileNode
|
from allmydata.immutable.filenode import ImmutableFileNode
|
||||||
|
|
||||||
children = [] # tuples of (k, v) (suitable for passing to dict())
|
|
||||||
packstr = None
|
|
||||||
|
|
||||||
class ContainerNode:
|
class ContainerNode:
|
||||||
implements(IFileNode)
|
implements(IFileNode)
|
||||||
# dirnodes sit on top of a "container" filenode, from which it extracts a
|
# dirnodes sit on top of a "container" filenode, from which it extracts a
|
||||||
@ -31,9 +28,6 @@ class FakeNodeMaker:
|
|||||||
def create_from_cap(self, writecap, readcap=None):
|
def create_from_cap(self, writecap, readcap=None):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
nodemaker = FakeNodeMaker()
|
|
||||||
testdirnode = dirnode.DirectoryNode(ContainerNode(), nodemaker, uploader=None)
|
|
||||||
|
|
||||||
def random_unicode(l):
|
def random_unicode(l):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -76,24 +70,31 @@ def random_metadata():
|
|||||||
def random_child():
|
def random_child():
|
||||||
return random_fsnode(), random_metadata()
|
return random_fsnode(), random_metadata()
|
||||||
|
|
||||||
def init_for_pack(N):
|
class B(object):
|
||||||
for i in xrange(len(children), N):
|
def __init__(self):
|
||||||
name = random_unicode(random.randrange(1, 9))
|
self.children = [] # tuples of (k, v) (suitable for passing to dict())
|
||||||
children.append( (name, random_child()) )
|
self.packstr = None
|
||||||
|
self.nodemaker = FakeNodeMaker()
|
||||||
|
self.testdirnode = dirnode.DirectoryNode(ContainerNode(), self.nodemaker, uploader=None)
|
||||||
|
|
||||||
def init_for_unpack(N):
|
def init_for_pack(self, N):
|
||||||
|
for i in xrange(len(self.children), N):
|
||||||
|
name = random_unicode(random.randrange(1, 9))
|
||||||
|
self.children.append( (name, random_child()) )
|
||||||
|
|
||||||
|
def init_for_unpack(self, N):
|
||||||
global packstr
|
global packstr
|
||||||
init_for_pack(N)
|
self.init_for_pack(N)
|
||||||
packstr = pack(N)
|
packstr = pack(N)
|
||||||
|
|
||||||
def pack(N):
|
def pack(self, N):
|
||||||
return testdirnode._pack_contents(dict(children[:N]))
|
return self.testdirnode._pack_contents(dict(self.children[:N]))
|
||||||
|
|
||||||
def unpack(N):
|
def unpack(self, N):
|
||||||
return testdirnode._unpack_contents(packstr)
|
return self.testdirnode._unpack_contents(self.packstr)
|
||||||
|
|
||||||
def unpack_and_repack(N):
|
def unpack_and_repack(self, N):
|
||||||
return testdirnode._pack_contents(testdirnode._unpack_contents(packstr))
|
return self.testdirnode._pack_contents(self.testdirnode._unpack_contents(packstr))
|
||||||
|
|
||||||
PROF_FILE_NAME="bench_dirnode.prof"
|
PROF_FILE_NAME="bench_dirnode.prof"
|
||||||
|
|
||||||
|
@ -524,7 +524,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
|
|||||||
def _cb(res):
|
def _cb(res):
|
||||||
out, err, rc_or_sig = res
|
out, err, rc_or_sig = res
|
||||||
self.failUnlessEqual(rc_or_sig, 1)
|
self.failUnlessEqual(rc_or_sig, 1)
|
||||||
self.failUnless("does not look like a node directory" in err)
|
self.failUnless("does not look like a node directory" in err, err)
|
||||||
d.addCallback(_cb)
|
d.addCallback(_cb)
|
||||||
|
|
||||||
def _then_stop_it(res):
|
def _then_stop_it(res):
|
||||||
|
Loading…
Reference in New Issue
Block a user