예제 #1
0
    def _check_failing_line(self,
                            configuration: sut.Configuration,
                            phases: Sequence[Phase],
                            invalid_line_cases: Sequence[NameAndValue[SourceAndStatus]]):
        proc_cases = [
            NameAndValue('not allowed to pollute current process',
                         sut.new_processor_that_should_not_pollute_current_process(configuration)),
            NameAndValue('allowed to pollute current process',
                         sut.new_processor_that_is_allowed_to_pollute_current_process(configuration)),
        ]
        for phase in phases:
            for invalid_line_case in invalid_line_cases:
                source_and_status = invalid_line_case.value
                assert isinstance(source_and_status, SourceAndStatus)  # Type info for IDE

                file_with_error = fs.file_with_lines('file-with-error.src', [
                    source_and_status.failing_source_line,
                ])
                erroneous_line = single_line_sequence(1, source_and_status.failing_source_line)

                test_case_file = fs.file_with_lines('test.case', [
                    section_header(phase.section_name),
                    directive_for_inclusion_of_file(file_with_error.name),
                ])
                line_that_includes_erroneous_file = single_line_sequence(2, directive_for_inclusion_of_file(
                    file_with_error.name))

                cwd_contents = fs.DirContents([test_case_file,
                                               file_with_error])

                expected_source_location_path = SourceLocationPath(
                    location=SourceLocation(erroneous_line,
                                            pathlib.Path(file_with_error.name)),
                    file_inclusion_chain=[SourceLocation(line_that_includes_erroneous_file,
                                                         pathlib.Path(test_case_file.name))])

                for proc_case in proc_cases:
                    with self.subTest(phase=phase.section_name,
                                      proc=proc_case.name,
                                      line=erroneous_line.first_line):
                        processor = proc_case.value
                        assert isinstance(processor, Processor)
                        with tmp_dir_as_cwd(cwd_contents):
                            test_case_reference = test_case_reference_of_source_file(pathlib.Path(test_case_file.name))
                            # ACT #
                            result = processor.apply(test_case_reference)
                            # ASSERT #
                            assert isinstance(result, Result)  # Type info for IDE

                            source_and_status.expected_result_statuses.apply_with_message(self,
                                                                                          result,
                                                                                          'result statuses')

                            source_location_path_expectation = equals_source_location_path(
                                expected_source_location_path)
                            source_location_path_expectation.apply_with_message(self,
                                                                                result.source_location_path,
                                                                                'source location path')
예제 #2
0
    def test_relative_path_to_root_file_in_sub_dir_of_cwd(self):
        # ARRANGE #

        root_file_sub_dir_path = Path('sub-dir')

        root_file_in_sub_dir = file_with_lines('root-file-base-name.src', [
            phase_names.CONFIGURATION.syntax,
            INSTR_THAT_ASSERTS_SOURCE_INFO_MATCHES_LOCATION,
        ])

        cwd_dir_contents = DirContents([
            Dir(str(root_file_sub_dir_path), [
                root_file_in_sub_dir,
            ])
        ])

        file_arg_to_parser_rel_cwd = root_file_sub_dir_path / root_file_in_sub_dir.name

        with tmp_dir_as_cwd(cwd_dir_contents) as abs_cwd_dir_path:
            instruction_parser_file_loc_assertion = matches_file_location_info(
                abs_path_of_dir_containing_first_file_path=asrt.equals(abs_cwd_dir_path),
                file_path_rel_referrer=asrt.equals(file_arg_to_parser_rel_cwd),
                file_inclusion_chain=asrt.is_empty_sequence,
            )

            # ACT & ASSERT #

            fail_if_test_case_does_not_pass(
                self,
                file_arg_to_parser_rel_cwd,
                test_case_definition_with_config_phase_assertion_instruction(self,
                                                                             instruction_parser_file_loc_assertion))
예제 #3
0
    def test_relative_path_to_root_file_in_sub_dir_of_cwd(self):
        # ARRANGE #

        root_file_sub_dir_path = Path('sub-dir')

        root_file_in_sub_dir = file_with_lines('root-file-base-name.src', [
            phase_names.CONFIGURATION.syntax,
            INSTR_THAT_ASSERTS_SOURCE_INFO_MATCHES_LOCATION,
        ])

        cwd_dir_contents = DirContents([
            Dir(str(root_file_sub_dir_path), [
                root_file_in_sub_dir,
            ])
        ])

        file_arg_to_parser_rel_cwd = root_file_sub_dir_path / root_file_in_sub_dir.name

        with tmp_dir_as_cwd(cwd_dir_contents) as abs_cwd_dir_path:
            instruction_parser_file_loc_assertion = matches_file_location_info(
                abs_path_of_dir_containing_first_file_path=asrt.equals(abs_cwd_dir_path),
                file_path_rel_referrer=asrt.equals(file_arg_to_parser_rel_cwd),
                file_inclusion_chain=asrt.is_empty_sequence,
            )

            # ACT & ASSERT #

            fail_if_test_case_does_not_pass(
                self,
                file_arg_to_parser_rel_cwd,
                test_case_definition_with_config_phase_assertion_instruction(self,
                                                                             instruction_parser_file_loc_assertion))
