コード例 #1
0
 def test_middle_instruction_fails(self):
     recording_media = RecordingMedia()
     instruction_executor = InstructionExecutorThatRecordsInstructionNameAndFailsFor(
         instruction_with_name('Middle instruction'),
         recording_media.new_recorder_with_header('instruction executor'),
         PartialInstructionControlledFailureInfo(
             PartialControlledFailureEnum.FAIL,
             asrt_text_doc.new_single_string_text_for_test('fail message')))
     phase_contents = SectionContents((
         new_instruction_element(Line(1, '1'),
                                 TestInstruction('First instruction')),
         new_instruction_element(Line(2, '2'),
                                 TestInstruction('Middle instruction')),
         new_instruction_element(Line(3, '3'),
                                 TestInstruction('Last instruction')),
     ))
     self._standard_test(
         recording_media, phase_contents, instruction_executor,
         asrt_failure.is_present_with(
             ExecutionFailureStatus.FAIL,
             equals_single_line_source_location_path(Line(2, '2')),
             asrt_failure_details.is_failure_message_of('fail message')), [
                 'instruction header for source line number: 1',
                 'instruction executor: First instruction',
                 'instruction header for source line number: 2',
                 'instruction executor: Middle instruction',
             ])
コード例 #2
0
 def test_SHOULD_be_equal(self):
     # ARRANGE #
     expected = Line(1, 'text')
     actual = Line(1, 'text')
     assertion = sut.equals_line(expected)
     # ACT & ASSERT #
     assertion.apply_without_message(self, actual)
コード例 #3
0
 def test_when_there_are_only_comment_elements_than_the_result_should_be_pass(self):
     phase_contents = SectionContents((new_comment_element(Line(1, '1')),
                                       new_comment_element(Line(2, '2'))))
     self._standard_test_with_successful_instruction_executor(
         phase_contents,
         asrt_failure.is_not_present(),
         ['comment header for source line number: 1',
          'comment header for source line number: 2'])
コード例 #4
0
 def test_successful_sequence(self):
     phase_contents = SectionContents((
         new_instruction_element(Line(1, '1'),
                                 TestInstruction('First instruction')),
         new_comment_element(Line(2, '2')),
         new_instruction_element(Line(3, '3'),
                                 TestInstruction('Second instruction')),
         new_comment_element(Line(4, '4')),
         new_comment_element(Line(50, '50')),
         new_instruction_element(Line(60, '60'),
                                 TestInstruction('Third instruction')),
         new_instruction_element(Line(70, '70'),
                                 TestInstruction('Fourth instruction')),
         new_comment_element(Line(80, '80')),
     ))
     self._standard_test_with_successful_instruction_executor(
         phase_contents, asrt_failure.is_not_present(), [
             'instruction header for source line number: 1',
             'instruction executor: First instruction',
             'comment header for source line number: 2',
             'instruction header for source line number: 3',
             'instruction executor: Second instruction',
             'comment header for source line number: 4',
             'comment header for source line number: 50',
             'instruction header for source line number: 60',
             'instruction executor: Third instruction',
             'instruction header for source line number: 70',
             'instruction executor: Fourth instruction',
             'comment header for source line number: 80',
         ])
コード例 #5
0
    def test_SHOULD_not_be_equal(self):
        # ARRANGE #
        cases = [
            NEA('unequal line number',
                expected=Line(2, 'text'),
                actual=Line(1, 'text')),
            NEA('unequal text',
                expected=Line(1, 'expected'),
                actual=Line(1, 'actual')),
        ]

        for name_and_ea in cases:
            with self.subTest(name_and_ea.name):
                assertion = sut.equals_line(name_and_ea.expected)
                # ACT & ASSERT #
                assert_that_assertion_fails(assertion, name_and_ea.actual)
コード例 #6
0
 def test_successful_execution_of_single_instruction(self):
     phase_contents = SectionContents(
         (new_instruction_element(Line(1, '1'),
                                  TestInstruction('The instruction')), ))
     self._standard_test_with_successful_instruction_executor(
         phase_contents, asrt_failure.is_not_present(), [
             'instruction header for source line number: 1',
             'instruction executor: The instruction'
         ])
