示例#1
0
def equals_container(
        expected: SymbolContainer,
        ignore_source_line: bool = True) -> Assertion[SymbolContainer]:
    """
    :param expected: Must contain a data type value
    """

    component_assertions = [
        asrt.sub_component('value_type', SymbolContainer.value_type.fget,
                           asrt.is_(expected.value_type)),
    ]

    if not ignore_source_line:
        component_assertions.append(
            asrt.sub_component(
                'definition_source', SymbolContainer.definition_source.fget,
                equals_line_sequence(expected.definition_source)))
    component_assertions.append(
        asrt.sub_component(
            'source_location', SymbolContainer.source_location.fget,
            asrt.is_none_or_instance_with(
                SourceLocationInfo,
                asrt_src_loc.is_valid_source_location_info())), )

    expected_sdv = expected.sdv
    assert isinstance(expected_sdv,
                      DataTypeSdv), 'All actual values must be DataTypeSdv'
    component_assertions.append(
        asrt.sub_component('sdv', SymbolContainer.sdv.fget,
                           equals_data_type_sdv(expected_sdv)))
    return asrt.is_instance_with(SymbolContainer,
                                 asrt.and_(component_assertions))
示例#2
0
def equals_list_resolver_element(expected: list_resolver.Element,
                                 symbols: SymbolTable = None) -> ValueAssertion:
    if symbols is None:
        symbols = symbol_table_with_values_matching_references(list(expected.references))
    expected_resolved_value_list = expected.resolve(symbols)
    assertion_on_resolved_value = asrt.matches_sequence(
        [equals_string_value(sv) for sv in expected_resolved_value_list])
    component_assertions = [
        asrt.sub_component('references',
                           lambda x: list(x.references),
                           equals_symbol_references(list(expected.references))),
        asrt.sub_component('resolved value',
                           lambda x: x.resolve(symbols),
                           assertion_on_resolved_value),

    ]
    symbol_reference_assertion = asrt.is_none
    if expected.symbol_reference_if_is_symbol_reference is not None:
        symbol_reference_assertion = equals_symbol_reference(expected.symbol_reference_if_is_symbol_reference)
    symbol_reference_component_assertion = asrt.sub_component('symbol_reference_if_is_symbol_reference',
                                                              lambda x: x.symbol_reference_if_is_symbol_reference,
                                                              symbol_reference_assertion)
    component_assertions.append(symbol_reference_component_assertion)
    return asrt.is_instance_with(
        list_resolver.Element,
        asrt.and_(component_assertions))
示例#3
0
 def test_false__with_message_builder(self):
     with self.assertRaises(TestException):
         value = ['not none']
         sut.sub_component('component name', lambda x: x[0],
                           sut.ValueIsNone()).apply(
                               self.put, value,
                               sut.MessageBuilder('message head'))
示例#4
0
def is_failure__of_indirect_reference(
    failing_symbol: Assertion[str] = asrt.is_instance(str),
    path_to_failing_symbol: Assertion[Sequence[str]] = asrt.is_instance(list),
    error_message: Assertion[TextRenderer] = asrt_text_doc.is_any_text(),
    meaning_of_failure: Assertion[
        Optional[TextRenderer]] = asrt.is_none_or_instance_with(
            SequenceRenderer, asrt_text_doc.is_any_text()),
) -> Assertion[Failure]:
    return asrt.is_instance_with(
        FailureOfIndirectReference,
        asrt.and_([
            asrt.sub_component('failing_symbol',
                               FailureOfIndirectReference.failing_symbol.fget,
                               failing_symbol),
            asrt.sub_component(
                'path_to_failing_symbol',
                FailureOfIndirectReference.path_to_failing_symbol.fget,
                path_to_failing_symbol),
            asrt.sub_component(
                'error', FailureOfIndirectReference.error.fget,
                asrt_val_rest.matches_value_restriction_failure(
                    error_message)),
            asrt.sub_component(
                'meaning_of_failure',
                FailureOfIndirectReference.meaning_of_failure.fget,
                meaning_of_failure),
        ]))
示例#5
0
def equals(expected: Element) -> Assertion[Element]:
    return asrt.and_([
        asrt.sub_component(
            'tag',
            _get_element_tag,
            asrt.equals(expected.tag),
        ),
        asrt.sub_component(
            'attributes',
            _get_element_attrib,
            asrt.equals(expected.attrib),
        ),
        asrt.sub_component(
            'text',
            _get_element_text,
            _text_assertion__none_eq_empty_str(expected.text),
        ),
        asrt.sub_component(
            'tail',
            _get_element_tail,
            _text_assertion__none_eq_empty_str(expected.tail),
        ),
        asrt.sub_component(
            'children',
            _get_element_children,
            asrt.matches_sequence__named([
                NameAndValue(repr(child.tag), equals(child))
                for child in list(expected)
            ]),
        ),
    ])
