本文整理汇总了Python中ooni.nettest.NetTestLoader类的典型用法代码示例。如果您正苦于以下问题:Python NetTestLoader类的具体用法?Python NetTestLoader怎么用?Python NetTestLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetTestLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createDeck
def createDeck(global_options, url=None):
from ooni.nettest import NetTestLoader
from ooni.deck import Deck, nettest_to_path
if url:
log.msg("Creating deck for: %s" % (url))
if global_options['no-yamloo']:
log.msg("Will not write to a yamloo report file")
deck = Deck(bouncer=global_options['bouncer'],
no_collector=global_options['no-collector'])
try:
if global_options['testdeck']:
deck.loadDeck(global_options['testdeck'], global_options)
else:
log.debug("No test deck detected")
test_file = nettest_to_path(global_options['test_file'], True)
if url is not None:
args = ('-u', url)
else:
args = tuple()
if any(global_options['subargs']):
args = global_options['subargs'] + args
net_test_loader = NetTestLoader(args,
test_file=test_file,
annotations=global_options['annotations'])
if global_options['collector']:
net_test_loader.collector = \
CollectorClient(global_options['collector'])
deck.insert(net_test_loader)
except errors.MissingRequiredOption as option_name:
log.err('Missing required option: "%s"' % option_name)
incomplete_net_test_loader = option_name.net_test_loader
print incomplete_net_test_loader.usageOptions().getUsage()
sys.exit(2)
except errors.NetTestNotFound as path:
log.err('Requested NetTest file not found (%s)' % path)
sys.exit(3)
except errors.OONIUsageError as e:
log.err(e)
print e.net_test_loader.usageOptions().getUsage()
sys.exit(4)
except errors.HTTPSCollectorUnsupported:
log.err("HTTPS collectors require a twisted version of at least 14.0.2.")
sys.exit(6)
except errors.InsecureBackend:
log.err("Attempting to report to an insecure collector.")
log.err("To enable reporting to insecure collector set the "
"advanced->insecure_backend option to true in "
"your ooniprobe.conf file.")
sys.exit(7)
except Exception as e:
if config.advanced.debug:
log.exception(e)
log.err(e)
sys.exit(5)
return deck
示例2: loadDeck
def loadDeck(self, deckFile, global_options={}):
with open(deckFile) as f:
self.id = sha256(f.read()).hexdigest()
f.seek(0)
test_deck = yaml.safe_load(f)
for test in test_deck:
try:
nettest_path = nettest_to_path(test['options']['test_file'])
except e.NetTestNotFound:
log.err("Could not find %s" % test['options']['test_file'])
log.msg("Skipping...")
continue
annotations = test['options'].get('annotations', {})
if global_options.get('annotations') is not None:
annotations = global_options["annotations"]
collector_address = test['options'].get('collector', None)
if global_options.get('collector') is not None:
collector_address = global_options['collector']
net_test_loader = NetTestLoader(test['options']['subargs'],
annotations=annotations,
test_file=nettest_path)
if collector_address is not None:
net_test_loader.collector = CollectorClient(
collector_address
)
if test['options'].get('bouncer', None) is not None:
self.bouncer = self._BouncerClient(test['options']['bouncer'])
if self.bouncer.backend_type is "onion":
self.requiresTor = True
self.insert(net_test_loader)
示例3: test_load_with_missing_required_option
def test_load_with_missing_required_option(self):
try:
ntl = NetTestLoader(dummyArgs)
ntl.loadNetTestString(net_test_string_with_required_option)
except MissingRequiredOption:
pass
示例4: test_setup_local_options_in_test_cases
def test_setup_local_options_in_test_cases(self):
options = {'subargs':dummyArgs, 'test':StringIO(net_test_string)}
ntl = NetTestLoader(options)
ntl.checkOptions()
for test_class, test_method in ntl.testCases:
self.assertEqual(test_class.localOptions, dummyOptions)
示例5: test_load_net_test_multiple_different_options
def test_load_net_test_multiple_different_options(self):
ntl = NetTestLoader(dummyArgs)
ntl.loadNetTestString(double_different_options_net_test_string)
test_cases = ntl.getTestCases()
self.verifyMethods(test_cases)
self.assertRaises(IncoherentOptions, ntl.checkOptions)
示例6: test_require_root_succeed
def test_require_root_succeed(self):
# XXX: will require root to run
ntl = NetTestLoader(dummyArgs)
ntl.loadNetTestString(net_test_root_required)
for test_class, methods in ntl.getTestCases():
self.assertTrue(test_class.requiresRoot)
示例7: test_singular_input_processor
def test_singular_input_processor(self):
"""
Verify that all measurements use the same object as their input processor.
"""
ntl = NetTestLoader(dummyArgs)
ntl.loadNetTestString(generator_id_net_test)
ntl.checkOptions()
director = Director()
self.filename = 'dummy_report.yamloo'
d = director.startNetTest(ntl, self.filename)
@d.addCallback
def complete(result):
with open(self.filename) as report_file:
all_report_entries = yaml.safe_load_all(report_file)
header = all_report_entries.next()
results_case_a = all_report_entries.next()
aa_test, ab_test, ac_test = results_case_a.get('results', [])
results_case_b = all_report_entries.next()
ba_test = results_case_b.get('results', [])[0]
# Within a NetTestCase an inputs object will be consistent
self.assertEqual(aa_test, ab_test, ac_test)
# An inputs object will be different between different NetTestCases
self.assertNotEqual(aa_test, ba_test)
return d
示例8: test_load_with_option
def test_load_with_option(self):
ntl = NetTestLoader(dummyArgs)
ntl.loadNetTestString(net_test_string)
self.assertIsInstance(ntl, NetTestLoader)
for test_klass, test_meth in ntl.getTestCases():
for option in dummyOptions.keys():
self.assertIn(option, test_klass.usageOptions())
示例9: test_load_net_test_multiple_different_options
def test_load_net_test_multiple_different_options(self):
ntl = NetTestLoader(dummyArgs)
ntl.loadNetTestString(double_different_options_net_test_string)
self.verifyMethods(ntl.testCases)
self.verifyClasses(ntl.testCases, set(('DummyTestCaseA', 'DummyTestCaseB')))
self.assertRaises(IncoherentOptions, ntl.checkOptions)
示例10: test_setup_local_options_in_test_cases
def test_setup_local_options_in_test_cases(self):
ntl = NetTestLoader(dummyArgs)
ntl.loadNetTestString(net_test_string)
ntl.checkOptions()
for test_class, test_method in ntl.testCases:
self.assertEqual(test_class.localOptions, dummyOptions)
示例11: test_load_net_test_multiple
def test_load_net_test_multiple(self):
ntl = NetTestLoader(dummyArgs)
ntl.loadNetTestString(double_net_test_string)
self.verifyMethods(ntl.testCases)
self.verifyClasses(ntl.testCases, set(('DummyTestCaseA', 'DummyTestCaseB')))
ntl.checkOptions()
示例12: runWithDirector
def runWithDirector():
"""
Instance the director, parse command line options and start an ooniprobe
test!
"""
global_options = parseOptions()
config.global_options = global_options
config.set_paths()
config.read_config_file()
log.start(global_options['logfile'])
if config.privacy.includepcap:
try:
checkForRoot()
except errors.InsufficientPrivileges:
log.err("Insufficient Privileges to capture packets."
" See ooniprobe.conf privacy.includepcap")
sys.exit(2)
# contains (test_cases, options, cmd_line_options)
test_list = []
director = Director()
d = director.start()
if global_options['list']:
print "# Installed nettests"
for net_test_id, net_test in director.netTests.items():
print "* %s (%s/%s)" % (net_test['name'],
net_test['category'],
net_test['id'])
print " %s" % net_test['description']
sys.exit(0)
#XXX: This should mean no bouncer either!
if global_options['no-collector']:
log.msg("Not reporting using a collector")
collector = global_options['collector'] = None
global_options['bouncer'] = None
deck = Deck()
deck.bouncer = global_options['bouncer']
try:
if global_options['testdeck']:
deck.loadDeck(global_options['testdeck'])
else:
log.debug("No test deck detected")
test_file = nettest_to_path(global_options['test_file'])
net_test_loader = NetTestLoader(global_options['subargs'],
test_file=test_file)
deck.insert(net_test_loader)
except errors.MissingRequiredOption, option_name:
log.err('Missing required option: "%s"' % option_name)
print net_test_loader.usageOptions().getUsage()
sys.exit(2)
示例13: test_load_with_invalid_option
def test_load_with_invalid_option(self):
try:
ntl = NetTestLoader(dummyInvalidArgs)
ntl.loadNetTestString(net_test_string)
ntl.checkOptions()
raise Exception
except UsageError:
pass
示例14: test_load_net_test_from_str
def test_load_net_test_from_str(self):
"""
Given a file like object verify that the net test cases are properly
generated.
"""
ntl = NetTestLoader(dummyArgs)
ntl.loadNetTestString(net_test_string)
self.verifyMethods(ntl.getTestCases())
示例15: test_load_with_invalid_option
def test_load_with_invalid_option(self):
options = {'subargs':dummyInvalidArgs,
'test':StringIO(net_test_string)}
try:
ntl = NetTestLoader(options)
ntl.checkOptions()
raise Exception
except UsageError:
pass