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

[tor-commits] [ooni-probe/master] Refactor reporting system



commit cf72e20df6fb9271f415984c65c7026f26f56325
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Thu Nov 8 16:08:57 2012 +0100

    Refactor reporting system
    * Fix import error in http host test
---
 nettests/core/http_host.py |    1 +
 nettests/simpletest.py     |    2 +-
 ooni/nettest.py            |    4 +++-
 ooni/reporter.py           |   31 ++++++++++++-------------------
 ooni/runner.py             |   11 ++++++++---
 5 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/nettests/core/http_host.py b/nettests/core/http_host.py
index 137d3b8..e09fc84 100644
--- a/nettests/core/http_host.py
+++ b/nettests/core/http_host.py
@@ -9,6 +9,7 @@
 # :authors: Arturo Filastò
 # :licence: see LICENSE
 
+from twisted.python import usage
 from ooni.templates import httpt
 
 class UsageOptions(usage.Options):
diff --git a/nettests/simpletest.py b/nettests/simpletest.py
index a83b8ce..11bd485 100644
--- a/nettests/simpletest.py
+++ b/nettests/simpletest.py
@@ -1,6 +1,6 @@
 from ooni import nettest
 class SimpleTest(nettest.NetTestCase):
-    inputs = range(1,100)
+    inputs = range(1,20)
     optParameters = [['asset', 'a', None, 'Asset file'],
                      ['controlserver', 'c', 'google.com', 'Specify the control server'],
                      ['resume', 'r', 0, 'Resume at this index'],
diff --git a/ooni/nettest.py b/ooni/nettest.py
index a8d3560..83c5727 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -47,10 +47,12 @@ class InputTestSuite(pyunit.TestSuite):
                           "running is not a nettest")
                 log.debug(e)
 
-            log.debug("Running test")
+            log.debug("Running test with name %s" % str(test))
             # XXX we may want in a future to put all of these tests inside of a
             # thread pool and run them all in parallel
             test(result)
+            # Here we need to set the test name to be that of the test case we are running
+            result._tests[self._idx]['test'] = str(test)
             log.debug("Ran.")
 
             self._idx += 1
diff --git a/ooni/reporter.py b/ooni/reporter.py
index 6fab5f9..c9654e8 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -156,10 +156,10 @@ class OReporter(pyunit.TestResult):
         self._write(format_string, *args)
         self._write('\n')
 
-    def writeYamlLine(self, line):
-        to_write = safe_dump([line])
-        self._write(to_write)
-
+    def writeReportEntry(self, entry):
+        self._write('---\n')
+        self._write(safe_dump(entry))
+        self._write('...\n')
 
 class ReporterFactory(OReporter):
     """
@@ -224,8 +224,7 @@ class ReporterFactory(OReporter):
                         'test_version': options['version'],
                         }
 
-        self.writeYamlLine(test_details)
-        self._writeln('')
+        self.writeReportEntry(test_details)
 
     def create(self):
         r = OONIReporter(self._stream, self.tbformat, self.realtime,
@@ -265,7 +264,7 @@ class OONIReporter(OReporter):
         if not self._startTime:
             self._startTime = self._getTime()
 
-        log.debug("Starting test %s" % idx)
+        log.debug("startTest on %s" % idx)
         test.report = {}
 
         self._tests[idx] = {}
@@ -277,17 +276,15 @@ class OONIReporter(OReporter):
             test_input = test.input
 
         self._tests[idx]['input'] = test_input
-        self._tests[idx]['name'] = test.name
         log.debug("Now starting %s" % self._tests[idx])
 
-
     def stopTest(self, test):
         log.debug("Stopping test")
         super(OONIReporter, self).stopTest(test)
 
         idx = self.getTestIndex(test)
 
-        self._tests[idx]['last_time'] = self._getTime() - \
+        self._tests[idx]['runtime'] = self._getTime() - \
                                         self._tests[idx]['test_started']
 
         # XXX I put a dict() here so that the object is re-instantiated and I
@@ -313,15 +310,11 @@ class OONIReporter(OReporter):
         and L{_separator} are all implemented.
         """
         log.debug("Test run concluded")
-        if self._startTime is not None:
-            self.report['start_time'] = self._startTime
-            self.report['run_time'] = time.time() - self._startTime
-            self.report['tests_run'] = self.testsRun
-        self.report['tests'] = self._tests
-        self.writeReport()
-
-    def writeReport(self):
-        self.writeYamlLine(self.report)
+        self.writeTestsReport(self._tests)
+
+    def writeTestsReport(self, tests):
+        for test in tests.values():
+            self.writeReportEntry(test)
 
     def addSuccess(self, test):
         OReporter.addSuccess(self, test)
diff --git a/ooni/runner.py b/ooni/runner.py
index b4d9560..6ed89ab 100644
--- a/ooni/runner.py
+++ b/ooni/runner.py
@@ -170,12 +170,17 @@ class ORunner(object):
                 log.msg("Could not find inputs!")
                 log.msg("options[0] = %s" % first)
                 self.inputs = [None]
+        if cmd_line_options['reportfile']:
+            report_filename = cmd_line_options['reportfile']
+        else:
+            report_filename = 'report_'+date.timestamp()+'.yamloo'
 
+        if os.path.exists(report_filename):
+            os.rename(report_filename, report_filename+'.1')
         try:
-            reportFile = open(cmd_line_options['reportfile'], 'a+')
+            reportFile = open(report_filename, 'w+')
         except TypeError:
-            filename = 'report_'+date.timestamp()+'.yaml'
-            reportFile = open(filename, 'a+')
+            reportFile = open(filename_filename, 'w+')
         self.reporterFactory = ReporterFactory(reportFile,
                                                testSuite=self.baseSuite(self.cases))
 



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