Ejemplo n.º 1
0
class TestHtmlDoc(unittest.TestCase):
    TEST_CASE_INSTRUCTION_SET = instruction_set()
    TEST_SUITE_CONFIGURATION_SECTION_INSTRUCTIONS = CONFIGURATION_SECTION_INSTRUCTIONS

    def test_that_html_doc_renderer_returns_valid_section_contents(self):
        # ARRANGE #
        application_help = new_application_help(
            self.TEST_CASE_INSTRUCTION_SET,
            self.TEST_SUITE_CONFIGURATION_SECTION_INSTRUCTIONS)
        # ACT #
        actual = sut.section_contents(application_help)
        # ASSERT #
        struct_check.is_section_contents.apply(self, actual)

    def test_generate_and_output_SHOULD_output_xhtml(self):
        # ARRANGE #
        application_help = new_application_help(
            self.TEST_CASE_INSTRUCTION_SET,
            self.TEST_SUITE_CONFIGURATION_SECTION_INSTRUCTIONS)
        output_file = io.StringIO()
        # ACT #
        sut.generate_and_output(output_file, application_help)
        # ASSERT #
        actual_output = output_file.getvalue()
        begins_with(DOCTYPE_XHTML1_0).apply(self, actual_output,
                                            asrt.MessageBuilder('file output'))

    def test_anchors_and_references(self):
        # ARRANGE #

        application_help = new_application_help(
            default_instructions_setup.INSTRUCTIONS_SETUP,
            test_suite_default_setup.CONFIGURATION_SECTION_INSTRUCTIONS)
        # ACT #
        actual_section_contents = sut.section_contents(application_help)
        # ASSERT #
        collector = _SectionItemAnchorsCollector([], [])

        collector.handle_section_contents(actual_section_contents)

        target_renderer = HtmlTargetRenderer()

        anchors = [
            target_renderer.visit(t) for t in collector.anchors
            if _is_internal_target(t)
        ]
        references = [
            target_renderer.visit(t) for t in collector.references
            if _is_internal_target(t)
        ]

        anchor_2_num_defs = count_elements(anchors)

        # Every anchor must be used only once
        for t, n in anchor_2_num_defs.items():
            self.assertEqual(1, n, t)

        # Every reference must have a corresponding anchor
        for r in references:
            self.assertTrue(r in anchor_2_num_defs, r)
Ejemplo n.º 2
0
    def test_act(self):
        # ARRANGE #
        cases = {
            STEP__ACT__PARSE: {
                EXECUTION__INTERNAL_ERROR:
                ActorThatRunsConstantActions(parse_atc=DO_RAISES_EXCEPTION),
            },
            STEP__VALIDATE_PRE_SDS: {
                EXECUTION__VALIDATION_ERROR:
                ActorThatRunsConstantActions(
                    validate_pre_sds_action=SVH_VALIDATION_ERROR),
                EXECUTION__HARD_ERROR:
                ActorThatRunsConstantActions(
                    validate_pre_sds_action=SVH_HARD_ERROR),
                EXECUTION__INTERNAL_ERROR:
                ActorThatRunsConstantActions(
                    validate_pre_sds_initial_action=DO_RAISES_EXCEPTION),
            },
        }
        test_case_definition = test_case_definition_for(instruction_set())

        test_case_source = ''

        for step, exit_value_2_constructor in cases.items():
            for exit_value, constructor in exit_value_2_constructor.items():
                expectation = Expectation(exit_value, output_is_empty)
                with self.subTest(step=step,
                                  exit_value=exit_value.exit_identifier):
                    # ACT & ASSERT #
                    _check(self, test_case_definition, constructor,
                           test_case_source,
                           self.sandbox_dir_resolver_that_should_not_be_called,
                           expectation)
Ejemplo n.º 3
0
 def test_WHEN_pass_THEN_sds_SHOULD_be_printed(self):
     # ARRANGE #
     test_case_definition = test_case_definition_for(instruction_set())
     test_case_source = ''
     expectation = Expectation(EXECUTION__PASS,
                               output_is_sds_which_should_be_preserved)
     # ACT & ASSERT #
     _check(self, test_case_definition, ActorThatRunsConstantActions(),
            test_case_source, self.sandbox_dir_resolver_of_given_dir,
            expectation)
Ejemplo n.º 4
0
 def test_WHEN_pass_THEN_sds_SHOULD_be_printed(self):
     # ARRANGE #
     test_case_definition = test_case_definition_for(instruction_set())
     test_case_source = ''
     expectation = Expectation(EXECUTION__PASS, output_is_sds_which_should_be_preserved)
     # ACT & ASSERT #
     _check(self,
            test_case_definition,
            ActorThatRunsConstantActions(),
            test_case_source,
            self.sandbox_dir_resolver_of_given_dir,
            expectation)
