Пример #1
0
    def _check(self, exception_from_hierarchy_reader: SuiteReadError):
        # ARRANGE #
        str_std_out_files = StringStdOutFiles()
        suite_root_file_path = Path('root-suite-file')

        suite_hierarchy_reader = ReaderThatRaises(
            exception_from_hierarchy_reader)

        reporter = ExecutionTracingProcessingReporter()
        processor = Processor(
            DUMMY_CASE_PROCESSING, suite_hierarchy_reader, reporter,
            DepthFirstEnumerator(),
            lambda x: TestCaseProcessorThatRaisesUnconditionally())
        # ACT #
        exit_code = processor.process(suite_root_file_path,
                                      str_std_out_files.reporting_environment)
        # ASSERT #
        check_exit_code_and_empty_stdout(self,
                                         exit_values.INVALID_SUITE.exit_code,
                                         exit_code, str_std_out_files)
        expected_invalid_suite_invocations = asrt.matches_sequence([
            asrt.equals(exit_values.INVALID_SUITE),
        ])
        expected_invalid_suite_invocations.apply_with_message(
            self, reporter.report_invalid_suite_invocations,
            'report_invalid_suite_invocations')
        ExpectedSuiteReporting.check_list(self, [],
                                          reporter.complete_suite_reporter)
Пример #2
0
    def test_suite_execution_order_using_empty_suites(self):
        # ARRANGE #
        reporter = ExecutionTracingProcessingReporter()
        str_std_out_files = StringStdOutFiles()
        sub11 = test_suite('11', [], [])
        sub12 = test_suite('12', [], [])
        sub1 = test_suite('1', [sub11, sub12], [])
        sub21 = test_suite('21', [], [])
        sub2 = test_suite('2', [sub21], [])
        root = test_suite('root', [sub1, sub2], [])

        expected_suites = [
            ExpectedSuiteReporting(sub11, []),
            ExpectedSuiteReporting(sub12, []),
            ExpectedSuiteReporting(sub1, []),
            ExpectedSuiteReporting(sub21, []),
            ExpectedSuiteReporting(sub2, []),
            ExpectedSuiteReporting(root, []),
        ]
        suite_hierarchy_reader = ReaderThatGivesConstantSuite(root)
        processor = Processor(
            DUMMY_CASE_PROCESSING, suite_hierarchy_reader, reporter,
            DepthFirstEnumerator(),
            lambda config: TestCaseProcessorThatGivesConstantPerCase({}))
        # ACT #
        exit_code = processor.process(pathlib.Path('root-suite-file'),
                                      str_std_out_files.reporting_environment)
        # ASSERT #
        check_exit_code_and_empty_stdout(
            self, ExecutionTracingRootSuiteReporter.VALID_SUITE_EXIT_CODE,
            exit_code, str_std_out_files)
        ExpectedSuiteReporting.check_list(self, expected_suites,
                                          reporter.complete_suite_reporter)
Пример #3
0
def new_processor(
        setup_phase_instructions: Dict[str, InstructionParser],
        test_case_processor_constructor: TestCaseProcessorConstructor,
        predefined_properties: PredefinedProperties) -> sut.Processor:
    test_case_definition = TestCaseDefinition(
        TestCaseParsingSetup(space_separator_instruction_name_extractor,
                             instruction_setup(setup_phase_instructions),
                             ActPhaseParser()), predefined_properties)
    default_configuration = processors.Configuration(
        test_case_definition,
        test_case_handling_setup_with_identity_preprocessor(),
        os_services_access.new_for_current_os(), 2**10, False,
        sandbox_dir_resolving.mk_tmp_dir_with_prefix('test-suite-'))

    return sut.Processor(
        default_configuration,
        suite_hierarchy_reading.Reader(
            suite_hierarchy_reading.Environment(
                SectionElementParserThatRaisesRecognizedSectionElementSourceError(
                ), test_case_definition.parsing_setup,
                default_configuration.default_handling_setup)),
        ExecutionTracingProcessingReporter(),
        enumeration.DepthFirstEnumerator(),
        test_case_processor_constructor,
    )
