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

[tor-commits] [ooni-probe/master] Properly accept assets when running tests



commit 6306a4e3b5670cd68fd450cd9ed39f88c2b528ac
Author: Arturo Filastò <hellais@xxxxxxxxxxxxxx>
Date:   Wed May 2 22:14:37 2012 +0200

    Properly accept assets when running tests
---
 oonicli.py      |   20 ++++++++++----------
 plugins/skel.py |    2 +-
 plugoo/tests.py |    6 ++++--
 plugoo/work.py  |   42 +++++++++++++++++++++++-------------------
 4 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/oonicli.py b/oonicli.py
index 0a9c1cc..c2d01d2 100755
--- a/oonicli.py
+++ b/oonicli.py
@@ -9,7 +9,7 @@
 #
 
 import sys
-from plugoo import tests, work
+from plugoo import tests, work, assets
 
 from twisted.python import usage
 from twisted.plugin import getPlugins
@@ -62,20 +62,20 @@ class StupidAsset(object):
         self.idx += 1
         return self.idx
 
+
 def runTest(test, options):
-    pprint(test)
-    wgen = work.WorkGenerator(StupidAsset, plugoo[test].__class__,
-            dict(options),
-            start=options['resume'])
+    asset = None
+    if options['asset']:
+        print options['asset']
+        asset = assets.Asset(options['asset'])
+        print asset
+
+    wgen = work.WorkGenerator(asset, plugoo[test].__class__,
+            dict(options), start=options['resume'])
 
     worker = work.Worker()
     for x in wgen:
-        print "------"
-        print "Work unit"
-        print "------"
-        print x.serialize()
         worker.push(x)
-        print "------"
 
     reactor.run()
 
diff --git a/plugins/skel.py b/plugins/skel.py
index 41420b1..0427239 100644
--- a/plugins/skel.py
+++ b/plugins/skel.py
@@ -4,7 +4,7 @@ from twisted.plugin import IPlugin
 from plugoo.tests import ITest, TwistedTest
 
 class SkelArgs(usage.Options):
-    optParameters = [['assets', 'a', None, 'Asset file'],
+    optParameters = [['asset', 'a', None, 'Asset file'],
                      ['resume', 'r', 0, 'Resume at this index']]
 
 class SkelTest(TwistedTest):
diff --git a/plugoo/tests.py b/plugoo/tests.py
index 41363ee..e74586c 100644
--- a/plugoo/tests.py
+++ b/plugoo/tests.py
@@ -171,10 +171,11 @@ class TwistedTest(object):
         #self.ooninet = ooninet
 
     def __repr__(self):
-        return "<TwistedTest %s %s %s>" % (self.arguments, self.asset, self.node)
+        return "<TwistedTest %s %s>" % (self.arguments, self.asset)
 
     def finished(self, result):
         #self.ooninet.report(result)
+        print "FINIHSED"
         self.end_time = datetime.now()
         result['start_time'] = self.start_time
         result['end_time'] = self.end_time
@@ -182,6 +183,7 @@ class TwistedTest(object):
         return self.d.callback(result)
 
     def startTest(self):
+        print "Starting test"
         self.d = defer.Deferred()
         result = {}
         reactor.callLater(2.0, self.finished, result)
@@ -189,7 +191,7 @@ class TwistedTest(object):
 
 class TwistedTestFactory(object):
 
-    test = StupidTest
+    test = None
 
     def __init__(self, assets, node,
                  idx=0):
diff --git a/plugoo/work.py b/plugoo/work.py
index 809e9bd..7be4758 100644
--- a/plugoo/work.py
+++ b/plugoo/work.py
@@ -31,13 +31,10 @@ class Worker(object):
         self._queued = []
 
     def _run(self, r):
-        print "RUNNING"
         self._running -= 1
         if self._running < self.maxconcurrent and self._queued:
             workunit, d = self._queued.pop(0)
             for work in workunit:
-                print "Going over workunits bis"
-                print work
                 self._running += 1
                 actuald = work.startTest().addBoth(self._run)
         if isinstance(r, failure.Failure):
@@ -51,11 +48,8 @@ class Worker(object):
         return r
 
     def push(self, workunit):
-        print "PUSHING"
         if self._running < self.maxconcurrent:
             for work in workunit:
-                print "Going over work units"
-                print dir(work)
                 self._running += 1
                 work.startTest().addBoth(self._run)
             return
@@ -83,11 +77,13 @@ class WorkUnit(object):
     test = None
     arguments = None
 
-    def __init__(self, node, asset, test, idx, arguments=None):
+    def __init__(self, asset, test, idx, arguments=None):
         self.asset = asset
-        self.assetGenerator = iter(asset)
+        if not asset:
+            self.assetGenerator = iter([1])
+        else:
+            self.assetGenerator = iter(asset)
         self.Test = test
-        self.node = node
         self.arguments = arguments
         self.idx = idx
 
@@ -109,14 +105,9 @@ class WorkUnit(object):
         """
         try:
             asset = self.assetGenerator.next()
-            print "Next shit.."
-            print asset
             ret = self.Test(asset, self.arguments)
-            print type(ret)
-            print repr(ret)
             return ret
         except StopIteration:
-            print "Stopped iteration!"
             raise StopIteration
 
 
@@ -127,14 +118,14 @@ class WorkGenerator(object):
     This shall be run on the machine running OONI-cli. The returned WorkUnits
     can either be run locally or on a remote OONI Node or Network Node.
     """
-    node = LocalNode
     size = 10
 
     def __init__(self, asset, test, arguments=None, start=None):
-        self.assetGenerator = asset()
+        self.assetGenerator = asset
         self.Test = test
         self.arguments = arguments
         self.idx = 0
+        self.end = False
         if start:
             self.skip(start)
 
@@ -148,11 +139,24 @@ class WorkGenerator(object):
             self.idx += 1
 
     def next(self):
+        if self.end:
+            raise StopIteration
+
+        if not self.assetGenerator:
+            self.end = True
+            return WorkUnit(None, self.Test, self.idx, self.arguments)
+
         # Plank asset
         p_asset = []
         for i in xrange(0, self.size):
-            p_asset.append(self.assetGenerator.next())
-        self.idx += 1
-        return WorkUnit(self.node, p_asset, self.Test, self.idx, self.arguments)
+            try:
+                asset = self.assetGenerator.next()
+                p_asset.append(asset)
+                print asset
+            except StopIteration:
+                self.end = True
+                break
 
+        self.idx += 1
+        return WorkUnit(p_asset, self.Test, self.idx, self.arguments)
 



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