当前位置: 首页>>代码示例>>Python>>正文


Python director.Director类代码示例

本文整理汇总了Python中ooni.director.Director的典型用法代码示例。如果您正苦于以下问题:Python Director类的具体用法?Python Director怎么用?Python Director使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Director类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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
开发者ID:willscott,项目名称:ooni-probe,代码行数:27,代码来源:test_nettest.py

示例2: test_get_net_tests

 def test_get_net_tests(self):
     director = Director()
     nettests = director.getNetTests()
     assert "http_requests" in nettests
     assert "dnsconsistency" in nettests
     assert "http_header_field_manipulation" in nettests
     assert "traceroute" in nettests
开发者ID:jacobhaven,项目名称:ooni-probe,代码行数:7,代码来源:test_director.py

示例3: runWithDirector

def runWithDirector(global_options):
    """
    Instance the director, parse command line options and start an ooniprobe
    test!
    """
    from ooni.director import Director
    director = Director()
    if global_options['list']:
        net_tests = [net_test for net_test in director.getNetTests().items()]
        print ""
        print "Installed nettests"
        print "=================="
        for net_test_id, net_test in net_tests:
            optList = []
            for name, details in net_test['arguments'].items():
                optList.append({'long': name, 'doc': details['description']})

            desc = ('\n' +
                    net_test['name'] +
                    '\n' +
                    '-'*len(net_test['name']) +
                    '\n' +
                    '\n'.join(textwrap.wrap(net_test['description'], 80)) +
                    '\n\n' +
                    '$ ooniprobe {}/{}'.format(net_test['category'],
                                                      net_test['id']) +
                    '\n\n' +
                    ''.join(usage.docMakeChunks(optList))
            )
            print desc
            print "Note: Third party tests require an external "\
                  "application to run properly."

        sys.exit(0)

    elif global_options['printdeck']:
        del global_options['printdeck']
        print "# Copy and paste the lines below into a test deck to run the specified test with the specified arguments"
        print yaml.safe_dump([{'options': global_options}]).strip()

        sys.exit(0)

    if global_options.get('annotations') is not None:
        global_options['annotations'] = setupAnnotations(global_options)

    if global_options['no-collector']:
        log.msg("Not reporting using a collector")
        global_options['collector'] = None
        start_tor = False
    else:
        start_tor = True

    if global_options['collector']:
        start_tor |= True

    return runTestWithDirector(director=director,
                               start_tor=start_tor,
                               global_options=global_options)
开发者ID:willscott,项目名称:ooni-probe,代码行数:58,代码来源:oonicli.py

示例4: 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)
开发者ID:WheresAlice,项目名称:ooni-probe,代码行数:58,代码来源:oonicli.py

示例5: test_nettest_timeout

    def test_nettest_timeout(self):
        ntl = NetTestLoader(('-u', 'http://localhost:8007/'))
        ntl.loadNetTestString(http_net_test)

        ntl.checkOptions()
        director = Director()

        d = director.startNetTest(ntl, [MockReporter()])

        @d.addCallback
        def complete(result):
            assert director.failedMeasurements == 1

        return d
开发者ID:qlimaxx,项目名称:ooni-probe-dev,代码行数:14,代码来源:test_nettest.py

示例6: TestStartSniffing

class TestStartSniffing(unittest.TestCase):
    def setUp(self):
        self.director = Director()
        self.testDetails = {
            'test_name': 'foo',
            'test_start_time': '2016-01-01 12:34:56'
        }

        # Each NetTestCase has a name attribute
        class FooTestCase(object):
            name = 'foo'
        self.FooTestCase = FooTestCase

    def test_start_sniffing_once(self):
        with patch('ooni.settings.config.scapyFactory') as mock_scapy_factory:
            with patch('ooni.utils.txscapy.ScapySniffer') as mock_scapy_sniffer:
                self.director.startSniffing(self.testDetails)
                sniffer = mock_scapy_sniffer.return_value
                mock_scapy_factory.registerProtocol.assert_called_once_with(sniffer)

    def test_start_sniffing_twice(self):
        with patch('ooni.settings.config.scapyFactory') as mock_scapy_factory:
            with patch('ooni.utils.txscapy.ScapySniffer') as mock_scapy_sniffer:
                sniffer = mock_scapy_sniffer.return_value
                sniffer.pcapwriter.filename = 'foo1_filename'
                self.director.startSniffing(self.testDetails)
                self.assertEqual(len(self.director.sniffers), 1)

            self.testDetails = {
                'test_name': 'bar',
                'test_start_time': '2016-01-01 12:34:56'
            }
            with patch('ooni.utils.txscapy.ScapySniffer') as mock_scapy_sniffer:
                sniffer = mock_scapy_sniffer.return_value
                sniffer.pcapwriter.filename = 'foo2_filename'
                self.director.startSniffing(self.testDetails)
                self.assertEqual(len(self.director.sniffers), 2)

    def test_measurement_succeeded(self):
        with patch('ooni.settings.config.scapyFactory') as mock_scapy_factory:
            with patch('ooni.utils.txscapy.ScapySniffer') as mock_scapy_sniffer:
                self.director.startSniffing(self.testDetails)
                self.assertEqual(len(self.director.sniffers), 1)
                measurement = MagicMock()
                measurement.testInstance = self.FooTestCase()
                self.director.measurementSucceeded('awesome', measurement)
                self.assertEqual(len(self.director.sniffers), 0)
                sniffer = mock_scapy_sniffer.return_value
                mock_scapy_factory.unRegisterProtocol.assert_called_once_with(sniffer)
开发者ID:0xPoly,项目名称:ooni-probe,代码行数:49,代码来源:test_director.py

