Пример #1
0
def _from_success_or_validation_error_or_hard_error(
    res: svh.SuccessOrValidationErrorOrHardError,
) -> Optional[PartialInstructionControlledFailureInfo]:
    if res.is_success:
        return None
    elif res.is_validation_error:
        return PartialInstructionControlledFailureInfo(
            PartialControlledFailureEnum.VALIDATION_ERROR, res.failure_message)
    else:
        return PartialInstructionControlledFailureInfo(
            PartialControlledFailureEnum.HARD_ERROR, res.failure_message)
Пример #2
0
def _validate_symbol_reference(
    symbol_table: SymbolTable,
    reference: SymbolReference,
) -> Optional[PartialInstructionControlledFailureInfo]:
    assert isinstance(reference, SymbolReference)
    if not symbol_table.contains(reference.name):
        return PartialInstructionControlledFailureInfo(
            PartialControlledFailureEnum.VALIDATION_ERROR,
            error_messages.undefined_symbol(reference))
    else:
        err_msg = _validate_reference(reference, symbol_table)
        if err_msg is not None:
            return PartialInstructionControlledFailureInfo(
                PartialControlledFailureEnum.VALIDATION_ERROR, err_msg)
    return None
Пример #3
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',
             ])
Пример #4
0
def _from_pass_or_fail_or_hard_error(
    res: pfh.PassOrFailOrHardError
) -> Optional[PartialInstructionControlledFailureInfo]:
    if res.status is pfh.PassOrFailOrHardErrorEnum.PASS:
        return None
    else:
        return PartialInstructionControlledFailureInfo(
            PartialControlledFailureEnum(res.status.value),
            res.failure_message)
Пример #5
0
def _validate_symbol_definition(
    symbol_table: SymbolTable,
    definition: SymbolDefinition,
) -> Optional[PartialInstructionControlledFailureInfo]:
    if symbol_table.contains(definition.name):
        already_defined_sdv_container = symbol_table.lookup(definition.name)
        assert isinstance(already_defined_sdv_container, SymbolContainer), \
            'Value in SymTbl must be ResolverContainer'
        return PartialInstructionControlledFailureInfo(
            PartialControlledFailureEnum.VALIDATION_ERROR,
            error_messages.duplicate_symbol_definition(
                already_defined_sdv_container.source_location,
                definition.name))
    else:
        for referenced_value in definition.references:
            failure_info = validate_symbol_usage(referenced_value,
                                                 symbol_table)
            if failure_info is not None:
                return failure_info
        symbol_table.add(definition.symbol_table_entry)
        return None
Пример #6
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'
                 ])
Пример #7
0
def _from_success_or_hard_error(
        res: sh.SuccessOrHardError) -> PartialInstructionControlledFailureInfo:
    return (None
            if res.is_success else PartialInstructionControlledFailureInfo(
                PartialControlledFailureEnum.HARD_ERROR, res.failure_message))