[tor-commits] [ooni-probe/master] Add script to allow fast scaffolding of tests

art at torproject.org art at torproject.org
Thu May 31 03:01:43 UTC 2012


commit 66b806472e57f8be90b0b94b5b4354677ec7102f
Author: Arturo Filastò <hellais at torproject.org>
Date:   Thu May 31 03:32:24 2012 +0200

    Add script to allow fast scaffolding of tests
---
 ooni/plugins/scaffolding.py |   66 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/ooni/plugins/scaffolding.py b/ooni/plugins/scaffolding.py
new file mode 100755
index 0000000..fb7002d
--- /dev/null
+++ b/ooni/plugins/scaffolding.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+"""
+This script should be used for creating the scaffolding for a test.
+"""
+import os
+import sys
+
+test_template = """\"\"\"
+This is a self genrated test created by scaffolding.py.
+you will need to fill it up with all your necessities.
+Safe hacking :).
+\"\"\"
+from zope.interface import implements
+from twisted.python import usage
+from twisted.plugin import IPlugin
+from plugoo.tests import ITest, TwistedTest
+
+class %(testName)sArgs(usage.Options):
+    optParameters = [['asset', 'a', None, 'Asset file'],
+                     ['resume', 'r', 0, 'Resume at this index']]
+
+class %(testName)sTest(TwistedTest):
+    implements(IPlugin, ITest)
+
+    shortName = "%(testShortname)s"
+    description = "%(testName)s"
+    requirements = None
+    options = %(testName)sArgs
+    blocking = True
+
+    def control(self, experiment_result, args):
+        # What you return here ends up inside of the report.
+        return {}
+
+    def experiment(self, args):
+        # What you return here gets handed as input to control
+        return {}
+
+    def load_assets(self):
+        if self.local_options:
+            return {'asset': Asset(self.local_options['asset'])}
+        else:
+            return {}
+
+# We need to instantiate it otherwise getPlugins does not detect it
+# XXX Find a way to load plugins without instantiating them.
+%(testShortname)s = %(testName)sTest(None, None, None)
+"""
+
+test_vars = {'testName': None, 'testShortname': None}
+test_vars['testName'] = raw_input('Test Name: ')
+test_vars['testShortname'] = raw_input("Test Short Name: ")
+
+fname = test_vars['testShortname']+'.py'
+
+if os.path.exists(fname):
+    print 'WARNING! File named "%s" already exists.' % fname
+    if raw_input("Do you wish to continue (y/N)? ").lower() != 'y':
+        print "gotcha! Dying.."
+        sys.exit(0)
+
+fp = open(fname, 'w')
+fp.write(test_template % test_vars)
+fp.close()
+





More information about the tor-commits mailing list