示例7: test_net_test_completed_callback

    def test_net_test_completed_callback(self):
        ntl = NetTestLoader(dummyArgsWithFile)
        ntl.loadNetTestString(net_test_string_with_file)

        ntl.checkOptions()
        director = Director()

        d = director.startNetTest(ntl, [MockReporter()])

        @d.addCallback
        def complete(result):
            self.assertEqual(result, None)
            self.assertEqual(director.successfulMeasurements, 20)

        return d
开发者ID:qlimaxx,项目名称:ooni-probe-dev,代码行数:15,代码来源:test_nettest.py

示例8: test_nettest_timeout

    def test_nettest_timeout(self):
        ntl = NetTestLoader(('-u', 'http://localhost:8007/'))
        ntl.loadNetTestString(http_net_test)

        ntl.checkOptions()
        director = Director()

        self.filename = 'dummy_report.yamloo'
        d = director.start_net_test_loader(ntl, self.filename)

        @d.addCallback
        def complete(result):
            assert director.failedMeasurements == 1

        return d
开发者ID:TheTorProject,项目名称:ooni-probe,代码行数:15,代码来源:test_nettest.py

示例9: 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()

    # 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, global_options=global_options
            )
            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)
开发者ID:aagbsn,项目名称:ooni-probe,代码行数:48,代码来源:oonicli.py

示例10: setUp

    def setUp(self):
        with open('dummyInputFile.txt', 'w') as f:
            for i in range(10):
                f.write("%s\n" % i)

        self.reporters = [MockReporter()]
        self.director = Director()
开发者ID:bhitov,项目名称:ooni-probe,代码行数:7,代码来源:test_director.py

示例11: TestDirector

class TestDirector(unittest.TestCase):
    timeout = 1
    def setUp(self):
        with open('dummyInputFile.txt', 'w') as f:
            for i in range(10):
                f.write("%s\n" % i)

        self.reporters = [MockReporter()]
        self.director = Director()

    def tearDown(self):
        pass

    def test_start_net_test(self):
        options = {'test':net_test_string, 'subargs':dummyArgs}
        net_test_loader = NetTestLoader(options)
        net_test_loader.checkOptions()
        d = self.director.startNetTest('', net_test_loader, self.reporters)

        @d.addCallback
        def done(result):
            self.assertEqual(self.director.successfulMeasurements, 20)

        return d

    def test_stop_net_test(self):
        pass
开发者ID:bhitov,项目名称:ooni-probe,代码行数:27,代码来源:test_director.py

示例12: test_net_test_completed_callback

    def test_net_test_completed_callback(self):
        options = {'subargs':dummyArgsWithFile,
            'test':StringIO(net_test_string_with_file)}
        ntl = NetTestLoader(options)
        ntl.checkOptions()
        director = Director()

        d = director.startNetTest('', ntl, [MockReporter()])

        @d.addCallback
        def complete(result):
            #XXX: why is the return type (True, None) ?
            self.assertEqual(result, [(True,None)])
            self.assertEqual(director.successfulMeasurements, 20)

        return d
开发者ID:bhitov,项目名称:ooni-probe,代码行数:16,代码来源:test_nettest.py

示例13: test_run_test_fails_twice

    def test_run_test_fails_twice(self):
        finished = defer.Deferred()

        def net_test_done(net_test):
            summary_items = net_test.summary.items()
            self.assertEqual(len(summary_items), 50)
            for input_name, run_count in summary_items:
                self.assertEqual(run_count, 3)
            finished.callback(None)

        net_test_loader = NetTestLoader(('spam','ham'))
        net_test_loader.loadNetTestString(test_failing_twice)
        director = Director()
        director.netTestDone = net_test_done
        director.startNetTest(net_test_loader, None, no_yamloo=True)
        return finished
开发者ID:Archer-sys,项目名称:ooni-probe,代码行数:16,代码来源:test_director.py

示例14: runWithDirector

def runWithDirector(logging=True, start_tor=True, check_incoherences=True):
    """
    Instance the director, parse command line options and start an ooniprobe
    test!
    """

    global_options = setupGlobalOptions(logging, start_tor, check_incoherences)

    director = Director()
    if global_options['list']:
        print "# Installed nettests"
        for net_test_id, net_test in director.getNetTests().items():
            print "* %s (%s/%s)" % (net_test['name'],
                                    net_test['category'],
                                    net_test['id'])
            print "  %s" % net_test['description']

        sys.exit(0)

    elif global_options['printdeck']:
        del global_options['printdeck']
        print "# Copy and paste the lines below into a test deck to run the specified test with the specified arguments"
        print yaml.safe_dump([{'options': global_options}]).strip()

        sys.exit(0)

    if global_options.get('annotations') is not None:
        global_options['annotations'] = setupAnnotations(global_options)

    if global_options['no-collector']:
        log.msg("Not reporting using a collector")
        global_options['collector'] = None
        start_tor = False
    else:
        start_tor = True

    if global_options['collector']:
        start_tor |= True

    return runTestWithDirector(director=director,
                               start_tor=start_tor,
                               global_options=global_options,
                               check_incoherences=check_incoherences)
开发者ID:0xPoly,项目名称:ooni-probe,代码行数:43,代码来源:oonicli.py

示例15: setUp

    def setUp(self):
        self.director = Director()
        self.testDetails = {
            'test_name': 'foo',
            'test_start_time': '2016-01-01 12:34:56'
        }

        # Each NetTestCase has a name attribute
        class FooTestCase(object):
            name = 'foo'
        self.FooTestCase = FooTestCase
开发者ID:0xPoly,项目名称:ooni-probe,代码行数:11,代码来源:test_director.py


注:本文中的ooni.director.Director类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。