[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Port Netalyzr test to new API



commit f5bfad914eeb18dd104aaf44baa58a6502947074
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date:   Tue Oct 23 10:01:49 2012 +0000

    Port Netalyzr test to new API
    * Make new generation tests work properly
---
 nettests/third_party/netalyzr.py |   10 +++++-----
 ooni/nettest.py                  |    5 +++--
 ooni/oonicli.py                  |   11 ++++++-----
 ooni/reporter.py                 |    9 ++++-----
 ooni/runner.py                   |   11 +++++------
 5 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/nettests/third_party/netalyzr.py b/nettests/third_party/netalyzr.py
index 041c0be..bf94000 100644
--- a/nettests/third_party/netalyzr.py
+++ b/nettests/third_party/netalyzr.py
@@ -13,15 +13,14 @@ import os
 
 class NetalyzrWrapperTest(nettest.TestCase):
     name = "NetalyzrWrapper"
-    type = "wrapper"
 
     def setUp(self):
-        cwd = os.path.join(os.path.abspath(__file__), '..')
+        cwd = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))
 
         # XXX set the output directory to something more uniform
         outputdir = os.path.join(cwd, '..', '..')
 
-        program_path = os.path.join(cwd, 'NetalyzrCLI')
+        program_path = os.path.join(cwd, 'NetalyzrCLI.jar')
         program = "java -jar %s " % program_path
 
         test_token = time.asctime(time.gmtime()).replace(" ", "_").strip()
@@ -35,8 +34,9 @@ class NetalyzrWrapperTest(nettest.TestCase):
         """
         This test simply wraps netalyzr and runs it from command line
         """
-        log.msg("running NetalyzrWrapper with command '%s'" % self.run_me)
+        log.msg("Running NetalyzrWrapper (this will take some time, be patient)")
+        log.debug("with command '%s'" % self.run_me)
         os.system(self.run_me)
         self.report['netalyzr_report'] = self.output_file
-        log.msg("finished running NetalzrWrapper")
+        log.debug("finished running NetalzrWrapper")
 
diff --git a/ooni/nettest.py b/ooni/nettest.py
index 768833a..d35bd4d 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -1,9 +1,9 @@
 import itertools
 import os
 
-from twisted.python import log, usage
 from twisted.trial import unittest, itrial
 from twisted.internet import defer, utils
+from ooni.utils import log
 
 pyunit = __import__('unittest')
 
@@ -79,9 +79,10 @@ class TestCase(unittest.TestCase):
 
     optParameters = None
 
-    def _run(self, methodName, result):
+    def _raaun(self, methodName, result):
         from twisted.internet import reactor
         method = getattr(self, methodName)
+        log.debug("Running %s" % methodName)
         d = defer.maybeDeferred(
                 utils.runWithWarningsSuppressed, self._getSuppress(), method)
         d.addBoth(lambda x : call.active() and call.cancel() or x)
diff --git a/ooni/oonicli.py b/ooni/oonicli.py
index ef80c33..5ea92d7 100644
--- a/ooni/oonicli.py
+++ b/ooni/oonicli.py
@@ -26,7 +26,7 @@ from ooni import nettest, runner, reporter
 
 from twisted.internet import defer
 from twisted.application import app
-from twisted.python import usage, reflect, failure, log
+from twisted.python import usage, reflect, failure
 from twisted.python.filepath import FilePath
 from twisted import plugin
 from twisted.python.util import spewer
@@ -34,6 +34,8 @@ from twisted.python.compat import set
 from twisted.trial import itrial
 from twisted.trial import runner as irunner
 
+from ooni.utils import log
+
 class Options(usage.Options, app.ReactorSelectionMixin):
     synopsis = """%s [options] [[file|package|module|TestCase|testmethod]...]
     """ % (os.path.basename(sys.argv[0]),)
@@ -90,6 +92,9 @@ class Options(usage.Options, app.ReactorSelectionMixin):
 
 
 def run():
+    log.start()
+    log.debug("Started logging")
+
     if len(sys.argv) == 1:
         sys.argv.append("--help")
     config = Options()
@@ -101,10 +106,6 @@ def run():
     if config['debug-stacktraces']:
         defer.setDebugging(True)
 
-    #logFile = open(config['logfile'], 'w')
-    #logFileObserver = log.FileLogObserver(logFile)
-    #log.startLoggingWithObserver(logFileObserver.emit, 0)
-
     classes = runner.findTestClassesFromConfig(config)
     casesList, options = runner.loadTestsAndOptions(classes, config)
 
diff --git a/ooni/reporter.py b/ooni/reporter.py
index fd64cbe..a7b645b 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -132,7 +132,8 @@ class ReporterFactory(OReporter):
         client_geodata = {}
         log.msg("Running geo IP lookup via check.torproject.org")
 
-        client_ip = yield geodata.myIP()
+        #client_ip = yield geodata.myIP()
+        client_ip = '127.0.0.1'
         try:
             import txtorcon
             client_location = txtorcon.util.NetLocation(client_ip)
@@ -209,10 +210,8 @@ class OONIReporter(OReporter):
             test_input = test.input
 
         self._tests[idx]['input'] = test_input
-        #self._tests[idx]['idx'] = idx
         self._tests[idx]['name'] = test.name
-        #self._tests[idx]['test'] = test
-        print "Now starting %s" % self._tests[idx]
+        log.debug("Now starting %s" % self._tests[idx])
 
 
     def stopTest(self, test):
@@ -230,7 +229,7 @@ class OONIReporter(OReporter):
             #     actually end up with the report I want. This could either be a
             #     python bug or a yaml bug.
             report = dict(test.report)
-
+        log.debug("Adding to report %s" % report)
         self._tests[idx]['report'] = report
 
 
diff --git a/ooni/runner.py b/ooni/runner.py
index 1fbc4fe..b5c33a0 100644
--- a/ooni/runner.py
+++ b/ooni/runner.py
@@ -49,10 +49,7 @@ def isLegacyTest(obj):
     We do this for backward compatibility of the OONIProbe API.
     """
     try:
-        if issubclass(obj, oonitests.OONITest) and not obj == oonitests.OONITest:
-                return True
-        else:
-            return False
+        return issubclass(obj, oonitests.OONITest) and not obj == oonitests.OONITest
     except TypeError:
         return False
 
@@ -116,8 +113,10 @@ def findTestClassesFromConfig(config):
     module = filenameToModule(filename)
     for name, val in inspect.getmembers(module):
         if isTestCase(val):
+            log.debug("Detected TestCase %s" % val)
             classes.append(processTest(val, config))
         elif isLegacyTest(val):
+            log.debug("Detected Legacy Test %s" % val)
             classes.append(adapt_legacy_test(val, config))
     return classes
 
@@ -200,7 +199,8 @@ class ORunner(object):
             try:
                 first = options.pop(0)
             except:
-                first = {}
+                first = options
+
             if 'inputs' in first:
                 self.inputs = options['inputs']
             else:
@@ -238,7 +238,6 @@ class ORunner(object):
         result.done()
 
     def run(self):
-        log.start()
         self.reporterFactory.options = self.options
         for inputUnit in InputUnitFactory(self.inputs):
             self.runWithInputUnit(inputUnit)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits