From: Zooko O'Whielacronx Date: Fri, 21 May 2010 12:20:52 +0000 (-0700) Subject: tests: don't let bench_dirnode.py do stuff and have side-effects at import time ... X-Git-Url: https://git.rkrishnan.org/vdrive/%22news.html/module-simplejson.tests.html?a=commitdiff_plain;h=35efdf04ca003dcda01a1178f0cf7b77dc89763e;p=tahoe-lafs%2Ftahoe-lafs.git tests: don't let bench_dirnode.py do stuff and have side-effects at import time (unless __name__ == '__main__') --- diff --git a/src/allmydata/test/bench_dirnode.py b/src/allmydata/test/bench_dirnode.py index e5a47f80..48328880 100644 --- a/src/allmydata/test/bench_dirnode.py +++ b/src/allmydata/test/bench_dirnode.py @@ -1,6 +1,6 @@ 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 allmydata import dirnode, uri @@ -8,9 +8,6 @@ from allmydata.interfaces import IFileNode from allmydata.mutable.filenode import MutableFileNode from allmydata.immutable.filenode import ImmutableFileNode -children = [] # tuples of (k, v) (suitable for passing to dict()) -packstr = None - class ContainerNode: implements(IFileNode) # 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): return None -nodemaker = FakeNodeMaker() -testdirnode = dirnode.DirectoryNode(ContainerNode(), nodemaker, uploader=None) - def random_unicode(l): while True: try: @@ -76,24 +70,31 @@ def random_metadata(): def random_child(): return random_fsnode(), random_metadata() -def init_for_pack(N): - for i in xrange(len(children), N): - name = random_unicode(random.randrange(1, 9)) - children.append( (name, random_child()) ) +class B(object): + def __init__(self): + self.children = [] # tuples of (k, v) (suitable for passing to dict()) + self.packstr = None + self.nodemaker = FakeNodeMaker() + self.testdirnode = dirnode.DirectoryNode(ContainerNode(), self.nodemaker, uploader=None) + + 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(N): - global packstr - init_for_pack(N) - packstr = pack(N) + def init_for_unpack(self, N): + global packstr + self.init_for_pack(N) + packstr = pack(N) -def pack(N): - return testdirnode._pack_contents(dict(children[:N])) + def pack(self, N): + return self.testdirnode._pack_contents(dict(self.children[:N])) -def unpack(N): - return testdirnode._unpack_contents(packstr) + def unpack(self, N): + return self.testdirnode._unpack_contents(self.packstr) -def unpack_and_repack(N): - return testdirnode._pack_contents(testdirnode._unpack_contents(packstr)) + def unpack_and_repack(self, N): + return self.testdirnode._pack_contents(self.testdirnode._unpack_contents(packstr)) PROF_FILE_NAME="bench_dirnode.prof" diff --git a/src/allmydata/test/test_runner.py b/src/allmydata/test/test_runner.py index c88657d4..b543ecdb 100644 --- a/src/allmydata/test/test_runner.py +++ b/src/allmydata/test/test_runner.py @@ -524,7 +524,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin, def _cb(res): out, err, rc_or_sig = res 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) def _then_stop_it(res):