[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Get test version from net_test_file and parse all options
commit 2da452336aeb1eac53809305661ba727d8daef7c
Author: aagbsn <aagbsn@xxxxxxxx>
Date: Wed Jan 16 18:22:49 2013 +0000
Get test version from net_test_file and parse all options
Adds helper method _parseNetTestOptions to NetTestLoader in order
to assemble the various options and flags into a single object
Also add functionality to read the test name and version from the
NetTestCase
Check that the required option is not None
localOptions is a dict, and the required option may be None.
This adds a test for this case.
---
ooni/nettest.py | 42 ++++++++++++++++++++++++++++++++----------
1 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/ooni/nettest.py b/ooni/nettest.py
index f82354b..7c4278a 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -65,9 +65,6 @@ class NetTestLoader(object):
def __init__(self, net_test_file):
self.testCases = self.loadNetTest(net_test_file)
- # XXX Remove
- self.testName = 'fooo'
- self.testVersion = '0.1'
@property
def testDetails(self):
@@ -118,12 +115,36 @@ class NetTestLoader(object):
return test_details
+ def _parseNetTestOptions(self, klass):
+ """
+ Helper method to assemble the options into a single UsageOptions object
+ """
+ usage_options = klass.usageOptions
+
+ if not hasattr(usage_options, 'optParameters'):
+ usage_options.optParameters = []
+
+ if klass.inputFile:
+ usage_options.optParameters.append(klass.inputFile)
+
+ if klass.baseParameters:
+ for parameter in klass.baseParameters:
+ usage_options.optParameters.append(parameter)
+
+ if klass.baseFlags:
+ if not hasattr(usage_options, 'optFlags'):
+ usage_options.optFlags = []
+ for flag in klass.baseFlags:
+ usage_options.optFlags.append(flag)
+
+ return usage_options
+
@property
def usageOptions(self):
usage_options = None
for test_class, test_method in self.testCases:
if not usage_options:
- usage_options = test_class.usageOptions
+ usage_options = self._parseNetTestOptions(test_class)
else:
assert usage_options == test_class.usageOptions
return usage_options
@@ -149,10 +170,6 @@ class NetTestLoader(object):
is either a file path or a file like object that will be used to
generate the test_cases.
"""
- # XXX
- # self.testName =
- # os.path.basename('/foo/bar/python.py').replace('.py','')
- # self.testVersion = '0.1'
test_cases = None
try:
if os.path.isfile(net_test_file):
@@ -168,6 +185,10 @@ class NetTestLoader(object):
if not test_cases:
raise NoTestCasesFound
+ test_class, _ = test_cases[0]
+ self.testVersion = test_class.version
+ self.testName = os.path.basename(net_test_file).strip('.py')
+
return test_cases
def _loadNetTestFromFileObject(self, net_test_string):
@@ -467,8 +488,9 @@ class NetTestCase(object):
def _checkRequiredOptions(self):
for required_option in self.requiredOptions:
log.debug("Checking if %s is present" % required_option)
- if required_option not in self.localOptions:
- raise MissingRequiredOption(required_option)
+ if required_option not in self.localOptions or \
+ self.localOptions[required_option] == None:
+ raise MissingRequiredOption(required_option)
def __repr__(self):
return "<%s inputs=%s>" % (self.__class__, self.inputs)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits