예제 #1
0
    def test_metrics_processor_does_not_call_prepare_module_when_all_collectors_are_filtered_out(self):
        processor = MetricsProcessor()

        logger = Mock()

        module = 'module1'

        collector = Mock(key='filtered')

        module_description = Mock()
        module_description.expect_get_collectors(toReturn=[collector])

        collector2 = Mock(key='testing')
        collector2.expect_get_values(toReturn={'value1': 23})

        module_description2 = Mock()
        module_description2.expect_get_collectors(toReturn=[collector2])
        module_description2.expect_measured_modules(toReturn=[module])
        module_description2.expect_files(module, toReturn=[])

        module_descriptions = [module_description, module_description2]

        args = Mock(matching='test')

        result = DataBean()

        processor.process_metrics(args, module_descriptions, result)(logger)

        self.assertFalse(module_description.verify_prepare_environment(logger))
        self.assertTrue(module_description2.verify_prepare_environment(logger))
예제 #2
0
    def test_metrics_processor_does_not_call_prepare_module_when_all_collectors_are_filtered_out(
            self):
        processor = MetricsProcessor()

        logger = Mock()

        module = 'module1'

        collector = Mock(key='filtered')

        module_description = Mock()
        module_description.expect_get_collectors(toReturn=[collector])

        collector2 = Mock(key='testing')
        collector2.expect_get_values(toReturn={'value1': 23})

        module_description2 = Mock()
        module_description2.expect_get_collectors(toReturn=[collector2])
        module_description2.expect_measured_modules(toReturn=[module])
        module_description2.expect_files(module, toReturn=[])

        module_descriptions = [module_description, module_description2]

        args = Mock(matching='test')

        result = DataBean()

        processor.process_metrics(args, module_descriptions, result)(logger)

        self.assertFalse(module_description.verify_prepare_environment(logger))
        self.assertTrue(module_description2.verify_prepare_environment(logger))
예제 #3
0
    def test_metrics_processor(self):
        processor = MetricsProcessor()

        logger = Mock()

        module = 'module1'

        collector = Mock()
        collector.expect_get_values(toReturn={'value1' : 23})
        collector.expect_wants_file('a', toReturn=True)
        collector.expect_wants_file('b', toReturn=False)
        collector.expect_on_read_line('aline', toReturn=False)

        file_a = MockFile()
        file_a.expect_readline(toReturn='aline')

        module_description = Mock()
        module_description.expect_get_collectors(toReturn=[collector])
        module_description.expect_measured_modules(toReturn=[module])
        module_description.expect_files(module, toReturn=['a', 'b'])
        module_description.expect_open_file('a', toReturn=file_a)

        module_descriptions = [module_description]

        args = Mock(matching=None, buildno = 'ORLY-9')

        result = DataBean()

        processor.process_metrics(args, module_descriptions, result)(logger)

        self.assertTrue(module_description.verify_prepare_environment(logger))
        self.assertTrue(collector.verify_pre_files_scan(module))
        self.assertTrue(collector.verify_on_read_line('aline'))
        self.assertEqual(1, collector.callcount_on_read_line())
        self.assertTrue(collector.verify_post_files_scan(module))
        self.assertDictEqual({'jira.stats.value1' : 23}, result.metrics)
        self.assertEqual('ORLY-9', result.build_number)
예제 #4
0
    def test_metrics_processor(self):
        processor = MetricsProcessor()

        logger = Mock()

        module = 'module1'

        collector = Mock()
        collector.expect_get_values(toReturn={'value1': 23})
        collector.expect_wants_file('a', toReturn=True)
        collector.expect_wants_file('b', toReturn=False)
        collector.expect_on_read_line('aline', toReturn=False)

        file_a = MockFile()
        file_a.expect_readline(toReturn='aline')

        module_description = Mock()
        module_description.expect_get_collectors(toReturn=[collector])
        module_description.expect_measured_modules(toReturn=[module])
        module_description.expect_files(module, toReturn=['a', 'b'])
        module_description.expect_open_file('a', toReturn=file_a)

        module_descriptions = [module_description]

        args = Mock(matching=None, buildno='ORLY-9')

        result = DataBean()

        processor.process_metrics(args, module_descriptions, result)(logger)

        self.assertTrue(module_description.verify_prepare_environment(logger))
        self.assertTrue(collector.verify_pre_files_scan(module))
        self.assertTrue(collector.verify_on_read_line('aline'))
        self.assertEqual(1, collector.callcount_on_read_line())
        self.assertTrue(collector.verify_post_files_scan(module))
        self.assertDictEqual({'jira.stats.value1': 23}, result.metrics)
        self.assertEqual('ORLY-9', result.build_number)