Ejemplo n.º 1
0
    def test_load_with_missing_required_option(self):
        try:
            ntl = NetTestLoader(dummyArgs)
            ntl.loadNetTestString(net_test_string_with_required_option)

        except MissingRequiredOption:
            pass
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    def test_load_with_missing_required_option(self):
        try:
            ntl = NetTestLoader(dummyArgs)
            ntl.loadNetTestString(net_test_string_with_required_option)

        except MissingRequiredOption:
            pass
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
    def test_require_root_succeed(self):
        #XXX: will require root to run
        ntl = NetTestLoader(dummyArgs)
        ntl.loadNetTestString(net_test_root_required)

        for test_class, method in ntl.testCases:
            self.assertTrue(test_class.requiresRoot)
Ejemplo n.º 9
0
    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()
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    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.testCases:
            for option in dummyOptions.keys():
                self.assertIn(option, test_klass.usageOptions())
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
    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())
Ejemplo n.º 15
0
    def test_generate_measurements_size(self):
        ntl = NetTestLoader(dummyArgsWithFile)
        ntl.loadNetTestString(net_test_string_with_file)

        ntl.checkOptions()
        net_test = NetTest(ntl, None)

        measurements = list(net_test.generateMeasurements())
        self.assertEqual(len(measurements), 20)
Ejemplo n.º 16
0
    def test_net_test_inputs(self):
        ntl = NetTestLoader(dummyArgsWithFile)
        ntl.loadNetTestString(net_test_string_with_file)
        ntl.checkOptions()
        nt = NetTest(ntl.getTestCases(), ntl.getTestDetails(), None)
        yield nt.initialize()

        for test_class, test_methods in nt.testCases:
            self.assertEqual(len(list(test_class.inputs)), 10)
Ejemplo n.º 17
0
    def test_load_net_test_from_StringIO(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.testCases)
Ejemplo n.º 18
0
    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())
Ejemplo n.º 19
0
    def test_load_with_invalid_option(self):
        try:
            ntl = NetTestLoader(dummyInvalidArgs)
            ntl.loadNetTestString(net_test_string)

            ntl.checkOptions()
            raise Exception
        except UsageError:
            pass
Ejemplo n.º 20
0
    def test_load_with_invalid_option(self):
        try:
            ntl = NetTestLoader(dummyInvalidArgs)
            ntl.loadNetTestString(net_test_string)

            ntl.checkOptions()
            raise Exception
        except UsageError:
            pass
Ejemplo n.º 21
0
    def test_generate_measurements_size(self):
        ntl = NetTestLoader(dummyArgsWithFile)
        ntl.loadNetTestString(net_test_string_with_file)

        ntl.checkOptions()
        net_test = NetTest(ntl, None)

        measurements = list(net_test.generateMeasurements())
        self.assertEqual(len(measurements), 20)
Ejemplo n.º 22
0
    def test_net_test_inputs(self):
        ntl = NetTestLoader(dummyArgsWithFile)
        ntl.loadNetTestString(net_test_string_with_file)
        ntl.checkOptions()
        nt = NetTest(ntl.getTestCases(), ntl.getTestDetails(), None)
        yield nt.initialize()

        for test_class, test_methods in nt.testCases:
            self.assertEqual(len(list(test_class.inputs)), 10)
Ejemplo n.º 23
0
    def test_generate_measurements_size(self):
        ntl = NetTestLoader(dummyArgsWithFile)
        ntl.loadNetTestString(net_test_string_with_file)
        ntl.checkOptions()

        net_test = NetTest(ntl.getTestCases(), ntl.getTestDetails(), None)

        net_test.initializeInputProcessor()
        measurements = list(net_test.generateMeasurements())
        self.assertEqual(len(measurements), 20)
Ejemplo n.º 24
0
    def test_net_test_inputs(self):
        ntl = NetTestLoader(dummyArgsWithFile)
        ntl.loadNetTestString(net_test_string_with_file)
        ntl.checkOptions()
        nt = NetTest(ntl.getTestCases(), ntl.getTestDetails(), None)
        nt.initializeInputProcessor()

        # XXX: if you use the same test_class twice you will have consumed all
        # of its inputs!
        tested = set([])
        for test_instance, test_method, inputs in nt.testInstances:
            self.assertEqual(len(list(inputs)), 10)
Ejemplo n.º 25
0
    def test_net_test_inputs(self):
        ntl = NetTestLoader(dummyArgsWithFile)
        ntl.loadNetTestString(net_test_string_with_file)

        ntl.checkOptions()

        # XXX: if you use the same test_class twice you will have consumed all
        # of its inputs!
        tested = set([])
        for test_class, test_method in ntl.testCases:
            if test_class not in tested:
                tested.update([test_class])
                self.assertEqual(len(list(test_class.inputs)), 10)
Ejemplo n.º 26
0
    def test_net_test_inputs(self):
        ntl = NetTestLoader(dummyArgsWithFile)
        ntl.loadNetTestString(net_test_string_with_file)

        ntl.checkOptions()

        # XXX: if you use the same test_class twice you will have consumed all
        # of its inputs!
        tested = set([])
        for test_class, test_method in ntl.testCases:
            if test_class not in tested:
                tested.update([test_class])
                self.assertEqual(len(list(test_class.inputs)), 10)