def assert_source(is_at_eof: Assertion[bool] = asrt.anything_goes(),
                  is_at_eol: Assertion[bool] = asrt.anything_goes(),
                  is_at_eol__except_for_space: Assertion[bool] = asrt.anything_goes(),
                  has_current_line: Assertion[bool] = asrt.anything_goes(),
                  current_line_number: Assertion[int] = asrt.anything_goes(),
                  current_line_text: Assertion[str] = asrt.anything_goes(),
                  column_index: Assertion[int] = asrt.anything_goes(),
                  remaining_part_of_current_line: Assertion[str] = asrt.anything_goes(),
                  remaining_source: Assertion[str] = asrt.anything_goes(),
                  ) -> Assertion[ParseSource]:
    return asrt.And([
        asrt.is_instance(ParseSource, 'Value to apply assertions on must be a {}'.format(ParseSource)),
        asrt.sub_component('is_at_eof', ParseSource.is_at_eof.fget, is_at_eof),
        asrt.sub_component('has_current_line', ParseSource.has_current_line.fget, has_current_line),
        asrt.Or([
            asrt.sub_component('has_current_line', ParseSource.has_current_line.fget, asrt.equals(False)),
            # The following must only be checked if has_current_line (because of precondition of ParseSource):
            asrt.And([
                asrt.sub_component('is_at_eol', ParseSource.is_at_eol.fget, is_at_eol),
                asrt.sub_component('is_at_eol__except_for_space', ParseSource.is_at_eol__except_for_space.fget,
                                   is_at_eol__except_for_space),
                asrt.sub_component('current_line_number', ParseSource.current_line_number.fget, current_line_number),
                asrt.sub_component('column_index', ParseSource.column_index.fget, column_index),
                asrt.sub_component('current_line_text', ParseSource.current_line_text.fget, current_line_text),
                asrt.sub_component('remaining_part_of_current_line', ParseSource.remaining_part_of_current_line.fget,
                                   remaining_part_of_current_line),
            ])
        ]),
        asrt.sub_component('remaining_source', ParseSource.remaining_source.fget, remaining_source),
    ])
示例#7
0
def type_is_file_on_disk(
    path_of_file_on_disk: Assertion[pathlib.Path],
    fileno: Assertion[int] = asrt.anything_goes(),
) -> Assertion[sut.SpooledTextFile]:
    return asrt.and_([
        asrt.sub_component(
            'is_mem_buff',
            sut.SpooledTextFile.is_mem_buff.fget,
            asrt.equals(False),
        ),
        asrt.sub_component(
            'is_file_on_disk',
            sut.SpooledTextFile.is_file_on_disk.fget,
            asrt.equals(True),
        ),
        asrt.sub_component(
            'fileno',
            sut.SpooledTextFile.fileno,
            asrt.is_instance_with(int, fileno),
        ),
        asrt.sub_component(
            'path_of_file_on_disk',
            sut.SpooledTextFile.path_of_file_on_disk.fget,
            path_of_file_on_disk,
        ),
    ])
def is_line(description: str = '') -> Assertion[Any]:
    return asrt.is_instance_with(
        Line,
        asrt.And([
            asrt.sub_component('line_number', Line.line_number.fget,
                               asrt.is_instance(int)),
            asrt.sub_component('text', Line.text.fget, asrt.is_instance(str))
        ]), description)
示例#9
0
 def test_false__with_message_builder(self):
     with self.assertRaises(TestException):
         value = ['not none']
         sut.sub_component('component name',
                           lambda x: x[0],
                           sut.ValueIsNone()).apply(self.put,
                                                    value,
                                                    sut.MessageBuilder('message head'))
def assert_instruction(first_line_number: int,
                       source_string: str) -> ValueAssertion:
    return asrt.And([
        asrt.sub_component('first_line_number', Instruction.first_line_number.fget,
                           asrt.Equals(first_line_number)),
        asrt.sub_component('source_string', Instruction.source_string.fget,
                           asrt.Equals(source_string))
    ])
示例#11
0
 def test_true(self):
     value = [None]
     sut.sub_component('component name', lambda x: x[0],
                       sut.ValueIsNone()).apply(self.put, value)
     sut.sub_component('component name', lambda x: x[0],
                       sut.ValueIsNone()).apply(
                           self.put, value,
                           sut.MessageBuilder('message head'))
