Exemplo n.º 1
0
    def test_that_transformer_is_applied(self):
        # ARRANGE #
        source = 'SOURCE'
        p_source = 'PREPROCESSED SOURCE'
        expected_tc = test_case_doc.TestCase(new_empty_section_contents(),
                                             new_empty_section_contents(),
                                             new_empty_section_contents(),
                                             new_empty_section_contents(),
                                             new_empty_section_contents(),
                                             new_empty_section_contents())

        class ConstantTransformer(TestCaseTransformer):
            def transform(
                    self, test_case: test_case_doc.TestCase
            ) -> test_case_doc.TestCase:
                return expected_tc

        accessor = sut.AccessorFromParts(
            SourceReaderThatReturnsIfSame(PATH, source),
            PreprocessorThatReturnsIfSame(source, p_source),
            ParserThatReturnsIfSame(p_source, TEST_CASE),
            ConstantTransformer())
        # ACT #
        actual = accessor.apply(TEST_CASE_REFERENCE)
        # ASSERT #
        self.assertIs(expected_tc, actual)
Exemplo n.º 2
0
 def _generate(self) -> test_case_doc.TestCase:
     return test_case_doc.TestCase(
         self.phase_contents_for(phase_identifier.CONFIGURATION),
         self.phase_contents_for(phase_identifier.SETUP),
         self.phase_contents_for(phase_identifier.ACT),
         self.phase_contents_for(phase_identifier.BEFORE_ASSERT),
         self.phase_contents_for(phase_identifier.ASSERT),
         self.phase_contents_for(phase_identifier.CLEANUP)
     )
Exemplo n.º 3
0
 def build(self) -> test_case_doc.TestCase:
     element_generator = InstructionElementGenerator()
     return test_case_doc.TestCase(element_generator.section_contents(self.configuration_phase),
                                   element_generator.section_contents(self.setup_phase),
                                   element_generator.section_contents(self.act_phase),
                                   element_generator.section_contents(self.before_assert_phase),
                                   element_generator.section_contents(self.assert_phase),
                                   element_generator.section_contents(self.cleanup_phase),
                                   )
Exemplo n.º 4
0
 def apply(self,
           test_case: TestCaseFileReference,
           test_case_source: ParseSource) -> test_case_doc.TestCase:
     document = self.__section_document_parser.parse_source(test_case.file_path,
                                                            test_case_source)
     return test_case_doc.TestCase(
         document.elements_for_section_or_empty_if_phase_not_present(phase_identifier.CONFIGURATION.section_name),
         document.elements_for_section_or_empty_if_phase_not_present(phase_identifier.SETUP.section_name),
         document.elements_for_section_or_empty_if_phase_not_present(phase_identifier.ACT.section_name),
         document.elements_for_section_or_empty_if_phase_not_present(phase_identifier.BEFORE_ASSERT.section_name),
         document.elements_for_section_or_empty_if_phase_not_present(phase_identifier.ASSERT.section_name),
         document.elements_for_section_or_empty_if_phase_not_present(phase_identifier.CLEANUP.section_name),
     )
Exemplo n.º 5
0
def full_test_case_with_instructions(
        configuration_phase_instructions: list = (),
        setup_phase_instructions: list = (),
        act_phase_instructions: list = (),
        before_assert_phase_instructions: list = (),
        assert_phase_instructions: list = (),
        cleanup_phase_instructions: list = ()) -> test_case_doc.TestCase:
    instruction_line_con = instruction_line_constructor()

    def section_contents(instructions: list) -> SectionContents:
        return SectionContents(tuple(map(instruction_line_con, instructions)))

    return test_case_doc.TestCase(
        section_contents(configuration_phase_instructions),
        section_contents(setup_phase_instructions),
        section_contents(act_phase_instructions),
        section_contents(before_assert_phase_instructions),
        section_contents(assert_phase_instructions),
        section_contents(cleanup_phase_instructions))
Exemplo n.º 6
0
def test_case_that_records_property_of_env_for_each_step_of_partial_execution(
        property_recorder: PropertyRecorderBuilder) -> test_case_doc.TestCase:
    element_generator = InstructionElementGenerator()

    return test_case_doc.TestCase(
        element_generator.section_contents([]),
        element_generator.section_contents([
            setup_phase_instruction_that_records_property_of_env_for_each_step(
                property_recorder)
        ]),
        element_generator.section_contents([]),
        element_generator.section_contents([
            before_assert_phase_instruction_that_records_property_of_env_for_each_step(
                property_recorder)
        ]),
        element_generator.section_contents([
            assert_phase_instruction_that_records_property_of_env_for_each_step(
                property_recorder)
        ]),
        element_generator.section_contents([
            cleanup_phase_instruction_that_records_property_of_env_for_each_step(
                property_recorder)
        ]),
    )
Exemplo n.º 7
0
def append_single_char_to_string(s: str) -> str:
    return s + 'x'


def if_same_then_else_raise(expected, actual, result):
    if actual is expected:
        return result
    else:
        raise RuntimeError('should not be invoked')


ERROR_INFO = tcp.ErrorInfo(
    error_description.of_exception(ValueError('exception message')))

PROCESS_ERROR = tcp.ProcessError(ERROR_INFO)

PATH = pathlib.Path('path')

TEST_CASE_REFERENCE = TestCaseFileReference(PATH, pathlib.Path.cwd())

TEST_CASE = test_case_doc.TestCase(new_empty_section_contents(),
                                   new_empty_section_contents(),
                                   new_empty_section_contents(),
                                   new_empty_section_contents(),
                                   new_empty_section_contents(),
                                   new_empty_section_contents())

if __name__ == '__main__':
    unittest.TextTestRunner().run(suite())