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),
                ])
            ]),
        ]))
Beispiel #2
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
                    ),
                ]),
            )
        ])
    )
Beispiel #3
0
def is_single_validator_with(expectations: Sequence[NameAndValue[ValueAssertion[PreOrPostSdsValidator]]]
                             ) -> ValueAssertion[Sequence[PreOrPostSdsValidator]]:
    return asrt.and_([
        asrt.len_equals(1),
        asrt.on_transformed(pre_or_post_validation.all_of,
                            asrt.all_named(expectations))
    ])
Beispiel #4
0
def matches_section_documentation(name: ValueAssertion = asrt.anything_goes()) -> ValueAssertion:
    return asrt.is_instance_with(SectionDocumentation,
                                 asrt.and_([
                                     asrt.sub_component('name',
                                                        lambda sec_doc: sec_doc.name.plain,
                                                        name),
                                 ]))
Beispiel #5
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))
def matches(
        status: ValueAssertion[FullExeResultStatus] = asrt.anything_goes(),
        has_sds: ValueAssertion[bool] = asrt.anything_goes(),
        sds: ValueAssertion[Optional[SandboxDirectoryStructure]] = asrt.anything_goes(),
        has_action_to_check_outcome: ValueAssertion[bool] = asrt.anything_goes(),
        action_to_check_outcome: ValueAssertion[Optional[ActionToCheckOutcome]] = asrt.anything_goes(),
        failure_info: ValueAssertion[Optional[FailureInfo]] = asrt.anything_goes(),
) -> ValueAssertion[FullExeResult]:
    return asrt.and_([
        asrt.sub_component('status',
                           FullExeResult.status.fget,
                           status),
        asrt.sub_component('has_sds',
                           FullExeResult.has_sds.fget,
                           has_sds),
        asrt.sub_component('sds',
                           FullExeResult.sds.fget,
                           sds),
        asrt.sub_component('has_action_to_check_outcome',
                           FullExeResult.has_action_to_check_outcome.fget,
                           has_action_to_check_outcome),
        asrt.sub_component('action_to_check_outcome',
                           FullExeResult.action_to_check_outcome.fget,
                           action_to_check_outcome),
        asrt.sub_component('failure_info',
                           FullExeResult.failure_info.fget,
                           failure_info),
    ])
Beispiel #7
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)),
                                 ]))
Beispiel #8
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)),
                                 ]))
Beispiel #9
0
def is_existing_sds_with_post_execution_w_only_exitcode_result_files(exit_code: int) \
        -> ValueAssertion[SandboxDirectoryStructure]:
    return asrt.and_([
        sds_root_dir_exists_and_has_sds_dirs(),
        asrt.sub_component('result-dir',
                           SandboxDirectoryStructure.result_dir.fget,
                           DirContainsExactly(DirContents([
                               File(RESULT_FILE__EXITCODE, str(exit_code))
                           ])))
    ])
Beispiel #10
0
def equals_path_relativity_variants(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))
                                 ]))
Beispiel #11
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)),
    ])
Beispiel #12
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)),
        ]))
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)
                           ),
    ])
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),
    ])
Beispiel #15
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))),
    ])
Beispiel #16
0
def contents_raises_hard_error(may_depend_on_external_resources: Assertion[bool],
                               structure: Assertion[NodeRenderer]
                               = asrt_trace_rendering.matches_node_renderer(),
                               ) -> Assertion[StringSource]:
    return asrt.and_([
        has_structure_description(structure),
        contents_matches(
            asrt.and_(
                [asrt_str_src_contents.external_dependencies(may_depend_on_external_resources)] +
                [
                    asrt.named(
                        contents_case.name,
                        RaisesHardErrorAsLastAction(
                            contents_case.value
                        )
                    )
                    for contents_case in properties_access.ALL_CASES__WO_LINES_ITER_CHECK
                ]),
        ),
    ])
Beispiel #17
0
def matches2(status: FullExeResultStatus,
             sds: ValueAssertion[FullExeResult],
             action_to_check_outcome: ValueAssertion[FullExeResult],
             failure_info: ValueAssertion[Optional[FailureInfo]] = asrt.anything_goes()
             ) -> ValueAssertion[FullExeResult]:
    return asrt.and_([
        matches(status=asrt.is_(status),
                failure_info=failure_info),
        sds,
        action_to_check_outcome,
    ])
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),
    ])