コード例 #7
0
 def test_single_exception_raising_instruction_executor(self):
     recording_media = RecordingMedia()
     instruction_executor = InstructionExecutorThatRecordsInstructionNameAndRaisesExceptionFor(
         any_instruction,
         recording_media.new_recorder_with_header('instruction executor'),
         TestException())
     phase_contents = SectionContents(
         (new_instruction_element(Line(1, '1'),
                                  TestInstruction('The instruction')), ))
     self._standard_test(
         recording_media, phase_contents, instruction_executor,
         asrt_failure.is_present_with(
             ExecutionFailureStatus.INTERNAL_ERROR,
             equals_single_line_source_location_path(Line(1, '1')),
             asrt_failure_details.is_exception_of_type(TestException)), [
                 'instruction header for source line number: 1',
                 'instruction executor: The instruction'
             ])
コード例 #8
0
 def test_single_failing_instruction_executor__status_hard_error(self):
     recording_media = RecordingMedia()
     instruction_executor = InstructionExecutorThatRecordsInstructionNameAndFailsFor(
         any_instruction,
         recording_media.new_recorder_with_header('instruction executor'),
         PartialInstructionControlledFailureInfo(
             PartialControlledFailureEnum.HARD_ERROR,
             asrt_text_doc.new_single_string_text_for_test(
                 'hard error message')))
     phase_contents = SectionContents(
         (new_instruction_element(Line(1, '1'),
                                  TestInstruction('The instruction')), ))
     self._standard_test(
         recording_media, phase_contents, instruction_executor,
         asrt_failure.is_present_with(
             ExecutionFailureStatus.HARD_ERROR,
             equals_single_line_source_location_path(Line(1, '1')),
             asrt_failure_details.is_failure_message_of(
                 'hard error message')), [
                     'instruction header for source line number: 1',
                     'instruction executor: The instruction'
                 ])
コード例 #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
ファイル: single_file.py プロジェクト: emilkarlen/exactly
    def test_invalid_section_name_should_raise_exception(self):
        parser = parser_for_sections(['section-header'])
        cases = [
            NEA('first section header is invalid (missing closing bracket)',
                actual=['[section-header'],
                expected=file_source_error_equals_line(Line(1, '[section-header'),
                                                       asrt.is_none)
                ),
            NEA('first section header is invalid (superfluous closing bracket)',
                actual=['[section-header]]'],
                expected=file_source_error_equals_line(Line(1, '[section-header]]'),
                                                       asrt.is_none)
                ),
            NEA('first section header is invalid (content after closing bracket)',
                actual=['[section-header] superfluous'],
                expected=file_source_error_equals_line(Line(1, '[section-header] superfluous'),
                                                       asrt.is_none)

                ),
            NEA('non-first section header is invalid',
                actual=['[section-header]',
                        'instruction 1',
                        '[section-header',
                        ]
                ,
                expected=file_source_error_equals_line(Line(3, '[section-header'),
                                                       asrt.is_none)

                ),
            NEA('section header with unknown section name (as first section header)',
                actual=['[unknown-section-header]',
                        'instruction 1'
                        ]
                ,
                expected=file_source_error_equals_line(Line(1, '[unknown-section-header]'),
                                                       asrt.is_none)
                ),
            NEA('section header with unknown section name (as non-first section header)',
                actual=['[section-header]',
                        'instruction 1',
                        '[unknown-section-header]',
                        'instruction 2',
                        ]
                ,
                expected=file_source_error_equals_line(Line(3, '[unknown-section-header]'),
                                                       asrt.is_none)
                ),
        ]
        for nea in cases:
            with self.subTest(nea.name):
                with self.assertRaises(FileSourceError) as cm:
                    self._parse_lines(parser, nea.actual)
                nea.expected.apply_without_message(self, cm.exception)