def equals_line(expected: Line) -> Assertion[Any]:
    return asrt.is_instance_with(
        Line,
        asrt.And([
            asrt.sub_component('line_number', Line.line_number.fget,
                               asrt.equals(expected.line_number)),
            asrt.sub_component('text', Line.text.fget,
                               asrt.equals(expected.text))
        ]))
示例#13
0
def is_name() -> Assertion:
    return asrt.is_instance_with(
        Name,
        asrt.and_([
            asrt.sub_component('singular', Name.singular.fget,
                               asrt.is_instance(str)),
            asrt.sub_component('plural', Name.plural.fget,
                               asrt.is_instance(str)),
        ]))
示例#14
0
def equals_name(name: Name) -> Assertion:
    return asrt.is_instance_with(
        Name,
        asrt.and_([
            asrt.sub_component('singular', Name.singular.fget,
                               asrt.equals(name.singular)),
            asrt.sub_component('plural', Name.plural.fget,
                               asrt.equals(name.plural)),
        ]))
def assert_instruction(first_line_number: int,
                       source_string: str) -> Assertion:
    return asrt.And([
        asrt.sub_component('first_line_number',
                           Instruction.first_line_number.fget,
                           asrt.Equals(first_line_number)),
        asrt.sub_component('source_string', Instruction.source_string.fget,
                           asrt.Equals(source_string))
    ])
示例#16
0
def equals_simple_phase_step(
        expected: SimplePhaseStep) -> Assertion[SimplePhaseStep]:
    assert isinstance(expected, SimplePhaseStep), 'Must be SimplePhaseStep'
    return asrt.and_([
        asrt.sub_component('phase', SimplePhaseStep.phase.fget,
                           asrt.is_(expected.phase)),
        asrt.sub_component('step', SimplePhaseStep.step.fget,
                           asrt.equals(expected.step)),
    ])
def matches(value: Assertion[bool] = asrt.is_instance(bool),
            trace: Assertion[NodeRenderer[bool]] = asrt_trace_rendering.
            matches_node_renderer()) -> Assertion[MatchingResult]:
    return asrt.is_instance_with__many(MatchingResult, [
        asrt.sub_component('value', MatchingResult.value.fget,
                           asrt.is_instance_with(bool, value)),
        asrt.sub_component('trace', MatchingResult.trace.fget,
                           asrt.is_instance_with(NodeRenderer, trace)),
    ])
def equals_test_case_reference(
        expected: TestCaseFileReference) -> Assertion[TestCaseFileReference]:
    return asrt.is_instance_with__many(TestCaseFileReference, [
        asrt.sub_component('file_path', TestCaseFileReference.file_path.fget,
                           asrt.equals(expected.file_path)),
        asrt.sub_component('path_relativity_root_dir',
                           TestCaseFileReference.path_relativity_root_dir.fget,
                           asrt.equals(expected.path_relativity_root_dir)),
    ])
示例#19
0
def matches_regex_resolver(
        primitive_value: Callable[[HomeAndSds], ValueAssertion[Pattern]] = lambda tcds: asrt.anything_goes(),
        references: ValueAssertion[Sequence[SymbolReference]] = asrt.is_empty_sequence,
        dir_dependencies: DirDependencies = DirDependencies.NONE,
        validation: ValidationExpectation = all_validations_passes(),
        symbols: symbol_table.SymbolTable = None,
        tcds: HomeAndSds = fake_home_and_sds(),
) -> ValueAssertion[RegexResolver]:
    symbols = symbol_table.symbol_table_from_none_or_value(symbols)

    def resolve_value(resolver: RegexResolver):
        return resolver.resolve(symbols)

    def on_resolve_primitive_value(tcds_: HomeAndSds) -> ValueAssertion[Pattern]:
        return asrt.is_instance_with(RE_PATTERN_TYPE,
                                     primitive_value(tcds_))

    resolved_value_assertion = matches_multi_dir_dependent_value(
        dir_dependencies,
        on_resolve_primitive_value,
        tcds,
    )

    def validation_is_successful(value: RegexValue) -> bool:
        validator = value.validator()
        return (validator.validate_pre_sds_if_applicable(tcds.hds) is None and
                validator.validate_post_sds_if_applicable(tcds) is None)

    return asrt.is_instance_with(
        RegexResolver,
        asrt.and_([
            asrt.sub_component(
                'references',
                resolver_structure.get_references,
                references),

            asrt.sub_component(
                'resolved value',
                resolve_value,
                asrt.and_([
                    asrt.sub_component(
                        'validator',
                        lambda value: value.validator(),
                        asrt.is_instance_with(PreOrPostSdsValueValidator,
                                              PreOrPostSdsValueValidationAssertion(
                                                  tcds,
                                                  validation))
                    ),
                    asrt.if_(
                        validation_is_successful,
                        resolved_value_assertion
                    ),
                ]),
            )
        ])
    )
