commit 5767d0e52ccf0cd569d030554c2ff54871a3864b Author: Isis Lovecruft isis@torproject.org Date: Wed Dec 5 14:32:08 2012 +0000
fixup! Added abort methods --- .gitignore | 1 + ooni/nettest.py | 47 ++++++++++++++++++++++++++--------------------- ooni/runner.py | 31 ++++++++++++++++--------------- ooniprobe.conf | 7 +++---- 4 files changed, 46 insertions(+), 40 deletions(-)
diff --git a/.gitignore b/.gitignore index d1015ab..4cb0775 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ pcaps/ report*.yaml docs/build/* data/*.dat +ooniprobe.conf diff --git a/ooni/nettest.py b/ooni/nettest.py index 139b4f4..9aa7a70 100644 --- a/ooni/nettest.py +++ b/ooni/nettest.py @@ -18,20 +18,8 @@ from twisted.trial import util as txtrutil from twisted.internet import defer, utils from twisted.python import usage
-from ooni import runner from ooni.utils import log
-# This needs to be here so that NetTestCase.abort() can call it, since we -# cannot import runner because runner imports NetTestCase. -def isTestCase(obj): - """ - Return True if obj is a subclass of NetTestCase, false if otherwise. - """ - try: - return issubclass(obj, NetTestCase) - except TypeError: - return False -
class NetTestCase(object): """ @@ -185,10 +173,10 @@ class NetTestCase(object):
def _getSkip(self): return txtrutil.acquireAttribute(self._parents, 'skip', None) - - #def _getSkipReason(self, method, skip): - # return super(TestCase, self)._getSkipReason(self, method, skip) - + + def _getSkipReason(self, method, skip): + return super(TestCase, self)._getSkipReason(self, method, skip) + def _getTimeout(self): """ Returns the timeout value set on this test. Check on the instance @@ -197,7 +185,10 @@ class NetTestCase(object): twisted.trial.util.DEFAULT_TIMEOUT_DURATION if it cannot find anything. See TestCase docstring for more details. """ - testMethod = getattr(self, methodName) + try: + testMethod = getattr(self, methodName) + except: + testMethod = self.setUp self._parents = [testMethod, self] self._parents.extend(txtrutil.getPythonContainers(testMethod)) timeout = txtrutil.acquireAttribute(self._parents, 'timeout', @@ -208,7 +199,7 @@ class NetTestCase(object): warnings.warn("'timeout' attribute needs to be a number.", category=DeprecationWarning) return txtrutil.DEFAULT_TIMEOUT_DURATION - + def _abort(self, reason, obj=None): """ Abort running an input, test_method, or test_class. If called with only @@ -218,7 +209,7 @@ class NetTestCase(object):
XXX call oreporter.allDone() from parent stack frame """ - reason = str(reason) # XXX should probably coerce + reason = str(reason) raise SkipTest("%s\n%s" % (str(reason), str(self.input)) )
def _abortMethod(self, reason, method): @@ -228,10 +219,10 @@ class NetTestCase(object): setattr(abort, 'skip', reason) else: log.debug("abortMethod(): could not find method %s" % str(method)) - + @log.catch def _abortClass(self, reason, cls): - if not inspect.isclass(obj) or not runner.isTestCase(obj): + if not inspect.isclass(obj) or not isTestCase(obj): log.debug("_abortClass() could not find class %s" % str(cls)) return abort = getattr(obj, '__class__', self.__class__) @@ -248,3 +239,17 @@ class NetTestCase(object):
def abortInput(self, reason): return self._abort(reason) + + +# This needs to be here so that NetTestCase.abort() can call it, since we +# cannot import runner because runner imports NetTestCase. +def isTestCase(obj): + """ + Return True if obj is a subclass of NetTestCase, false if otherwise. + """ + try: + return issubclass(obj, NetTestCase) + except TypeError: + return False + + diff --git a/ooni/runner.py b/ooni/runner.py index b6de21e..1895d8b 100644 --- a/ooni/runner.py +++ b/ooni/runner.py @@ -19,13 +19,12 @@ from twisted.python import reflect, usage, failure from twisted.internet import defer from twisted.trial.runner import filenameToModule from twisted.trial import util as txtrutil +from twisted.trial import reporter as txreporter +from twisted.trial.unittest import utils as txtrutils from twisted.internet import reactor, threads
from ooni.inputunit import InputUnitFactory -from ooni.nettest import NetTestCase, isTestCase - -from ooni import reporter - +from ooni import reporter, nettest from ooni.utils import log, checkForRoot, PermissionsError
def processTest(obj, cmd_line_options): @@ -112,7 +111,7 @@ def findTestClassesFromConfig(cmd_line_options):
module = filenameToModule(filename) for name, val in inspect.getmembers(module): - if isTestCase(val): + if nettest.isTestCase(val): classes.append(processTest(val, cmd_line_options)) return classes
@@ -165,15 +164,15 @@ def abortTestWasCalled(abort_reason, abort_what, test_class, test_instance, if abort_what == 'input': log.msg("%s test requested to abort for input: %s" % (test_instance.name, test_input)) - d = maybeDeferred() + d = defer.maybeDeferred(lambda x: object)
if hasattr(test_instance, "abort_all"): log.msg("%s test requested to abort all remaining inputs" % test_instance.name) - else: - d = defer.Deferred() - d.cancel() - d = abortTestRun(test_class, reason, test_input, oreporter) + #else: + # d = defer.Deferred() + # d.cancel() + # d = abortTestRun(test_class, reason, test_input, oreporter)
def runTestWithInput(test_class, test_method, test_input, oreporter): @@ -198,9 +197,9 @@ def runTestWithInput(test_class, test_method, test_input, oreporter): reactor.crash() test_instance._timedOut = True # see test_instance._wait # XXX result is TestResult utils? - RESULT.addExpectedFailure(test_instance, fail) - test_timeout = utils.suppressWarnings( - test_timeout, util.suppress(category=DeprecationWarning)) + test_instance._test_result.addExpectedFailure(test_instance, fail) + test_timeout = txtrutils.suppressWarnings( + test_timeout, txtrutil.suppress(category=DeprecationWarning))
def test_done(result, test_instance, test_name): log.debug("runTestWithInput: concluded %s" % test_name) @@ -216,15 +215,17 @@ def runTestWithInput(test_class, test_method, test_input, oreporter): # use this to keep track of the test runtime test_instance._start_time = time.time() test_instance.timeout = test_instance._getTimeout() + test_instance._test_result = txreporter.TestResult() # call setups on the test test_instance._setUp() test_instance.setUp() - test_ignored = util.acquireAttribute(test_instance._parents, 'skip', None) + test_ignored = txtrutil.acquireAttribute(test_instance._parents, + 'skip', None)
test = getattr(test_instance, test_method)
# check if we've aborted - test_skip = test.getSkip() + test_skip = test_instance._getSkip() if test_skip is not None: log.debug("%s.getSkip() returned %s" % (str(test_class), str(test_skip)) ) diff --git a/ooniprobe.conf b/ooniprobe.conf index e3a7198..595cc76 100644 --- a/ooniprobe.conf +++ b/ooniprobe.conf @@ -9,9 +9,6 @@ privacy: # Should we include the client's IP address of the probe in the report? # (Client IP is obtained by an HTTP request to https://check.torproject.org) includeip: false - # If we're including the client's IP address, how long should we wait for - # the connection to complete before timing out? - checktimeout: 15 # Should we include the ASN of the probe in the report? includeasn: false # Should we include the ASN of the probe in the report? @@ -28,4 +25,6 @@ advanced: geoip_data_dir: /home/x/code/networking/ooni-probe/data/ debug: true threadpool_size: 10 - # Connection timeout in seconds for \ No newline at end of file + # If we're including the client's IP address, how long should we wait for + # the connection to complete before timing out? + checktimeout: 15