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)
def test_accessor_exception_from_accessor(self): # ARRANGE # process_error = tcp.ProcessError( error_info.of_exception(ValueError('exception message'))) accessor = sut.AccessorFromParts( SourceReaderThat(raises(process_error)), PreprocessorThat(gives_constant('preprocessed source')), ParserThat(gives_constant(TEST_CASE)), identity_test_case_transformer()) executor = ExecutorThat(raises(PROCESS_ERROR)) processor = sut.ProcessorFromAccessorAndExecutor(accessor, executor) # ACT # result = processor.apply(tcp.test_case_reference_of_source_file(PATH)) # ASSERT # self.assertIs(tcp.Status.ACCESS_ERROR, result.status) self.assertIs(tcp.AccessErrorType.FILE_ACCESS_ERROR, result.access_error_type) self.assertIsNotNone(result.error_info, 'There should be ErrorInfo') err_description = result.error_info.description self.assertIsInstance(err_description, error_description.ErrorDescriptionOfException) assert isinstance(err_description, error_description.ErrorDescriptionOfException) self.assertEqual(err_description.exception.args[0], 'exception message')
def new_accessor( preprocessor: Preprocessor, test_case_parsing_setup: TestCaseParsingSetup, test_case_transformer: TestCaseTransformer) -> processing.Accessor: return processing_utils.AccessorFromParts(_SourceReader(), preprocessor, _Parser(test_case_parsing_setup), test_case_transformer)
def test_implementation_exception_from_executor(self): # ARRANGE # accessor = sut.AccessorFromParts( SourceReaderThat(gives_constant('source')), PreprocessorThat(gives_constant('preprocessed source')), ParserThat(gives_constant(TEST_CASE)), identity_test_case_transformer()) executor = ExecutorThat(raises(RuntimeError())) processor = sut.ProcessorFromAccessorAndExecutor(accessor, executor) # ACT # result = processor.apply(tcp.test_case_reference_of_source_file(PATH)) # ASSERT # self.assertEqual(tcp.Status.INTERNAL_ERROR, result.status)
def test_successful_application(self): # ARRANGE # source = 'SOURCE' p_source = 'PREPROCESSED SOURCE' accessor = sut.AccessorFromParts( SourceReaderThatReturnsIfSame(PATH, source), PreprocessorThatReturnsIfSame(source, p_source), ParserThatReturnsIfSame(p_source, TEST_CASE), identity_test_case_transformer()) # ACT # actual = accessor.apply(TEST_CASE_REFERENCE) # ASSERT # self.assertIs(TEST_CASE, actual)
def test_parser_that_raises(self): # ARRANGE # accessor = sut.AccessorFromParts( SourceReaderThat(gives_constant('source')), PreprocessorThat(gives_constant('preprocessed source')), ParserThat(raises(PROCESS_ERROR)), identity_test_case_transformer()) # ACT # with self.assertRaises(tcp.AccessorError) as cm: accessor.apply(TEST_CASE_REFERENCE) # ASSERT # expectation = asrt_tc_proc.accessor_error_matches( error=asrt.equals(tcp.AccessErrorType.SYNTAX_ERROR)) expectation.apply_with_message(self, cm.exception, 'exception data')
def test_source_reader_that_raises(self): # ARRANGE # accessor = sut.AccessorFromParts( SourceReaderThat(raises(PROCESS_ERROR)), PreprocessorThat(raises_should_not_be_invoked_error), ParserThat(raises_should_not_be_invoked_error), identity_test_case_transformer()) # ACT # with self.assertRaises(tcp.AccessorError) as cm: accessor.apply(TEST_CASE_REFERENCE) # ASSERT # expectation = asrt_tc_proc.accessor_error_matches( error=asrt.equals(tcp.AccessErrorType.FILE_ACCESS_ERROR)) expectation.apply_with_message(self, cm.exception, 'exception data')
def test_successful_application(self): # ARRANGE # accessor = sut.AccessorFromParts( SourceReaderThat(gives_constant('source')), PreprocessorThat(gives_constant('preprocessed source')), ParserThat(gives_constant(TEST_CASE)), identity_test_case_transformer()) full_result = new_skipped() executor = ExecutorThatReturnsIfSame(TEST_CASE, full_result) processor = sut.ProcessorFromAccessorAndExecutor(accessor, executor) # ACT # result = processor.apply(tcp.test_case_reference_of_source_file(PATH)) # ASSERT # self.assertIs(tcp.Status.EXECUTED, result.status) self.assertIs(full_result, result.execution_result)