示例#20
0
def equals_phase(expected: Phase) -> Assertion[Phase]:
    assert isinstance(expected, Phase), 'Must be Phase'
    return asrt.and_([
        asrt.sub_component('the_enum', Phase.the_enum.fget,
                           asrt.equals(expected.the_enum)),
        asrt.sub_component('section_name', Phase.section_name.fget,
                           asrt.equals(expected.section_name)),
        asrt.sub_component('identifier', Phase.identifier.fget,
                           asrt.equals(expected.identifier)),
    ])
示例#21
0
def matches_element_properties(
    indentation: Assertion[Indentation] = matches_indentation(),
    text_style: Assertion[Optional[TextStyle]] = matches_text_style(),
) -> Assertion[ElementProperties]:
    return asrt.is_instance_with__many(ElementProperties, [
        asrt.sub_component('indentation', ElementProperties.indentation.fget,
                           indentation),
        asrt.sub_component('text_style', ElementProperties.text_style.fget,
                           text_style),
    ])
def equals_line(expected: Line) -> ValueAssertion[Any]:
    return asrt.is_instance_with(Line,
                                 asrt.And([
                                     asrt.sub_component('line_number',
                                                        Line.line_number.fget,
                                                        asrt.equals(expected.line_number)),
                                     asrt.sub_component('text',
                                                        Line.text.fget,
                                                        asrt.equals(expected.text))
                                 ]))
示例#23
0
def path_relativity_variants_equals(expected: PathRelativityVariants) -> ValueAssertion:
    return asrt.is_instance_with(PathRelativityVariants,
                                 asrt.And([
                                     asrt.sub_component('rel_option_types',
                                                        PathRelativityVariants.rel_option_types.fget,
                                                        asrt.equals(expected.rel_option_types)),
                                     asrt.sub_component('absolute',
                                                        PathRelativityVariants.absolute.fget,
                                                        asrt.equals(expected.absolute)),
                                 ]))
def accessor_error_matches(
        error: Assertion[AccessErrorType] = asrt.anything_goes(),
        error_info: Assertion[ErrorInfo] = result_assertions.
    error_info_matches()) -> Assertion[AccessorError]:
    return asrt.is_instance_with__many(AccessorError, [
        asrt.sub_component('error', AccessorError.error.fget,
                           asrt.is_instance_with(AccessErrorType, error)),
        asrt.sub_component('error_info', AccessorError.error_info.fget,
                           asrt.is_instance_with(ErrorInfo, error_info)),
    ])
示例#25
0
def path_relativity_variants_equals(expected: PathRelativityVariants) -> Assertion:
    return asrt.is_instance_with(PathRelativityVariants,
                                 asrt.And([
                                     asrt.sub_component('rel_option_types',
                                                        PathRelativityVariants.rel_option_types.fget,
                                                        asrt.equals(expected.rel_option_types)),
                                     asrt.sub_component('absolute',
                                                        PathRelativityVariants.absolute.fget,
                                                        asrt.equals(expected.absolute)),
                                 ]))
示例#26
0
def is_name() -> ValueAssertion:
    return asrt.is_instance_with(Name,
                                 asrt.and_([
                                     asrt.sub_component('singular',
                                                        Name.singular.fget,
                                                        asrt.is_instance(str)),
                                     asrt.sub_component('plural',
                                                        Name.plural.fget,
                                                        asrt.is_instance(str)),
                                 ]))
示例#27
0
def equals_entity_type_names(entity_type_names: EntityTypeNames) -> Assertion:
    return asrt.is_instance_with(
        EntityTypeNames,
        asrt.and_([
            asrt.sub_component('identifier', EntityTypeNames.identifier.fget,
                               asrt.equals(entity_type_names.identifier)),
            asrt.sub_component('name', EntityTypeNames.name.fget,
                               equals_name_with_gender(
                                   entity_type_names.name)),
        ]))
示例#28
0
def equals_simple_phase_step(expected: SimplePhaseStep) -> ValueAssertion[SimplePhaseStep]:
    assert isinstance(expected, SimplePhaseStep), 'Must be SimplePhaseStep'
    return asrt.and_([
        asrt.sub_component('phase',
                           SimplePhaseStep.phase.fget,
                           asrt.is_(expected.phase)),
        asrt.sub_component('step',
                           SimplePhaseStep.step.fget,
                           asrt.equals(expected.step)),
    ])
示例#29
0
 def test_true(self):
     value = [None]
     sut.sub_component('component name',
                       lambda x: x[0],
                       sut.ValueIsNone()).apply(self.put, value)
     sut.sub_component('component name',
                       lambda x: x[0],
                       sut.ValueIsNone()).apply(self.put,
                                                value,
                                                sut.MessageBuilder('message head'))
def assert_token(token_type: ValueAssertion = asrt.anything_goes(),
                 string: ValueAssertion = asrt.anything_goes(),
                 source_string: ValueAssertion = asrt.anything_goes()) -> ValueAssertion:
    return asrt.And([
        asrt.is_instance(Token, 'Value to apply assertions on must be a {}'.format(
            Token)),
        asrt.sub_component('type', Token.type.fget, token_type),
        asrt.sub_component('string', Token.string.fget, string),
        asrt.sub_component('source_string', Token.source_string.fget, source_string),
    ])
示例#31
0
def equals_name(name: Name) -> ValueAssertion:
    return asrt.is_instance_with(Name,
                                 asrt.and_([
                                     asrt.sub_component('singular',
                                                        Name.singular.fget,
                                                        asrt.equals(name.singular)),
                                     asrt.sub_component('plural',
                                                        Name.plural.fget,
                                                        asrt.equals(name.plural)),
                                 ]))
def assert_token_stream(
        source: ValueAssertion[str] = asrt.anything_goes(),
        remaining_source: ValueAssertion[str] = asrt.anything_goes(),
        remaining_part_of_current_line: ValueAssertion[str] = asrt.anything_goes(),
        remaining_source_after_head: ValueAssertion[str] = asrt.anything_goes(),
        is_null: ValueAssertion[bool] = asrt.anything_goes(),
        head_token: ValueAssertion[Token] = asrt.anything_goes(),
        look_ahead_state: ValueAssertion[LookAheadState] = asrt.anything_goes(),
        position: ValueAssertion[int] = asrt.anything_goes()) -> ValueAssertion:
    return asrt.is_instance_with(
        TokenStream,
        asrt.and_([
            asrt.sub_component('source', TokenStream.source.fget, source),
            asrt.sub_component('remaining_source',
                               TokenStream.remaining_source.fget,
                               remaining_source),
            asrt.sub_component('remaining_part_of_current_line',
                               TokenStream.remaining_part_of_current_line.fget,
                               remaining_part_of_current_line),
            asrt.sub_component('position', TokenStream.position.fget, position),
            asrt.sub_component('look_ahead_state', TokenStream.look_ahead_state.fget, look_ahead_state),
            asrt.sub_component('is_null', TokenStream.is_null.fget, is_null),
            asrt.or_([
                asrt.sub_component('is_null', TokenStream.is_null.fget, asrt.is_true),
                # The following must only be checked if not is_null (because of precondition):
                asrt.and_([
                    asrt.sub_component('head_token', TokenStream.head.fget, head_token),
                    asrt.sub_component('remaining_source_after_head',
                                       TokenStream.remaining_source_after_head.fget, remaining_source_after_head),
                ])
            ]),
        ]))
示例#33
0
def matches_file_inclusion_directive(
    files_to_include: Assertion[Sequence[pathlib.Path]] = asrt.anything_goes(),
    source: Assertion[LineSequence] = asrt.anything_goes(),
) -> Assertion[ParsedFileInclusionDirective]:
    return asrt.and_([
        asrt.sub_component('files_to_include',
                           ParsedFileInclusionDirective.files_to_include.fget,
                           files_to_include),
        asrt.sub_component('source', ParsedFileInclusionDirective.source.fget,
                           source),
    ])
示例#34
0
def is_hard_error(assertion_on_error_message: ValueAssertion = asrt.anything_goes()
                  ) -> ValueAssertion[sh.SuccessOrHardError]:
    return is_sh_and(asrt.And([
        asrt.sub_component('is_hard_error',
                           sh.SuccessOrHardError.is_hard_error.fget,
                           asrt.equals(True,
                                       'Status is expected to be hard-error')),
        asrt.sub_component('error message',
                           sh.SuccessOrHardError.failure_message.fget,
                           assertion_on_error_message)
    ]))
示例#35
0
def equals(
        exit_code: int,
        stderr_contents: Optional[str]) -> Assertion[ExecutionResultAndStderr]:
    return asrt.is_instance_with__many(ExecutionResultAndStderr, [
        asrt.sub_component('stderr',
                           ExecutionResultAndStderr.stderr_contents.fget,
                           asrt.equals(stderr_contents)),
        asrt.sub_component('exit_code',
                           ExecutionResultAndStderr.exit_code.fget,
                           asrt.equals(exit_code)),
    ])
def _equals_target_info_node__shallow(expected: TargetInfoNode,
                                      mk_equals_cross_ref_id) -> Assertion:
    return asrt.And([
        _is_TargetInfoNodeObject_shallow,
        asrt.sub_component(
            'target_info', TargetInfoNode.data.fget,
            equals_target_info(expected.data, mk_equals_cross_ref_id)),
        asrt.sub_component(
            'children', TargetInfoNode.children.fget,
            asrt.len_equals(len(expected.children), 'Number of children'))
    ])
def is_line(description: str = '') -> ValueAssertion[Any]:
    return asrt.is_instance_with(Line,
                                 asrt.And([
                                     asrt.sub_component('line_number',
                                                        Line.line_number.fget,
                                                        asrt.is_instance(int)),
                                     asrt.sub_component('text',
                                                        Line.text.fget,
                                                        asrt.is_instance(str))
                                 ]),
                                 description)
示例#38
0
def file_source_error_equals_line(
    line: Line, maybe_section_name: Assertion[str] = asrt.anything_goes()
) -> Assertion[FileSourceError]:
    return asrt.and_([
        asrt.sub_component('maybe_section_name',
                           FileSourceError.maybe_section_name.fget,
                           maybe_section_name),
        asrt.sub_component('source', FileSourceError.source.fget,
                           equals_line_sequence(
                               line_sequence_from_line(line))),
    ])
def has(timeout: ValueAssertion[Optional[int]] = asrt.anything_goes(),
        test_case_status: ValueAssertion[TestCaseStatus] = asrt.anything_goes(),
        ) -> ValueAssertion[ConfigurationBuilder]:
    return asrt.and_([
        asrt.sub_component('timeout',
                           ConfigurationBuilder.timeout_in_seconds.fget,
                           timeout),
        asrt.sub_component('test-case-status',
                           ConfigurationBuilder.test_case_status.fget,
                           test_case_status),
    ])
示例#40
0
def equals_list_item(expected: HeaderContentListItem) -> Assertion:
    return asrt.is_instance_with(
        HeaderContentListItem,
        asrt.and_([
            asrt.sub_component('header', HeaderContentListItem.header.fget,
                               equals_text(expected.header)),
            asrt.sub_component(
                'content_paragraph_items',
                HeaderContentListItem.content_paragraph_items.fget,
                equals_paragraph_items(expected.content_paragraph_items)),
        ]))
示例#41
0
def matches_instruction_info(assertion_on_description: ValueAssertion[str],
                             assertion_on_instruction: ValueAssertion[model.Instruction],
                             ) -> ValueAssertion[model.InstructionInfo]:
    return asrt.and_([
        asrt.sub_component('description',
                           model.InstructionInfo.description.fget,
                           assertion_on_description),
        asrt.sub_component('instruction',
                           model.InstructionInfo.instruction.fget,
                           assertion_on_instruction),
    ])
示例#42
0
def file_source_error_equals_line(line: Line,
                                  maybe_section_name: ValueAssertion[str] = asrt.anything_goes()
                                  ) -> ValueAssertion[FileSourceError]:
    return asrt.and_([
        asrt.sub_component('maybe_section_name',
                           FileSourceError.maybe_section_name.fget,
                           maybe_section_name),
        asrt.sub_component('source',
                           FileSourceError.source.fget,
                           equals_line_sequence(line_sequence_from_line(line))),
    ])
def equals_test_case_reference(expected: TestCaseFileReference) -> ValueAssertion[TestCaseFileReference]:
    return asrt.and_([
        asrt.sub_component('file_path',
                           TestCaseFileReference.file_path.fget,
                           asrt.equals(expected.file_path)
                           ),
        asrt.sub_component('file_reference_relativity_root_dir',
                           TestCaseFileReference.file_reference_relativity_root_dir.fget,
                           asrt.equals(expected.file_reference_relativity_root_dir)
                           ),
    ])
示例#44
0
def result_for_executed_status_matches(
        full_result_status: FullExeResultStatus) -> Assertion[Result]:
    def get_full_result_status(result: Result) -> FullExeResultStatus:
        return result.execution_result.status

    return asrt.and_([
        asrt.sub_component('status', Result.status.fget,
                           asrt.equals(Status.EXECUTED)),
        asrt.sub_component('full_result/status', get_full_result_status,
                           asrt.equals(full_result_status)),
    ])
示例#45
0
def result_matches(
    hds: Assertion[HomeDs] = asrt.anything_goes(),
    sds: Assertion[SandboxDs] = asrt.anything_goes(),
    partial_result: Assertion[PartialExeResult] = asrt.anything_goes(),
) -> Assertion[Result]:
    return asrt.and_([
        asrt.sub_component('hds', Result.hds.fget, hds),
        asrt.sub_component('sds', Result.sds.fget, sds),
        asrt.sub_component('partial_result', Result.partial_result.fget,
                           partial_result),
    ])
def matches_reference(assertion_on_name: ValueAssertion[str] = asrt.anything_goes(),
                      assertion_on_restrictions: ValueAssertion[ReferenceRestrictions] = asrt.anything_goes()
                      ) -> ValueAssertion[su.SymbolReference]:
    return asrt.and_([
        asrt.sub_component('name',
                           su.SymbolReference.name.fget,
                           assertion_on_name),
        asrt.sub_component('restrictions',
                           su.SymbolReference.restrictions.fget,
                           assertion_on_restrictions)

    ])
def matches_source_location(source: ValueAssertion[LineSequence] = asrt.anything_goes(),
                            file_path_rel_referrer: ValueAssertion[pathlib.Path] = asrt.anything_goes(),
                            ) -> ValueAssertion[SourceLocation]:
    return asrt.is_instance_with(SourceLocation,
                                 asrt.and_([
                                     asrt.sub_component('source',
                                                        SourceLocation.source.fget,
                                                        source),
                                     asrt.sub_component('file_path_rel_referrer',
                                                        SourceLocation.file_path_rel_referrer.fget,
                                                        file_path_rel_referrer),
                                 ]))
def is_value_failure(message: ValueAssertion) -> ValueAssertion:
    return asrt.is_instance_with(
        ValueRestrictionFailure,
        asrt.and_([
            asrt.sub_component('message',
                               ValueRestrictionFailure.message.fget,
                               message),
            asrt.sub_component('message',
                               ValueRestrictionFailure.how_to_fix.fget,
                               asrt.is_instance(str)),
        ])
    )
示例#49
0
def equals_entity_type_names(entity_type_names: EntityTypeNames) -> ValueAssertion:
    return asrt.is_instance_with(EntityTypeNames,
                                 asrt.and_([
                                     asrt.sub_component('identifier',
                                                        EntityTypeNames.identifier.fget,
                                                        asrt.equals(entity_type_names.identifier)
                                                        ),
                                     asrt.sub_component('name',
                                                        EntityTypeNames.name.fget,
                                                        equals_name_with_gender(entity_type_names.name)
                                                        ),
                                 ]))
def matches_file_inclusion_directive(
        files_to_include: ValueAssertion[Sequence[pathlib.Path]] = asrt.anything_goes(),
        source: ValueAssertion[LineSequence] = asrt.anything_goes(),
) -> ValueAssertion[ParsedFileInclusionDirective]:
    return asrt.and_([
        asrt.sub_component('files_to_include',
                           ParsedFileInclusionDirective.files_to_include.fget,
                           files_to_include),
        asrt.sub_component('source',
                           ParsedFileInclusionDirective.source.fget,
                           source),
    ])
def matches_line_sequence(first_line_number: ValueAssertion[int] = asrt.anything_goes(),
                          lines: ValueAssertion[Sequence[str]] = asrt.anything_goes(),
                          ) -> ValueAssertion[LineSequence]:
    return asrt.is_instance_with(LineSequence,
                                 asrt.and_([
                                     asrt.sub_component('first_line_number',
                                                        LineSequence.first_line_number.fget,
                                                        first_line_number),
                                     asrt.sub_component('lines',
                                                        LineSequence.lines.fget,
                                                        lines),
                                 ]))
示例#52
0
def is_hard_error(
        assertion_on_error_message: Assertion[TextRenderer] = asrt_text_doc.
    is_any_text()) -> Assertion[sh.SuccessOrHardError]:
    return is_sh_and(
        asrt.And([
            asrt.sub_component(
                'is_hard_error', sh.SuccessOrHardError.is_hard_error.fget,
                asrt.equals(True, 'Status is expected to be hard-error')),
            asrt.sub_component('failure_message',
                               sh.SuccessOrHardError.failure_message.fget,
                               assertion_on_error_message)
        ]))
示例#53
0
def matches(
        message: Assertion[TextRenderer]) -> Assertion[ErrorMessageWithFixTip]:
    return asrt.is_instance_with(
        ErrorMessageWithFixTip,
        asrt.and_([
            asrt.sub_component('message', ErrorMessageWithFixTip.message.fget,
                               message),
            asrt.sub_component(
                'how_to_fix', ErrorMessageWithFixTip.how_to_fix.fget,
                asrt.is_none_or_instance_with(Renderer,
                                              asrt_text_doc.is_any_text())),
        ]))
def _equals_target_info_node__shallow(expected: TargetInfoNode,
                                      mk_equals_cross_ref_id) -> ValueAssertion:
    return asrt.And([
        _is_TargetInfoNodeObject_shallow,
        asrt.sub_component('target_info',
                           TargetInfoNode.data.fget,
                           equals_target_info(expected.data,
                                              mk_equals_cross_ref_id)),
        asrt.sub_component('children',
                           TargetInfoNode.children.fget,
                           asrt.len_equals(len(expected.children), 'Number of children'))
    ])
示例#55
0
def matches_file_source_error(
        maybe_section_name: Assertion[str],
        location_path: Sequence[SourceLocation]) -> Assertion[FileSourceError]:
    return asrt.and_([
        asrt.sub_component('maybe_section_name',
                           FileSourceError.maybe_section_name.fget,
                           maybe_section_name),
        asrt.sub_component('message', FileSourceError.message.fget,
                           asrt.is_not_none),
        asrt.sub_component('location_path', FileSourceError.location_path.fget,
                           equals_source_location_sequence(location_path)),
    ])
示例#56
0
def equals_shell_command_driver(expected: CommandDriverForShell) -> ValueAssertion[CommandDriver]:
    return asrt.is_instance_with_many(CommandDriverForShell,
                                      [
                                          asrt.sub_component('shell_command_line',
                                                             CommandDriverForShell.shell_command_line.fget,
                                                             asrt.equals(expected.shell_command_line)
                                                             ),
                                          asrt.sub_component('shell',
                                                             _get_is_shell,
                                                             asrt.equals(True)
                                                             ),
                                      ])
def matches_source_location_path(
        source_location: ValueAssertion[SourceLocation] = asrt.anything_goes(),
        file_inclusion_chain: ValueAssertion[Sequence[SourceLocation]] = asrt.anything_goes(),
) -> ValueAssertion[SourceLocationPath]:
    return asrt.is_instance_with(SourceLocationPath,
                                 asrt.and_([
                                     asrt.sub_component('location',
                                                        SourceLocationPath.location.fget,
                                                        source_location),
                                     asrt.sub_component('file_inclusion_chain',
                                                        SourceLocationPath.file_inclusion_chain.fget,
                                                        file_inclusion_chain),
                                 ]))
示例#58
0
def equals_phase(expected: Phase) -> ValueAssertion[Phase]:
    assert isinstance(expected, Phase), 'Must be Phase'
    return asrt.and_([
        asrt.sub_component('the_enum',
                           Phase.the_enum.fget,
                           asrt.equals(expected.the_enum)),
        asrt.sub_component('section_name',
                           Phase.section_name.fget,
                           asrt.equals(expected.section_name)),
        asrt.sub_component('identifier',
                           Phase.identifier.fget,
                           asrt.equals(expected.identifier)),
    ])
示例#59
0
def equals_executable_file_command_driver(expected: CommandDriverForExecutableFile
                                          ) -> ValueAssertion[CommandDriver]:
    return asrt.is_instance_with_many(CommandDriverForExecutableFile,
                                      [
                                          asrt.sub_component('executable_file',
                                                             CommandDriverForExecutableFile.executable_file.fget,
                                                             asrt.equals(expected.executable_file)
                                                             ),
                                          asrt.sub_component('shell',
                                                             _get_is_shell,
                                                             asrt.equals(False)
                                                             ),
                                      ])
示例#60
0
def equals_system_program_command_driver(expected: CommandDriverForSystemProgram
                                         ) -> ValueAssertion[CommandDriver]:
    return asrt.is_instance_with_many(CommandDriverForSystemProgram,
                                      [
                                          asrt.sub_component('executable_file',
                                                             CommandDriverForSystemProgram.program.fget,
                                                             asrt.equals(expected.program)
                                                             ),
                                          asrt.sub_component('shell',
                                                             _get_is_shell,
                                                             asrt.equals(False)
                                                             ),
                                      ])