Exemple #1
0
    def test_interactive_component_not_executed_in_non_interactive_mode(self):
        ctx = test_context(mode=Mode.BACKGROUND)

        executor = Executor()
        collector = InteractiveMockCollector()

        ctx.registry.register_collector("id", collector)

        executor.execute(ctx)

        self.assertFalse(collector.called)
Exemple #2
0
    def test_platform_incompatible_component_not_executed(self):
        ctx = test_context()

        executor = Executor()
        collector = PlatformInCompatible()

        ctx.registry.register_collector("id", collector)

        executor.execute(ctx)

        self.assertFalse(collector.called)
Exemple #3
0
    def test_experimental_component_not_executed(self):
        ctx = test_context()
        ctx.flags.experimental = False

        executor = Executor()
        collector = ExperimentalMockCollector()

        ctx.registry.register_collector("id", collector)

        executor.execute(ctx)

        self.assertFalse(collector.called)
Exemple #4
0
    def test_execute_collection_only(self):
        ctx = test_context()

        executor = Executor()
        collector = MockCollector("data")

        ctx.registry.register_collector("id", collector)

        self.assertEqual(ExecutionSummary(total_count=1, problem_count=0),
                         executor.execute(ctx))

        self.assertTrue(collector.called)
Exemple #5
0
    def test_experimental_component_executed_when_experimental_flag_is_on(
            self):
        ctx = test_context()
        ctx.flags.experimental = True

        executor = Executor()
        collector = ExperimentalMockCollector()

        ctx.registry.register_collector("id", collector)

        executor.execute(ctx)

        self.assertTrue(collector.called)
Exemple #6
0
    def test_execute_validation_only(self):
        ctx = test_context()

        executor = Executor()
        collector = MockCollector("data")
        validator = MockValidator(result=validation_result_with("data"))

        ctx.registry.register_collector("id", collector)
        ctx.registry.register_validator("id", validator)

        self.assertEqual(ExecutionSummary(total_count=1, problem_count=1),
                         executor.execute(ctx))

        self.assertTrue(collector.called)
        self.assertTrue(validator.called)
Exemple #7
0
    def test_execute_flow_with_multiple_components(self):
        ctx = test_context()
        handler = RecordingHandler(fail=True)

        executor = Executor()
        collector1 = MockCollector("comp1_data")
        collector2 = MockCollector("comp2_data")

        ctx.registry.register_collector("comp_1", collector1)
        ctx.registry.register_collector("comp_2", collector2)

        self.assertEqual(ExecutionSummary(total_count=2, problem_count=0),
                         executor.execute(ctx, get_handler=handler.get))

        self.assertTrue(collector1.called)
        self.assertTrue(collector2.called)
Exemple #8
0
    def test_execute_flow_with_empty_reactor(self):
        ctx = test_context()
        handler = RecordingHandler()

        executor = Executor()
        reactor = MockReactor()

        ctx.registry.register_collector("id", MockCollector("data"))
        ctx.registry.register_validator(
            "id", MockValidator(result=validation_result_with("data")))
        ctx.registry.register_reactor("id", reactor)

        self.assertEqual(ExecutionSummary(total_count=1, problem_count=1),
                         executor.execute(ctx, get_handler=handler.get))

        self.assertTrue(reactor.called)
        self.assertEqual(0, len(handler.recorded))
Exemple #9
0
    def test_filtered_component_list(self):
        ctx = test_context(mode=Mode.BACKGROUND)
        ctx.components = ["id1", "id3"]

        executor = Executor()
        collector1 = MockCollector("data")
        collector2 = MockCollector("data")
        collector3 = MockCollector("data")

        ctx.registry.register_collector("id1", collector1)
        ctx.registry.register_collector("id2", collector2)
        ctx.registry.register_collector("id3", collector3)

        executor.execute(ctx)

        self.assertTrue(collector1.called)
        self.assertFalse(collector2.called)
        self.assertTrue(collector3.called)
Exemple #10
0
    def test_basic_execute(self):
        ctx = test_context()
        handler = RecordingHandler()

        executor = Executor()
        collector = MockCollector("data")
        validator = MockValidator(result=validation_result_with("data"))
        reactor_command = ReactorCommand(cmd=["do", "nothing"])
        reactor = MockReactor(reactor_command)

        ctx.registry.register_collector("id", collector)
        ctx.registry.register_validator("id", validator)
        ctx.registry.register_reactor("id", reactor)

        self.assertEqual(ExecutionSummary(total_count=1, problem_count=1),
                         executor.execute(ctx, get_handler=handler.get))

        self.assertTrue(collector.called)
        self.assertTrue(validator.called)
        self.assertTrue(reactor.called)
        self.assertEqual(reactor_command, handler.recorded[0])
Exemple #11
0
def run_embedded(ctx):
    executor = Executor()

    def execute():
        summary = executor.execute(ctx)

        if summary.problem_count == 0:
            ctx.logger.success("No problems detected!")

        return summary

    return execute()
Exemple #12
0
    def test_execute_flow_with_command_failure(self):
        ctx = test_context()
        handler = RecordingHandler(fail=True)

        executor = Executor()
        collector = MockCollector("data")
        validator = MockValidator(result=validation_result_with("data"))
        reactor = MockReactor("whatever")

        ctx.registry.register_collector("id", collector)
        ctx.registry.register_validator("id", validator)
        ctx.registry.register_reactor("id", reactor)

        def execute():
            executor.execute(ctx, get_handler=handler.get)

        self.assertRaises(Exception, execute)
        self.assertIsNotNone(handler.raised)

        self.assertTrue(collector.called)
        self.assertTrue(validator.called)
        self.assertTrue(reactor.called)
Exemple #13
0
def run_embedded(ctx):
    executor = Executor()

    def execute():
        summary = executor.execute(ctx)

        if summary.problem_count > 0:
            verify_changes()
        else:
            ctx.logger.success("No problems detected!")

        return summary

    def verify_changes():
        if not ctx.flags.dryrun:
            ctx.logger.info("Inspecting components again to verify changes...")
            if inspector.run_embedded(_inspection_context()).problem_count > 0:
                ctx.logger.failure(
                    "Some issues could not be resolved. Please report this issue!"
                )

    return execute()
Exemple #14
0
    def test_empty_execute(self):
        executor = Executor()

        self.assertEqual(ExecutionSummary(0, 0),
                         executor.execute(test_context()))