From 6215ebd95e292ccad972e0c3ab9b9f4ab6b01aeb Mon Sep 17 00:00:00 2001 From: david-sarah Date: Sun, 31 Jan 2010 16:44:29 -0800 Subject: [PATCH] cli: suppress DeprecationWarnings emitted from importing nevow and twisted. Fixes #859 --- src/allmydata/__init__.py | 31 +++++++++++++++-- src/allmydata/test/test_runner.py | 57 +++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/src/allmydata/__init__.py b/src/allmydata/__init__.py index deebb080..1827adc8 100644 --- a/src/allmydata/__init__.py +++ b/src/allmydata/__init__.py @@ -6,6 +6,34 @@ maintainer web site: U{http://allmydata.com/} community web site: U{http://allmydata.org/} """ +# This is just to suppress DeprecationWarnings from nevow and twisted. +# See http://allmydata.org/trac/tahoe/ticket/859 and +# http://divmod.org/trac/ticket/2994 . +import warnings +warnings.filterwarnings("ignore", category=DeprecationWarning, + message="object.__new__\(\) takes no parameters", + append=True) +warnings.filterwarnings("ignore", category=DeprecationWarning, + message="The popen2 module is deprecated. Use the subprocess module.", + append=True) +warnings.filterwarnings("ignore", category=DeprecationWarning, + message="the md5 module is deprecated; use hashlib instead", + append=True) +warnings.filterwarnings("ignore", category=DeprecationWarning, + message="the sha module is deprecated; use the hashlib module instead", + append=True) +try: + import nevow + from twisted.persisted import sob + from twisted.python import filepath + hush_pyflakes = (nevow, sob, filepath) + del hush_pyflakes +finally: + warnings.filters.pop() + warnings.filters.pop() + warnings.filters.pop() + warnings.filters.pop() + __version__ = "unknown" try: from _version import __version__ @@ -27,9 +55,6 @@ except ImportError: # http://allmydata.org/trac/tahoe/wiki/Versioning __full_version__ = __appname__ + '/' + str(__version__) -hush_pyflakes = __version__ -del hush_pyflakes - import _auto_deps _auto_deps.require_auto_deps() diff --git a/src/allmydata/test/test_runner.py b/src/allmydata/test/test_runner.py index 4aef3da0..011f3fa2 100644 --- a/src/allmydata/test/test_runner.py +++ b/src/allmydata/test/test_runner.py @@ -355,6 +355,63 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin, return d test_introducer.timeout = 480 # This hit the 120-second timeout on "François Lenny-armv5tel", then it hit a 240-second timeout on our feisty2.5 buildslave: http://allmydata.org/buildbot/builders/feisty2.5/builds/2381/steps/test/logs/test.log + def test_client_no_noise(self): + self.skip_if_cannot_daemonize() + basedir = self.workdir("test_client_no_noise") + c1 = os.path.join(basedir, "c1") + HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline") + TWISTD_PID_FILE = os.path.join(c1, "twistd.pid") + PORTNUMFILE = os.path.join(c1, "client.port") + + d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ) + def _cb(res): + out, err, rc_or_sig = res + errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err) + assert rc_or_sig == 0, errstr + self.failUnlessEqual(rc_or_sig, 0) + # By writing this file, we get forty seconds before the client will exit. This insures + # that even if the 'stop' command doesn't work (and the test fails), the client should + # still terminate. + open(HOTLINE_FILE, "w").write("") + open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n") + # now it's safe to start the node + d.addCallback(_cb) + + def _start(res): + return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ) + d.addCallback(_start) + + def _cb2(res): + out, err, rc_or_sig = res + errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err) + open(HOTLINE_FILE, "w").write("") + self.failUnlessEqual(rc_or_sig, 0, errstr) + self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test. + self.failUnlessEqual(err, "", errstr) + + # the parent (twistd) has exited. However, twistd writes the pid + # from the child, not the parent, so we can't expect twistd.pid + # to exist quite yet. + + # the node is running, but it might not have made it past the + # first reactor turn yet, and if we kill it too early, it won't + # remove the twistd.pid file. So wait until it does something + # that we know it won't do until after the first turn. + d.addCallback(_cb2) + + def _node_has_started(): + return os.path.exists(PORTNUMFILE) + d.addCallback(lambda res: self.poll(_node_has_started)) + + # now we can kill it. TODO: On a slow machine, the node might kill + # itself before we get a chance too, especially if spawning the + # 'tahoe stop' command takes a while. + def _stop(res): + self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE)))) + return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ) + d.addCallback(_stop) + return d + def test_client(self): self.skip_if_cannot_daemonize() basedir = self.workdir("test_client") -- 2.45.2