Ejemplo n.º 5
0
    def test_act(self):
        # ARRANGE #
        cases = {
            STEP__VALIDATE_POST_SETUP:
                {
                    EXECUTION__VALIDATION_ERROR:
                        ActorThatRunsConstantActions(
                            validate_post_setup_action=SVH_VALIDATION_ERROR),

                    EXECUTION__HARD_ERROR:
                        ActorThatRunsConstantActions(
                            validate_post_setup_action=SVH_HARD_ERROR),

                    EXECUTION__IMPLEMENTATION_ERROR:
                        ActorThatRunsConstantActions(
                            validate_post_setup_initial_action=DO_RAISES_EXCEPTION),

                },
            STEP__ACT__PREPARE:
                {
                    EXECUTION__HARD_ERROR:
                        ActorThatRunsConstantActions(
                            prepare_action=SH_HARD_ERROR),

                    EXECUTION__IMPLEMENTATION_ERROR:
                        ActorThatRunsConstantActions(
                            prepare_initial_action=DO_RAISES_EXCEPTION),
                },
            STEP__ACT__EXECUTE:
                {
                    EXECUTION__IMPLEMENTATION_ERROR:
                        ActorThatRunsConstantActions(
                            execute_initial_action=DO_RAISES_EXCEPTION),
                },
        }
        test_case_definition = test_case_definition_for(instruction_set())

        test_case_source = ''

        for step, exit_value_2_constructor in cases.items():
            for exit_value, constructor in exit_value_2_constructor.items():
                expectation = Expectation(exit_value, output_is_sds_which_should_be_preserved)
                with self.subTest(step=step,
                                  exit_value=exit_value.exit_identifier):
                    # ACT & ASSERT #
                    _check(self,
                           test_case_definition,
                           constructor,
                           test_case_source,
                           self.sandbox_dir_resolver_of_given_dir,
                           expectation)
Ejemplo n.º 6
0
    def test_failing_parse(self):
        # ARRANGE #
        test_case_definition = test_case_definition_for(instruction_set())
        actor = ActorThatRunsConstantActions()
        test_case_source = lines_content([
            section_header(phase_identifier.SETUP.identifier),
            'not_the_name_of_an_instruction',
        ])

        expectation = Expectation(NO_EXECUTION__SYNTAX_ERROR, output_is_empty)
        # ACT & ASSERT #
        _check(self, test_case_definition, actor, test_case_source,
               self.sandbox_dir_resolver_that_should_not_be_called,
               expectation)
Ejemplo n.º 7
0
    def test_failing_parse(self):
        # ARRANGE #
        test_case_definition = test_case_definition_for(instruction_set())
        actor = ActorThatRunsConstantActions()
        test_case_source = lines_content([
            section_header(phase_identifier.SETUP.identifier),
            'not_the_name_of_an_instruction',
        ])

        expectation = Expectation(NO_EXECUTION__SYNTAX_ERROR, output_is_empty)
        # ACT & ASSERT #
        _check(self,
               test_case_definition,
               actor,
               test_case_source,
               self.sandbox_dir_resolver_that_should_not_be_called,
               expectation)
Ejemplo n.º 8
0
    def test_act(self):
        # ARRANGE #
        cases = {
            STEP__ACT__PARSE:
                {
                    EXECUTION__IMPLEMENTATION_ERROR:
                        ActorThatRunsConstantActions(
                            parse_atc=DO_RAISES_EXCEPTION),

                },
            STEP__VALIDATE_PRE_SDS:
                {
                    EXECUTION__VALIDATION_ERROR:
                        ActorThatRunsConstantActions(
                            validate_pre_sds_action=SVH_VALIDATION_ERROR),

                    EXECUTION__HARD_ERROR:
                        ActorThatRunsConstantActions(
                            validate_pre_sds_action=SVH_HARD_ERROR),

                    EXECUTION__IMPLEMENTATION_ERROR:
                        ActorThatRunsConstantActions(
                            validate_pre_sds_initial_action=DO_RAISES_EXCEPTION),
                },
        }
        test_case_definition = test_case_definition_for(instruction_set())

        test_case_source = ''

        for step, exit_value_2_constructor in cases.items():
            for exit_value, constructor in exit_value_2_constructor.items():
                expectation = Expectation(exit_value, output_is_empty)
                with self.subTest(step=step,
                                  exit_value=exit_value.exit_identifier):
                    # ACT & ASSERT #
                    _check(self,
                           test_case_definition,
                           constructor,
                           test_case_source,
                           self.sandbox_dir_resolver_that_should_not_be_called,
                           expectation)
Ejemplo n.º 9
0
    def test_act(self):
        # ARRANGE #
        cases = {
            STEP__VALIDATE_POST_SETUP: {
                EXECUTION__VALIDATION_ERROR:
                ActorThatRunsConstantActions(
                    validate_post_setup_action=SVH_VALIDATION_ERROR),
                EXECUTION__HARD_ERROR:
                ActorThatRunsConstantActions(
                    validate_post_setup_action=SVH_HARD_ERROR),
                EXECUTION__INTERNAL_ERROR:
                ActorThatRunsConstantActions(
                    validate_post_setup_initial_action=DO_RAISES_EXCEPTION),
            },
            STEP__ACT__PREPARE: {
                EXECUTION__HARD_ERROR:
                ActorThatRunsConstantActions(prepare_action=SH_HARD_ERROR),
                EXECUTION__INTERNAL_ERROR:
                ActorThatRunsConstantActions(
                    prepare_initial_action=DO_RAISES_EXCEPTION),
            },
            STEP__ACT__EXECUTE: {
                EXECUTION__INTERNAL_ERROR:
                ActorThatRunsConstantActions(
                    execute_initial_action=DO_RAISES_EXCEPTION),
            },
        }
        test_case_definition = test_case_definition_for(instruction_set())

        test_case_source = ''

        for step, exit_value_2_constructor in cases.items():
            for exit_value, actor in exit_value_2_constructor.items():
                expectation = Expectation(
                    exit_value, output_is_sds_which_should_be_preserved)
                with self.subTest(step=step,
                                  exit_value=exit_value.exit_identifier):
                    # ACT & ASSERT #
                    _check(self, test_case_definition, actor, test_case_source,
                           self.sandbox_dir_resolver_of_given_dir, expectation)