Beispiel #19
0
def matches2(
    status: Optional[ExecutionFailureStatus],
    sds: Assertion[PartialExeResult],
    action_to_check_outcome: Assertion[PartialExeResult],
    failure_info: Assertion[Optional[FailureInfo]] = asrt.anything_goes()
) -> Assertion[PartialExeResult]:
    return asrt.and_([
        matches(status=asrt.is_(status), failure_info=failure_info),
        sds,
        action_to_check_outcome,
    ])
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 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),
                                 ]))
Beispiel #22
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)),
    ])
Beispiel #23
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 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 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 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)),
        ])
    )
def matches_reference(assertion_on_name: Assertion[str] = asrt.anything_goes(),
                      assertion_on_restrictions: Assertion[ReferenceRestrictions] = asrt.anything_goes()
                      ) -> Assertion[SymbolReference]:
    return asrt.and_([
        asrt.sub_component('name',
                           SymbolReference.name.fget,
                           assertion_on_name),
        asrt.sub_component('restrictions',
                           SymbolReference.restrictions.fget,
                           assertion_on_restrictions)

    ])
Beispiel #28
0
def matches_instruction_info(
    assertion_on_description: Assertion[str],
    assertion_on_instruction: Assertion[model.Instruction],
) -> Assertion[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),
    ])
def is_string_lines(
    strings: Assertion[Sequence[str]] = asrt.anything_goes(),
) -> Assertion[LineObject]:
    return asrt.is_instance_with__many(
        StringLinesObject,
        [
            asrt.sub_component(
                'strings', StringLinesObject.strings.fget,
                asrt.and_(
                    [asrt.is_sequence_of(asrt.is_instance(str)), strings])),
        ],
    )
def matches_line_sequence(
    first_line_number: Assertion[int] = asrt.anything_goes(),
    lines: Assertion[Sequence[str]] = asrt.anything_goes(),
) -> Assertion[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),
        ]))
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),
                                 ]))
Beispiel #32
0
def equals_name_with_gender(name: NameWithGender) -> Assertion[NameWithGender]:
    return asrt.is_instance_with(
        Name,
        asrt.and_([
            asrt.sub_component('determinator_word',
                               NameWithGender.determinator_word.fget,
                               asrt.equals(name.determinator_word)),
            asrt.sub_component('singular', NameWithGender.singular.fget,
                               asrt.equals(name.singular)),
            asrt.sub_component('plural', NameWithGender.plural.fget,
                               asrt.equals(name.plural)),
        ]))
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)

    ])
Beispiel #34
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)),
    ])
def matches_recording(string: ValueAssertion[str] = asrt.anything_goes(),
                      file_location_info: ValueAssertion[FileLocationInfo] = asrt.anything_goes()
                      ) -> ValueAssertion[Recording]:
    return asrt.and_([
        asrt.sub_component('string',
                           Recording.string.fget,
                           string
                           ),
        asrt.sub_component('file_location_info',
                           Recording.file_location_info.fget,
                           file_location_info,
                           ),
    ])
Beispiel #36
0
def type_is_mem_buff() -> Assertion[sut.SpooledTextFile]:
    return asrt.and_([
        asrt.sub_component(
            'is_mem_buff',
            sut.SpooledTextFile.is_mem_buff.fget,
            asrt.equals(True),
        ),
        asrt.sub_component(
            'is_file_on_disk',
            sut.SpooledTextFile.is_file_on_disk.fget,
            asrt.equals(False),
        ),
    ])
Beispiel #37
0
def equals_name_with_gender(name: NameWithGender) -> ValueAssertion[NameWithGender]:
    return asrt.is_instance_with(Name,
                                 asrt.and_([
                                     asrt.sub_component('determinator_word',
                                                        NameWithGender.determinator_word.fget,
                                                        asrt.equals(name.determinator_word)),
                                     asrt.sub_component('singular',
                                                        NameWithGender.singular.fget,
                                                        asrt.equals(name.singular)),
                                     asrt.sub_component('plural',
                                                        NameWithGender.plural.fget,
                                                        asrt.equals(name.plural)),
                                 ]))
Beispiel #38
0
def equals_list_format(expected: lists.Format) -> Assertion:
    return asrt.is_instance_with(
        lists.Format,
        asrt.and_([
            asrt.sub_component('list_type', lists.Format.list_type.fget,
                               asrt.equals(expected.list_type)),
            asrt.sub_component('custom_indent_spaces',
                               lists.Format.custom_indent_spaces.fget,
                               asrt.equals(expected.custom_indent_spaces)),
            asrt.sub_component('custom_separations',
                               lists.Format.custom_separations.fget,
                               asrt.equals(expected.custom_separations)),
        ]))
def matches_container(assertion_on_resolver: ValueAssertion[rs.SymbolValueResolver],
                      assertion_on_source: ValueAssertion[LineSequence] = asrt_line_source.is_line_sequence(),
                      ) -> ValueAssertion[rs.SymbolContainer]:
    return asrt.is_instance_with(
        rs.SymbolContainer,
        asrt.and_([
            asrt.sub_component('source',
                               rs.SymbolContainer.definition_source.fget,
                               assertion_on_source),
            asrt.sub_component('resolver',
                               rs.SymbolContainer.resolver.fget,
                               assertion_on_resolver)
        ]))
def matches_file_source_error(maybe_section_name: ValueAssertion[str],
                              location_path: Sequence[SourceLocation]) -> ValueAssertion[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)),
    ])
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),
                                 ]))
Beispiel #42
0
def matches_instruction(
    source: Assertion[line_source.LineSequence] = asrt.anything_goes(),
    instruction_info: Assertion[InstructionInfo] = asrt.anything_goes(),
) -> Assertion[ParsedSectionElement]:
    return asrt.is_instance_with(
        ParsedInstruction,
        asrt.and_([
            asrt.sub_component('source', ParsedInstruction.source.fget,
                               source),
            asrt.sub_component('instruction_info',
                               ParsedInstruction.instruction_info.fget,
                               instruction_info),
        ]))
def is_tree_detail(
        tree: Assertion[Node[Any]] = asrt.anything_goes(),
) -> Assertion[Detail]:
    return asrt.is_instance_with__many(
        TreeDetail,
        [
            asrt.sub_component(
                'tree',
                TreeDetail.tree.fget,
                asrt.is_not_none_and(asrt.and_([_MatchesNode(), tree])),
            ),
        ],
    )
Beispiel #44
0
def matches_recording(string: Assertion[str] = asrt.anything_goes(),
                      file_location_info: Assertion[FileLocationInfo] = asrt.anything_goes()
                      ) -> Assertion[Recording]:
    return asrt.and_([
        asrt.sub_component('string',
                           Recording.string.fget,
                           string
                           ),
        asrt.sub_component('file_location_info',
                           Recording.file_location_info.fget,
                           file_location_info,
                           ),
    ])
Beispiel #45
0
def is_open_mem_buff_with_contents(
        position: int, remaining_contents: str,
        full_contents: str) -> Assertion[sut.SpooledTextFile]:
    return asrt.and_([
        is_open(),
        type_is_mem_buff(),
        asrt.sub_component(
            'mem_buff',
            sut.SpooledTextFile.mem_buff.fget,
            asrt.equals(full_contents),
        ),
        is_at_pos_with_remaining_contents(position, remaining_contents),
    ])
Beispiel #46
0
 def visit_header_value_list(self, expected: HeaderContentList):
     self._assert_is_type(HeaderContentList)
     actual = self.actual
     assertions = asrt.is_instance_with(
         lists.HeaderContentList,
         asrt.and_([
             asrt.sub_component('list-format',
                                lists.HeaderContentList.list_format.fget,
                                equals_list_format(expected.list_format)),
             asrt.sub_component('list-items',
                                lists.HeaderContentList.items.fget,
                                equals_list_items(expected.items)),
         ]))
     assertions.apply(self.put, actual, self.message_builder)
Beispiel #47
0
def equals_path_relativity(expected: SpecificPathRelativity) -> Assertion:
    return asrt.is_instance_with(SpecificPathRelativity,
                                 asrt.and_([
                                     asrt.sub_component('is_absolute',
                                                        SpecificPathRelativity.is_absolute.fget,
                                                        asrt.equals(expected.is_absolute)),
                                     asrt.sub_component('is_relative',
                                                        SpecificPathRelativity.is_relative.fget,
                                                        asrt.equals(expected.is_relative)),
                                     asrt.sub_component('relativity_type',
                                                        SpecificPathRelativity.relativity_type.fget,
                                                        asrt.equals(expected.relativity_type)),
                                 ])
                                 )
Beispiel #48
0
def equals_path_relativity(expected: SpecificPathRelativity) -> ValueAssertion:
    return asrt.is_instance_with(SpecificPathRelativity,
                                 asrt.and_([
                                     asrt.sub_component('is_absolute',
                                                        SpecificPathRelativity.is_absolute.fget,
                                                        asrt.equals(expected.is_absolute)),
                                     asrt.sub_component('is_relative',
                                                        SpecificPathRelativity.is_relative.fget,
                                                        asrt.equals(expected.is_relative)),
                                     asrt.sub_component('relativity_type',
                                                        SpecificPathRelativity.relativity_type.fget,
                                                        asrt.equals(expected.relativity_type)),
                                 ])
                                 )
def equals_container(expected: rs.SymbolContainer,
                     ignore_source_line: bool = True) -> ValueAssertion[rs.SymbolContainer]:
    component_assertions = []
    if not ignore_source_line:
        component_assertions.append(asrt.sub_component('source',
                                                       rs.SymbolContainer.definition_source.fget,
                                                       equals_line_sequence(expected.definition_source)))
    expected_resolver = expected.resolver
    assert isinstance(expected_resolver, DataValueResolver), 'All actual values must be DataValueResolver'
    component_assertions.append(asrt.sub_component('resolver',
                                                   rs.SymbolContainer.resolver.fget,
                                                   equals_resolver(expected_resolver)))
    return asrt.is_instance_with(rs.SymbolContainer,
                                 asrt.and_(component_assertions))
def is_string_detail(
    to_string_object: Assertion[ToStringObject] = asrt.anything_goes(),
) -> Assertion[Detail]:
    return asrt.is_instance_with__many(
        StringDetail,
        [
            asrt.sub_component(
                'string', StringDetail.string.fget,
                asrt.and_([
                    asrt_to_string.matches(asrt.anything_goes()),
                    to_string_object,
                ])),
        ],
    )
Beispiel #51
0
def is_reference_restrictions__value_type(
        expected: Sequence[ValueType]) -> Assertion[ReferenceRestrictions]:
    """
    Assertion on a :class:`ReferenceRestrictions`,
    that it is a :class:`TypeCategoryRestriction`,
    with a given :class:`TypeCategory`.
    """
    return asrt.is_instance_with(
        ValueTypeRestriction,
        asrt.and_([
            asrt.sub_component('value_type', _get_value_types__as_list,
                               asrt.equals(list(expected))),
        ]),
    )
Beispiel #52
0
def matches_non_instruction(
    source: Assertion[line_source.LineSequence] = asrt.anything_goes(),
    element_type: Assertion[ElementType] = asrt.anything_goes(),
) -> Assertion[ParsedSectionElement]:
    return asrt.is_instance_with(
        ParsedNonInstructionElement,
        asrt.and_([
            asrt.sub_component('source',
                               ParsedNonInstructionElement.source.fget,
                               source),
            asrt.sub_component('element_type',
                               ParsedNonInstructionElement.element_type.fget,
                               element_type),
        ]))
Beispiel #53
0
    def test_populate_result_dir_with_act_result(self):
        act_result = SubProcessResult(
            exitcode=72,
            stdout='the stdout',
            stderr='the stderr',
        )

        result_dir_contains_files_corresponding_to_act_result = asrt_tcds_contents.dir_contains_exactly(
            RelOptionType.REL_RESULT,
            DirContents([
                File(sds.RESULT_FILE__EXITCODE, str(act_result.exitcode)),
                File(sds.RESULT_FILE__STDOUT, str(act_result.stdout)),
                File(sds.RESULT_FILE__STDERR, str(act_result.stderr)),
            ])
        )

        all_tcds_dirs_but_result_dir_are_empty = asrt.and_([
            dir_is_empty(tcds_dir)
            for tcds_dir in RelOptionType if tcds_dir is not RelOptionType.REL_RESULT
        ])

        self._check___single_and_multi(
            utils.single_line_arguments(),
            ARBITRARY_MODEL,
            parser_of_matcher_that_is_an_assertion_on_tcds(
                self,
                asrt.and_([
                    result_dir_contains_files_corresponding_to_act_result,
                    all_tcds_dirs_but_result_dir_are_empty,
                ]
                )
            ),
            arrangement_w_tcds(
                act_result=ActResultProducerFromActResult(act_result)
            ),
            Expectation(),
        )
Beispiel #54
0
    def test_tcds_directories_are_empty(self):
        all_tcds_dirs_are_empty = asrt.and_([
            dir_is_empty(tcds_dir)
            for tcds_dir in RelOptionType
        ])

        self._check___single_and_multi(
            utils.single_line_arguments(),
            ARBITRARY_MODEL,
            parser_of_matcher_that_is_an_assertion_on_tcds(
                self,
                all_tcds_dirs_are_empty,
            ),
            arrangement_w_tcds(),
            is_expectation_of_execution_result_of(True))
Beispiel #55
0
def matches_file_inclusion_directive(
    source: Assertion[line_source.LineSequence] = asrt.anything_goes(),
    files_to_include: Assertion[Sequence[pathlib.Path]] = asrt.anything_goes(),
) -> Assertion[ParsedSectionElement]:
    return asrt.is_instance_with(
        ParsedFileInclusionDirective,
        asrt.and_([
            asrt.sub_component('source',
                               ParsedFileInclusionDirective.source.fget,
                               source),
            asrt.sub_component(
                'files_to_include',
                ParsedFileInclusionDirective.files_to_include.fget,
                files_to_include),
        ]))
def matches_source_location(source: Assertion[LineSequence] = asrt.anything_goes(),
                            file_path_rel_referrer: Assertion[Optional[pathlib.Path]] = asrt.anything_goes(),
                            ) -> Assertion[SourceLocation]:
    return asrt.is_instance_with(
        SourceLocation,
        asrt.and_([
            asrt.sub_component(
                'source',
                SourceLocation.source.fget,
                asrt.is_instance_with(LineSequence, source)),
            asrt.sub_component(
                'file_path_rel_referrer',
                SourceLocation.file_path_rel_referrer.fget,
                asrt.is_optional_instance_with(pathlib.Path, file_path_rel_referrer)),
        ]))
Beispiel #57
0
def matches_file_access_error(
        erroneous_path: Path, location_path: Sequence[SourceLocation],
        section_name: Optional[str]) -> Assertion[FileAccessError]:
    return asrt.and_([
        asrt.sub_component('erroneous_path',
                           FileAccessError.erroneous_path.fget,
                           asrt.equals(erroneous_path)),
        asrt.sub_component('message', FileAccessError.message.fget,
                           asrt.is_not_none),
        asrt.sub_component('location_path', FileAccessError.location_path.fget,
                           equals_source_location_sequence(location_path)),
        asrt.sub_component('maybe_section_name',
                           FileAccessError.maybe_section_name.fget,
                           asrt.equals(section_name)),
    ])
Beispiel #58
0
def matches__on_direct_and_indirect(
    assertion_on_direct: Assertion[ValueRestriction] = asrt.anything_goes(),
    assertion_on_indirect: Assertion[ValueRestriction] = asrt.anything_goes(),
) -> Assertion[ReferenceRestrictions]:
    return asrt.is_instance_with(
        ReferenceRestrictionsOnDirectAndIndirect,
        asrt.and_([
            asrt.sub_component(
                'direct', ReferenceRestrictionsOnDirectAndIndirect.direct.fget,
                assertion_on_direct),
            asrt.sub_component(
                'indirect',
                ReferenceRestrictionsOnDirectAndIndirect.indirect.fget,
                assertion_on_indirect),
        ]))
Beispiel #59
0
def is_at_pos_with_remaining_contents(
    position: int,
    remaining_contents: str,
) -> Assertion[sut.SpooledTextFile]:
    return asrt.and_([
        asrt.sub_component(
            'tell',
            sut.SpooledTextFile.tell,
            asrt.equals(position),
        ),
        asrt.sub_component(
            'read (remaining contents)',
            sut.SpooledTextFile.read,
            asrt.equals(remaining_contents),
        ),
    ])
Beispiel #60
0
def equals__or(expected: OrReferenceRestrictions) -> Assertion:
    expected_sub_restrictions = [
        asrt.is_instance_with(
            OrRestrictionPart,
            asrt.and_([
                asrt.sub_component('selector', OrRestrictionPart.selector.fget,
                                   asrt.equals(part.selector)),
                asrt.sub_component(
                    'restriction', OrRestrictionPart.restriction.fget,
                    _equals_on_direct_and_indirect(part.restriction)),
            ])) for part in expected.parts
    ]
    return asrt.is_instance_with(
        OrReferenceRestrictions,
        asrt.sub_component('parts', OrReferenceRestrictions.parts.fget,
                           asrt.matches_sequence(expected_sub_restrictions)))