Пример #4
0
def check(setup: Setup, put: unittest.TestCase):
    with tempfile.TemporaryDirectory(prefix=program_info.PROGRAM_NAME +
                                     '-test-') as tmp_dir:
        tmp_dir_path = resolved_path(tmp_dir)
        setup.file_structure_to_read(tmp_dir_path).write_to(tmp_dir_path)
        test_case_handling_setup = setup.test_case_handling_setup()
        suite_reading_environment = Environment(
            setup.suite_configuration_section_parser(),
            _TEST_CASE_PARSING_SETUP, test_case_handling_setup)
        hierarchy_reader = Reader(suite_reading_environment)
        reporter = ExecutionTracingProcessingReporter()
        processor = Processor(
            _default_case_configuration(test_case_handling_setup),
            hierarchy_reader, reporter, DepthFirstEnumerator(),
            case_processing.
            new_processor_that_is_allowed_to_pollute_current_process)
        exit_code = processor.process(setup.root_suite_based_at(tmp_dir_path),
                                      null_output_reporting_environment())
        setup.assertions(put, reporter.complete_suite_reporter, exit_code)
Пример #5
0
 def test_single_suite_with_test_cases_with_different_result(self):
     # ARRANGE #
     reporter = ExecutionTracingProcessingReporter()
     str_std_out_files = StringStdOutFiles()
     tc_internal_error = test_case_reference_of_source_file(
         Path('internal error'))
     tc_access_error = test_case_reference_of_source_file(
         Path('access error'))
     tc_executed = test_case_reference_of_source_file(Path('executed'))
     root = test_suite('root', [], [
         tc_internal_error,
         tc_access_error,
         tc_executed,
     ])
     test_case_processor = TestCaseProcessorThatGivesConstantPerCase({
         id(tc_internal_error):
         new_internal_error(error_info.of_message('message')),
         id(tc_access_error):
         new_access_error(tcp.AccessErrorType.SYNTAX_ERROR,
                          error_info.of_message('syntax error')),
         id(tc_executed):
         new_executed(FULL_RESULT_PASS),
     })
     expected_suites = [
         ExpectedSuiteReporting(root, [
             (tc_internal_error, tcp.Status.INTERNAL_ERROR),
             (tc_access_error, tcp.Status.ACCESS_ERROR),
             (tc_executed, tcp.Status.EXECUTED),
         ])
     ]
     suite_hierarchy_reader = ReaderThatGivesConstantSuite(root)
     processor = Processor(DUMMY_CASE_PROCESSING, suite_hierarchy_reader,
                           reporter, DepthFirstEnumerator(),
                           lambda config: test_case_processor)
     # ACT #
     exit_code = processor.process(pathlib.Path('root-suite-file'),
                                   str_std_out_files.reporting_environment)
     # ASSERT #
     check_exit_code_and_empty_stdout(
         self, ExecutionTracingRootSuiteReporter.VALID_SUITE_EXIT_CODE,
         exit_code, str_std_out_files)
     ExpectedSuiteReporting.check_list(self, expected_suites,
                                       reporter.complete_suite_reporter)
Пример #6
0
 def _check(self, result: tcp.Result):
     # ARRANGE #
     str_std_out_files = StringStdOutFiles()
     test_case = test_case_reference_of_source_file(Path('test-case'))
     root = test_suite('root', [], [test_case])
     suite_hierarchy_reader = ReaderThatGivesConstantSuite(root)
     reporter = ExecutionTracingProcessingReporter()
     executor = Processor(
         DUMMY_CASE_PROCESSING, suite_hierarchy_reader, reporter,
         DepthFirstEnumerator(),
         lambda config: TestCaseProcessorThatGivesConstant(result))
     # ACT #
     exit_code = executor.process(pathlib.Path('root-suite-file'),
                                  str_std_out_files.reporting_environment)
     # ASSERT #
     check_exit_code_and_empty_stdout(
         self, ExecutionTracingRootSuiteReporter.VALID_SUITE_EXIT_CODE,
         exit_code, str_std_out_files)
     ExpectedSuiteReporting.check_list(
         self, [ExpectedSuiteReporting(root, [(test_case, result.status)])],
         reporter.complete_suite_reporter)