예제 #4
0
    def test_relative_path_to_root_file_in_sub_dir_of_cwd(self):
        # ARRANGE #

        root_file_sub_dir_path = Path('sub-dir')
        root_file_base_name = 'root-file-base-name.src'

        root_file_in_sub_dir = file_with_lines(root_file_base_name, [
            phase_names.CONFIGURATION.syntax,
            INSTR_THAT_ASSERTS_HDS_DIR_MATCHES_PATH,
        ])

        cwd_dir_contents = DirContents(
            [Dir(str(root_file_sub_dir_path), [
                root_file_in_sub_dir,
            ])])

        file_arg_to_parser_rel_cwd = root_file_sub_dir_path / root_file_base_name

        with tmp_dir_as_cwd(cwd_dir_contents) as abs_cwd_dir_path:
            hds_dir_assertion = asrt.equals(abs_cwd_dir_path /
                                            root_file_sub_dir_path)

            # ACT & ASSERT #

            fail_if_test_case_does_not_pass(
                self, file_arg_to_parser_rel_cwd,
                test_case_definition_with_config_phase_assertion_instruction(
                    self, hds_dir_assertion))
예제 #5
0
    def test_inclusion_of_file_SHOULD_be_possible_in_all_phases_except_act(
            self):
        # ARRANGE #
        name_of_recording_instruction = 'recording-instruction'

        file_to_include = fs.file_with_lines('included-file.src', [
            name_of_recording_instruction,
        ])
        proc_cases = [
            NameAndValue(
                'not allowed to pollute current process',
                sut.new_processor_that_should_not_pollute_current_process),
            NameAndValue(
                'allowed to pollute current process',
                sut.new_processor_that_is_allowed_to_pollute_current_process),
        ]
        for phase in phase_identifier.ALL_WITH_INSTRUCTIONS:
            for proc_case in proc_cases:
                with self.subTest(phase.section_name, proc=proc_case.name):
                    test_case_file = fs.file_with_lines(
                        'test.case', [
                            section_header(phase.section_name),
                            directive_for_inclusion_of_file(
                                file_to_include.name),
                        ])
                    cwd_contents = fs.DirContents(
                        [test_case_file, file_to_include])
                    recording_output = []
                    configuration = configuration_with_instruction_in_each_phase_that_records_phase_name(
                        name_of_recording_instruction, recording_output)
                    processor = proc_case.value(configuration)
                    with tmp_dir_as_cwd(cwd_contents):
                        test_case_reference = test_case_reference_of_source_file(
                            pathlib.Path(test_case_file.name))
                        # ACT #
                        result = processor.apply(test_case_reference)
                        # ASSERT #
                        assert isinstance(result, Result)  # Type info for IDE
                        self.assertEqual(Status.EXECUTED, result.status)
                        self.assertFalse(result.execution_result.is_failure)
                        self.assertEqual(FullExeResultStatus.PASS,
                                         result.execution_result.status)
                        self.assertEqual([phase.section_name],
                                         recording_output)
예제 #6
0
    def test_inclusion_of_file_SHOULD_be_possible_in_all_phases_except_act(self):
        # ARRANGE #
        name_of_recording_instruction = 'recording-instruction'

        file_to_include = fs.file_with_lines('included-file.src', [
            name_of_recording_instruction,
        ])
        proc_cases = [
            NameAndValue('not allowed to pollute current process',
                         sut.new_processor_that_should_not_pollute_current_process),
            NameAndValue('allowed to pollute current process',
                         sut.new_processor_that_is_allowed_to_pollute_current_process),
        ]
        for phase in phase_identifier.ALL_WITH_INSTRUCTIONS:
            for proc_case in proc_cases:
                with self.subTest(phase.section_name,
                                  proc=proc_case.name):
                    test_case_file = fs.file_with_lines('test.case', [
                        section_header(phase.section_name),
                        directive_for_inclusion_of_file(file_to_include.name),
                    ])
                    cwd_contents = fs.DirContents([test_case_file,
                                                   file_to_include])
                    recording_output = []
                    configuration = configuration_with_instruction_in_each_phase_that_records_phase_name(
                        name_of_recording_instruction,
                        recording_output)
                    processor = proc_case.value(configuration)
                    with tmp_dir_as_cwd(cwd_contents):
                        test_case_reference = test_case_reference_of_source_file(pathlib.Path(test_case_file.name))
                        # ACT #
                        result = processor.apply(test_case_reference)
                        # ASSERT #
                        assert isinstance(result, Result)  # Type info for IDE
                        self.assertEqual(Status.EXECUTED,
                                         result.status)
                        self.assertFalse(result.execution_result.is_failure)
                        self.assertEqual(FullExeResultStatus.PASS,
                                         result.execution_result.status)
                        self.assertEqual([phase.section_name],
                                         recording_output)
예제 #7
0
 def test_inclusion_of_non_exiting_file_SHOULD_cause_file_access_error(
         self):
     # ARRANGE #
     name_of_non_existing_file = 'non-existing.src'
     configuration = configuration_with_no_instructions_and_no_preprocessor(
     )
     proc_cases = [
         NameAndValue(
             'not allowed to pollute current process',
             sut.new_processor_that_should_not_pollute_current_process(
                 configuration)),
         NameAndValue(
             'allowed to pollute current process',
             sut.new_processor_that_is_allowed_to_pollute_current_process(
                 configuration)),
     ]
     for phase in phase_identifier.ALL_WITH_INSTRUCTIONS:
         for proc_case in proc_cases:
             with self.subTest(phase.section_name, proc=proc_case.name):
                 test_case_file = fs.file_with_lines(
                     'test.case', [
                         section_header(phase.section_name),
                         directive_for_inclusion_of_file(
                             name_of_non_existing_file),
                     ])
                 cwd_contents = fs.DirContents([test_case_file])
                 processor = proc_case.value
                 assert isinstance(processor, Processor)
                 with tmp_dir_as_cwd(cwd_contents):
                     test_case_reference = test_case_reference_of_source_file(
                         pathlib.Path(test_case_file.name))
                     # ACT #
                     result = processor.apply(test_case_reference)
                     # ASSERT #
                     assert isinstance(result, Result)  # Type info for IDE
                     self.assertEqual(Status.ACCESS_ERROR, result.status)
                     self.assertEqual(AccessErrorType.FILE_ACCESS_ERROR,
                                      result.access_error_type)
                     source_location_path_expectation = equals_source_location_path(
                         source_location_path_of(
                             pathlib.Path(test_case_file.name),
                             Line(
                                 2,
                                 directive_for_inclusion_of_file(
                                     name_of_non_existing_file))))
                     source_location_path_expectation.apply_with_message(
                         self, result.error_info.source_location_path,
                         'source location path')
예제 #8
0
    def test_relative_path_to_root_file_in_cwd(self):
        # ARRANGE #

        root_file_base_name = 'root-file-base-name.src'

        root_file_in_cwd = file_with_lines(root_file_base_name, [
            phase_names.SETUP.syntax,
            INSTR_THAT_ASSERTS_ENV_VARS,
        ])

        cwd_dir_contents = DirContents([root_file_in_cwd])

        with tmp_dir_as_cwd(cwd_dir_contents):
            expected_default = None
            expected_from_defaults_getter = dict(os.environ)

            # ACT & ASSERT #

            fail_if_test_case_does_not_pass(
                self, Path(root_file_base_name),
                test_case_definition_with_setup_phase_assertion_instruction(
                    self, expected_default, expected_from_defaults_getter))
예제 #9
0
 def test_inclusion_of_non_exiting_file_SHOULD_cause_file_access_error(self):
     # ARRANGE #
     name_of_non_existing_file = 'non-existing.src'
     configuration = configuration_with_no_instructions_and_no_preprocessor()
     proc_cases = [
         NameAndValue('not allowed to pollute current process',
                      sut.new_processor_that_should_not_pollute_current_process(configuration)),
         NameAndValue('allowed to pollute current process',
                      sut.new_processor_that_is_allowed_to_pollute_current_process(configuration)),
     ]
     for phase in phase_identifier.ALL_WITH_INSTRUCTIONS:
         for proc_case in proc_cases:
             with self.subTest(phase.section_name,
                               proc=proc_case.name):
                 test_case_file = fs.file_with_lines('test.case', [
                     section_header(phase.section_name),
                     directive_for_inclusion_of_file(name_of_non_existing_file),
                 ])
                 cwd_contents = fs.DirContents([test_case_file])
                 processor = proc_case.value
                 assert isinstance(processor, Processor)
                 with tmp_dir_as_cwd(cwd_contents):
                     test_case_reference = test_case_reference_of_source_file(pathlib.Path(test_case_file.name))
                     # ACT #
                     result = processor.apply(test_case_reference)
                     # ASSERT #
                     assert isinstance(result, Result)  # Type info for IDE
                     self.assertEqual(Status.ACCESS_ERROR,
                                      result.status)
                     self.assertEqual(AccessErrorType.FILE_ACCESS_ERROR,
                                      result.access_error_type)
                     source_location_path_expectation = equals_source_location_path(
                         source_location_path_of(pathlib.Path(test_case_file.name),
                                                 Line(2,
                                                      directive_for_inclusion_of_file(name_of_non_existing_file))))
                     source_location_path_expectation.apply_with_message(self,
                                                                         result.error_info.source_location_path,
                                                                         'source location path')
예제 #10
0
    def test_abs_path_to_root_file_in_cwd(self):
        # ARRANGE #

        root_file_base_name = 'root-file-base-name.src'

        root_file_in_cwd = file_with_lines(root_file_base_name, [
            phase_names.CONFIGURATION.syntax,
            INSTR_THAT_ASSERTS_HDS_DIR_MATCHES_PATH,
        ])

        cwd_dir_contents = DirContents([root_file_in_cwd])

        with tmp_dir_as_cwd(cwd_dir_contents) as abs_cwd_dir_path:
            abs_file_arg_to_parser = abs_cwd_dir_path / root_file_base_name

            hds_dir_assertion = asrt.equals(abs_cwd_dir_path)

            # ACT & ASSERT #

            fail_if_test_case_does_not_pass(
                self, abs_file_arg_to_parser,
                test_case_definition_with_config_phase_assertion_instruction(
                    self, hds_dir_assertion))
예제 #11
0
    def test_relative_path_to_root_file_in_cwd(self):
        # ARRANGE #

        root_file_base_name = 'root-file-base-name.src'

        root_file_in_cwd = file_with_lines(root_file_base_name, [
            phase_names.SETUP.syntax,
            INSTR_THAT_ASSERTS_ENV_VARS,
        ])

        cwd_dir_contents = DirContents([
            root_file_in_cwd
        ])

        with tmp_dir_as_cwd(cwd_dir_contents):
            expected_env_vars_to_exist_at_least = os.environ

            # ACT & ASSERT #

            fail_if_test_case_does_not_pass(
                self,
                Path(root_file_base_name),
                test_case_definition_with_setup_phase_assertion_instruction(self,
                                                                            expected_env_vars_to_exist_at_least))
예제 #12
0
    def _check_failing_line(
            self, configuration: sut.Configuration, phases: Sequence[Phase],
            invalid_line_cases: Sequence[NameAndValue[SourceAndStatus]]):
        proc_cases = [
            NameAndValue(
                'not allowed to pollute current process',
                sut.new_processor_that_should_not_pollute_current_process(
                    configuration)),
            NameAndValue(
                'allowed to pollute current process',
                sut.new_processor_that_is_allowed_to_pollute_current_process(
                    configuration)),
        ]
        for phase in phases:
            for invalid_line_case in invalid_line_cases:
                source_and_status = invalid_line_case.value
                assert isinstance(source_and_status,
                                  SourceAndStatus)  # Type info for IDE

                file_with_error = fs.file_with_lines('file-with-error.src', [
                    source_and_status.failing_source_line,
                ])
                erroneous_line = single_line_sequence(
                    1, source_and_status.failing_source_line)

                test_case_file = fs.file_with_lines('test.case', [
                    section_header(phase.section_name),
                    directive_for_inclusion_of_file(file_with_error.name),
                ])
                line_that_includes_erroneous_file = single_line_sequence(
                    2, directive_for_inclusion_of_file(file_with_error.name))

                cwd_contents = fs.DirContents(
                    [test_case_file, file_with_error])

                expected_source_location_path = SourceLocationPath(
                    location=SourceLocation(erroneous_line,
                                            pathlib.Path(
                                                file_with_error.name)),
                    file_inclusion_chain=[
                        SourceLocation(line_that_includes_erroneous_file,
                                       pathlib.Path(test_case_file.name))
                    ])

                for proc_case in proc_cases:
                    with self.subTest(phase=phase.section_name,
                                      proc=proc_case.name,
                                      line=erroneous_line.first_line):
                        processor = proc_case.value
                        assert isinstance(processor, Processor)
                        with tmp_dir_as_cwd(cwd_contents):
                            test_case_reference = test_case_reference_of_source_file(
                                pathlib.Path(test_case_file.name))
                            # ACT #
                            result = processor.apply(test_case_reference)
                            # ASSERT #
                            assert isinstance(result,
                                              Result)  # Type info for IDE

                            source_and_status.expected_result_statuses.apply_with_message(
                                self, result, 'result statuses')

                            source_location_path_expectation = equals_source_location_path(
                                expected_source_location_path)
                            source_location_path_expectation.apply_with_message(
                                self, result.source_location_path,
                                'source location path')