Ejemplo n.º 27
0
    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
Ejemplo n.º 28
0
    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
Ejemplo n.º 29
0
    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
Ejemplo n.º 30
0
    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.startNetTest(ntl, self.filename)

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

        return d
Ejemplo n.º 31
0
    def test_net_test_completed_callback(self):
        ntl = NetTestLoader(dummyArgsWithFile)
        ntl.loadNetTestString(net_test_string_with_file)

        ntl.checkOptions()
        director = Director()

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

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

        return d
Ejemplo n.º 32
0
    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
Ejemplo n.º 33
0
    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):
            print "IN here y0"
            self.assertEqual(result, None)
            self.assertEqual(director.successfulMeasurements, 20)

        return d
Ejemplo n.º 34
0
    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
Ejemplo n.º 35
0
    def test_send_to_inputs_generator(self):
        """
        Verify that a net test can send information back into an inputs generator.
        """
        ntl = NetTestLoader(dummyArgs)
        ntl.loadNetTestString(generator_net_test)
        ntl.checkOptions()

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

        @d.addCallback
        def complete(result):
            with open(self.filename) as report_file:
                all_report_entries = map(json.loads, report_file)
                results = [x['input'] for x in all_report_entries]
            self.assertEqual(results, [9, 8, 7, 6, 5, 5, 3, 2, 1, 0])

        return d
Ejemplo n.º 36
0
    def test_send_to_inputs_generator(self):
        """
        Verify that a net test can send information back into an inputs generator.
        """
        ntl = NetTestLoader(dummyArgs)
        ntl.loadNetTestString(generator_net_test)
        ntl.checkOptions()

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

        @d.addCallback
        def complete(result):
            with open(self.filename) as report_file:
                all_report_entries = map(json.loads, report_file)
                results = [x['input'] for x in all_report_entries]
            self.assertEqual(results, [9, 8, 7, 6, 5, 5, 3, 2, 1, 0])

        return d
Ejemplo n.º 37
0
    def test_setup_local_options_in_test_cases(self):
        ntl = NetTestLoader(dummyArgs)
        ntl.loadNetTestString(net_test_string)

        ntl.checkOptions()
        self.assertEqual(dict(ntl.localOptions), dummyOptions)
Ejemplo n.º 38
0
    def test_load_with_required_option(self):
        ntl = NetTestLoader(dummyArgsWithRequiredOptions)
        ntl.loadNetTestString(net_test_string_with_required_option)

        self.assertIsInstance(ntl, NetTestLoader)
Ejemplo n.º 39
0
 def test_load_with_missing_required_option(self):
     ntl = NetTestLoader(dummyArgs)
     ntl.loadNetTestString(net_test_string_with_required_option)
     self.assertRaises(MissingRequiredOption, ntl.checkOptions)
Ejemplo n.º 40
0
    def test_setup_local_options_in_test_cases(self):
        ntl = NetTestLoader(dummyArgs)
        ntl.loadNetTestString(net_test_string)

        ntl.checkOptions()
        self.assertEqual(dict(ntl.localOptions), dummyOptions)
Ejemplo n.º 41
0
 def test_load_with_invalid_option(self):
     ntl = NetTestLoader(dummyInvalidArgs)
     ntl.loadNetTestString(net_test_string)
     self.assertRaises(UsageError, ntl.checkOptions)
     self.assertRaises(OONIUsageError, ntl.checkOptions)
Ejemplo n.º 42
0
    def test_load_with_required_option(self):
        ntl = NetTestLoader(dummyArgsWithRequiredOptions)
        ntl.loadNetTestString(net_test_string_with_required_option)

        self.assertIsInstance(ntl, NetTestLoader)
Ejemplo n.º 43
0
 def test_load_net_test_multiple(self):
     ntl = NetTestLoader(dummyArgs)
     ntl.loadNetTestString(double_net_test_string)
     test_cases = ntl.getTestCases()
     self.verifyMethods(test_cases)
     ntl.checkOptions()
Ejemplo n.º 44
0
 def test_load_with_missing_required_option(self):
     ntl = NetTestLoader(dummyArgs)
     ntl.loadNetTestString(net_test_string_with_required_option)
     self.assertRaises(MissingRequiredOption, ntl.checkOptions)
Ejemplo n.º 45
0
 def test_load_with_invalid_option(self):
     ntl = NetTestLoader(dummyInvalidArgs)
     ntl.loadNetTestString(net_test_string)
     self.assertRaises(UsageError, ntl.checkOptions)
     self.assertRaises(OONIUsageError, ntl.checkOptions)
Ejemplo n.º 46
0
 def test_load_net_test_multiple(self):
     ntl = NetTestLoader(dummyArgs)
     ntl.loadNetTestString(double_net_test_string)
     test_cases = ntl.getTestCases()
     self.verifyMethods(test_cases)
     ntl.checkOptions()