Пример #7
0
    def test_complex_suite_structure_with_test_cases(self):
        # ARRANGE #
        reporter = ExecutionTracingProcessingReporter()
        str_std_out_files = StringStdOutFiles()
        tc_internal_error_11 = test_case_reference_of_source_file(
            Path('internal error 11'))
        tc_internal_error_21 = test_case_reference_of_source_file(
            Path('internal error 21'))
        tc_access_error_1 = test_case_reference_of_source_file(
            Path('access error A'))
        tc_access_error_12 = test_case_reference_of_source_file(
            Path('access error 12'))
        tc_executed_11 = test_case_reference_of_source_file(
            Path('executed 11'))
        tc_executed_12 = test_case_reference_of_source_file(
            Path('executed 12'))
        tc_executed_1 = test_case_reference_of_source_file(Path('executed 1'))
        tc_executed_2 = test_case_reference_of_source_file(Path('executed 2'))
        tc_executed_root = test_case_reference_of_source_file(
            Path('executed root'))
        test_case_processor = TestCaseProcessorThatGivesConstantPerCase({
            id(tc_internal_error_11):
            new_internal_error(error_info.of_message('message A')),
            id(tc_internal_error_21):
            new_internal_error(error_info.of_message('message B')),
            id(tc_access_error_1):
            new_access_error(tcp.AccessErrorType.SYNTAX_ERROR,
                             error_info.of_message('syntax error')),
            id(tc_access_error_12):
            new_access_error(tcp.AccessErrorType.FILE_ACCESS_ERROR,
                             error_info.of_message('file access error')),
            id(tc_executed_11):
            new_executed(FULL_RESULT_PASS),
            id(tc_executed_12):
            new_executed(FULL_RESULT_PASS),
            id(tc_executed_1):
            new_executed(FULL_RESULT_PASS),
            id(tc_executed_2):
            new_executed(FULL_RESULT_PASS),
            id(tc_executed_root):
            new_executed(FULL_RESULT_PASS),
        })
        sub11 = test_suite('11', [], [tc_internal_error_11, tc_executed_11])
        sub12 = test_suite('12', [], [tc_executed_12, tc_access_error_12])
        sub1 = test_suite('1', [sub11, sub12],
                          [tc_access_error_1, tc_executed_1])
        sub21 = test_suite('21', [], [tc_internal_error_21])
        sub2 = test_suite('2', [sub21], [tc_executed_2])
        sub3 = test_suite('2', [], [])
        root = test_suite('root', [sub1, sub2, sub3], [tc_executed_root])

        expected_suites = [
            ExpectedSuiteReporting(
                sub11, [(tc_internal_error_11, tcp.Status.INTERNAL_ERROR),
                        (tc_executed_11, tcp.Status.EXECUTED)]),
            ExpectedSuiteReporting(
                sub12, [(tc_executed_12, tcp.Status.EXECUTED),
                        (tc_access_error_12, tcp.Status.ACCESS_ERROR)]),
            ExpectedSuiteReporting(
                sub1, [(tc_access_error_1, tcp.Status.ACCESS_ERROR),
                       (tc_executed_1, tcp.Status.EXECUTED)]),
            ExpectedSuiteReporting(
                sub21, [(tc_internal_error_21, tcp.Status.INTERNAL_ERROR)]),
            ExpectedSuiteReporting(sub2,
                                   [(tc_executed_2, tcp.Status.EXECUTED)]),
            ExpectedSuiteReporting(sub3, []),
            ExpectedSuiteReporting(root,
                                   [(tc_executed_root, tcp.Status.EXECUTED)]),
        ]
        suite_hierarchy_reader = ReaderThatGivesConstantSuite(root)
        processor = Processor(DUMMY_CASE_PROCESSING, suite_hierarchy_reader,
                              reporter, DepthFirstEnumerator(),
                              lambda config: test_case_processor)
        # ACT #
        exit_code = processor.process(pathlib.Path('root-suite-file'),
                                      str_std_out_files.reporting_environment)
        # ASSERT #
        check_exit_code_and_empty_stdout(
            self, ExecutionTracingRootSuiteReporter.VALID_SUITE_EXIT_CODE,
            exit_code, str_std_out_files)
        ExpectedSuiteReporting.check_list(self, expected_suites,
                                          reporter.complete_suite_reporter)