示例#1
0
def matches_executable_file_command_driver(
    executable: Assertion[pathlib.Path], ) -> Assertion[CommandDriver]:
    return asrt.is_instance_with(
        CommandDriverForExecutableFile,
        asrt.sub_component('executable_file',
                           CommandDriverForExecutableFile.executable_file.fget,
                           asrt.is_instance_with(pathlib.Path, executable)),
    )
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)),
    ])
示例#3
0
def is_identity_transformer(expected: bool) -> Assertion[StringTransformer]:
    def get_is_identity(x: StringTransformer) -> bool:
        return x.is_identity_transformer

    return asrt.is_instance_with(
        StringTransformer,
        asrt.sub_component('is_identity', get_is_identity,
                           asrt.is_instance_with(bool, asrt.equals(expected))),
    )
示例#4
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
                    ),
                ]),
            )
        ])
    )
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)),
    ])
示例#6
0
def matches_sdv_of_string_transformer_constant(
        references: Assertion[
            Sequence[SymbolReference]] = asrt.anything_goes(),
        primitive_value: Assertion[StringTransformer] = asrt.anything_goes(),
        symbols: SymbolTable = None) -> Assertion[SymbolDependentValue]:
    return matches_sdv(
        asrt.is_instance(StringTransformerSdv), references,
        asrt.is_instance_with(
            StringTransformerDdv,
            asrt_logic.matches_logic_ddv(lambda tcds: asrt.is_instance_with(
                StringTransformer, primitive_value))), asrt.anything_goes(),
        symbol_table_from_none_or_value(symbols))
示例#7
0
def matches_sdv_of_program(
        references: Assertion[Sequence[SymbolReference]],
        primitive_value: Callable[[TestCaseDs], Assertion[Program]],
        symbols: Optional[SymbolTable] = None
) -> Assertion[SymbolDependentValue]:
    return matches_sdv(
        asrt.is_instance(ProgramSdv), references,
        asrt.is_instance_with(
            ProgramDdv,
            asrt_logic.matches_logic_ddv(lambda tcds: asrt.is_instance_with(
                Program, primitive_value(tcds)))), asrt.anything_goes(),
        symbol_table_from_none_or_value(symbols))
示例#8
0
def matches_sdv_of_files_condition_constant(
        references: Assertion[
            Sequence[SymbolReference]] = asrt.anything_goes(),
        primitive_value: Assertion[FilesCondition] = asrt.anything_goes(),
        symbols: SymbolTable = None) -> Assertion[SymbolDependentValue]:
    return matches_sdv(
        asrt.is_instance(FilesConditionSdv), references,
        asrt.is_instance_with(
            FilesConditionDdv,
            asrt_logic.matches_logic_ddv(lambda tcds: asrt.is_instance_with(
                FilesCondition, primitive_value))), asrt.anything_goes(),
        symbol_table_from_none_or_value(symbols))
示例#9
0
def matches_definition(
    name: Assertion[str],
    container: Assertion[SymbolContainer],
) -> Assertion[SymbolDefinition]:
    return asrt.is_instance_with(
        SymbolDefinition,
        asrt.And([
            asrt.sub_component('name', SymbolDefinition.name.fget,
                               asrt.is_instance_with(str, name)),
            asrt.sub_component(
                'symbol_container', SymbolDefinition.symbol_container.fget,
                asrt.is_instance_with(SymbolContainer, container)),
        ]))
示例#10
0
def matches_indentation(
        level: Assertion[int] = asrt.anything_goes(),
        suffix: Assertion[str] = asrt.anything_goes(),
) -> Assertion[Indentation]:
    return asrt.is_instance_with__many(Indentation, [
        asrt.sub_component('level', Indentation.level.fget,
                           asrt.is_instance_with(int, level)),
        asrt.sub_component(
            'suffix',
            Indentation.suffix.fget,
            asrt.is_instance_with(str, suffix),
        ),
    ])
示例#11
0
def is_string(string: Assertion[str] = asrt.anything_goes(),
              string_is_line_ended: Assertion[bool] = asrt.anything_goes()
              ) -> Assertion[LineObject]:
    return asrt.is_instance_with__many(
        StringLineObject,
        [
            asrt.sub_component('string', StringLineObject.string.fget,
                               asrt.is_instance_with(str, string)),
            asrt.sub_component(
                'string_is_line_ended',
                StringLineObject.string_is_line_ended.fget,
                asrt.is_instance_with(bool, string_is_line_ended)),
        ],
    )
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)),
        ]))
示例#13
0
def matches_shell_command_driver(
        shell_command_line: Assertion[str]) -> Assertion[CommandDriver]:
    return asrt.is_instance_with(
        CommandDriverForShell,
        asrt.sub_component('shell_command_line',
                           CommandDriverForShell.shell_command_line.fget,
                           shell_command_line))
示例#14
0
 def is_section_item(self,
                     put: unittest.TestCase,
                     value,
                     message_builder: asrt.MessageBuilder = asrt.MessageBuilder()):
     asrt.IsInstance(doc.SectionItem).apply(put, value, message_builder)
     assert isinstance(value, doc.SectionItem)
     asrt.sub_component('header',
                        doc.SectionItem.header.fget,
                        is_text
                        ).apply(put, value, message_builder)
     asrt.sub_component('tags',
                        doc.SectionItem.tags.fget,
                        asrt.is_instance_with(set,
                                              asrt.on_transformed(list,
                                                                  asrt.is_sequence_of(asrt.is_instance(str)))
                                              )
                        ).apply(put, value, message_builder)
     asrt.sub_component('target',
                        doc.SectionItem.target.fget,
                        asrt.is_instance(core.CrossReferenceTarget)),
     if isinstance(value, doc.Article):
         is_article_contents.apply(put, value.contents,
                                   message_builder.for_sub_component('article_contents'))
     elif isinstance(value, doc.Section):
         is_section_contents.apply(put, value.contents,
                                   message_builder.for_sub_component('section_contents'))
     else:
         asrt.fail('Not a {}: {}'.format(str(doc.SectionItem), str(value)))
def matches_external_process(
        external_process_error: Assertion[ExternalProcessError] = asrt.
    anything_goes(),
        message: Optional[Assertion[MinorTextRenderer]] = asrt.anything_goes()
) -> Assertion[ErrorDescription]:
    return asrt.is_none_or_instance_with__many(
        err_descr.ErrorDescriptionOfExternalProcessError,
        [
            asrt.sub_component_many(
                'message',
                err_descr.ErrorDescriptionOfExternalProcessError.message.fget,
                [
                    asrt.is_none_or_instance_with(
                        SequenceRenderer,
                        asrt_renderer.is_renderer_of_major_blocks()),
                    message,
                ],
            ),
            asrt.sub_component(
                'external_process_error',
                err_descr.ErrorDescriptionOfExternalProcessError.
                external_process_error.fget,
                asrt.is_instance_with(
                    ExternalProcessError,
                    external_process_error,
                )),
        ],
    )
示例#16
0
def equals_system_program_command_driver(
        expected: CommandDriverForSystemProgram) -> Assertion[CommandDriver]:
    return asrt.is_instance_with(
        CommandDriverForSystemProgram,
        asrt.sub_component('executable_file',
                           CommandDriverForSystemProgram.program.fget,
                           asrt.equals(expected.program)))
示例#17
0
def _symbol_usages_assertion(
    reference_assertions: Sequence[Assertion[SymbolReference]]
) -> Assertion[Sequence[SymbolUsage]]:
    return asrt.matches_sequence([
        asrt.is_instance_with(SymbolReference, sr)
        for sr in reference_assertions
    ])
示例#18
0
def external_dependencies(expectation: Assertion[bool] = asrt.anything_goes()
                          ) -> Assertion[StringSourceContents]:
    return asrt.sub_component(
        'may_depend_on_external_resources',
        get_may_depend_on_external_resources,
        asrt.is_instance_with(bool, expectation),
    )
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),
                ])
            ]),
        ]))
示例#20
0
def equals_executable_file_command_driver(
        expected: CommandDriverForExecutableFile) -> Assertion[CommandDriver]:
    return asrt.is_instance_with(
        CommandDriverForExecutableFile,
        asrt.sub_component('executable_file',
                           CommandDriverForExecutableFile.executable_file.fget,
                           asrt.equals(expected.executable_file)))
示例#21
0
def is_reference_to_files_condition(
        symbol_name: str) -> Assertion[SymbolReference]:
    return asrt.is_instance_with(
        SymbolReference,
        asrt_sym_usage.matches_reference(
            asrt.equals(symbol_name),
            IS_FILES_CONDITION_REFERENCE_RESTRICTION))
示例#22
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),
        ]))
示例#23
0
def equals_shell_command_driver(
        expected: CommandDriverForShell) -> Assertion[CommandDriver]:
    return asrt.is_instance_with(
        CommandDriverForShell,
        asrt.sub_component('shell_command_line',
                           CommandDriverForShell.shell_command_line.fget,
                           asrt.equals(expected.shell_command_line)))
示例#24
0
def equals_instruction_in_section(
        expected: InstructionInSection) -> Assertion[model.Instruction]:
    return asrt.is_instance_with(
        InstructionInSection,
        asrt.sub_component('section_name',
                           InstructionInSection.section_name.fget,
                           asrt.equals(expected.section_name)))
示例#25
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)))
示例#26
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,
        ),
    ])
示例#27
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 equals__path_w_relativity(
        expected: PathAndRelativityRestriction) -> Assertion[ValueRestriction]:
    return asrt.is_instance_with(
        PathAndRelativityRestriction,
        asrt.sub_component('accepted',
                           PathAndRelativityRestriction.accepted.fget,
                           equals_path_relativity_variants(expected.accepted)))
示例#29
0
def equals_custom_cross_ref_test_impl(
        expected: CustomCrossReferenceTargetTestImpl) -> Assertion:
    return asrt.is_instance_with(
        CustomCrossReferenceTargetTestImpl,
        asrt.sub_component('identifier',
                           CustomCrossReferenceTargetTestImpl.identifier.fget,
                           asrt.equals(expected.identifier)))
示例#30
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))
示例#31
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),
                                 ]))
示例#32
0
def matches_string_matcher_resolver(primitive_value: ValueAssertion[StringMatcher] = asrt.anything_goes(),
                                    references: ValueAssertion = asrt.is_empty_sequence,
                                    symbols: symbol_table.SymbolTable = None,
                                    tcds: HomeAndSds = fake_home_and_sds(),
                                    ) -> ValueAssertion[LogicValueResolver]:
    symbols = symbol_table.symbol_table_from_none_or_value(symbols)

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

    def resolve_primitive_value(value: StringMatcherValue):
        return value.value_of_any_dependency(tcds)

    resolved_value_assertion = asrt.is_instance_with_many(
        StringMatcherValue,
        [
            asrt.sub_component('resolving dependencies',
                               lambda sm_value: sm_value.resolving_dependencies(),
                               asrt.is_set_of(asrt.is_instance(DirectoryStructurePartition))),

            asrt.sub_component('primitive value',
                               resolve_primitive_value,
                               asrt.is_instance_with(StringMatcher,
                                                     primitive_value))
        ])

    return asrt.is_instance_with(
        StringMatcherResolver,
        asrt.and_([
            is_resolver_of_logic_type(LogicValueType.STRING_MATCHER,
                                      ValueType.STRING_MATCHER),

            asrt.sub_component('references',
                               resolver_structure.get_references,
                               references),

            asrt.sub_component('validator',
                               lambda resolver: resolver.validator,
                               asrt.is_instance(PreOrPostSdsValidator)
                               ),

            asrt.sub_component('resolved value',
                               resolve_value,
                               resolved_value_assertion
                               ),
        ])
    )
示例#33
0
def is_lower(lower_limit: int) -> Assertion[Range]:
    return asrt.is_instance_with(
        LowerLimitRange,
        asrt.sub_component('lower_limit',
                           lambda x: x.lower_limit,
                           asrt.equals(lower_limit)
                           )
    )
示例#34
0
def is_single(line_number: int) -> Assertion[Range]:
    return asrt.is_instance_with(
        SingleLineRange,
        asrt.sub_component('line_number',
                           lambda x: x.line_number,
                           asrt.equals(line_number)
                           )
    )
示例#35
0
def is_upper(upper_limit: int) -> Assertion[Range]:
    return asrt.is_instance_with(
        UpperLimitRange,
        asrt.sub_component('upper_limit',
                           lambda x: x.upper_limit,
                           asrt.equals(upper_limit)
                           )
    )
def equals_or_reference_restrictions(expected: OrReferenceRestrictions) -> ValueAssertion:
    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_reference_restriction_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)))
def is_identity_transformer() -> ValueAssertion[StringTransformer]:
    def get_is_identity(x: StringTransformer) -> bool:
        return x.is_identity_transformer

    return asrt.is_instance_with(StringTransformer,
                                 asrt.sub_component('is_identity',
                                                    get_is_identity,
                                                    asrt.equals(True)),
                                 )
示例#38
0
def matches_resolver_of_program(references: ValueAssertion[Sequence[SymbolReference]],
                                resolved_program_value: ValueAssertion[DirDependentValue],
                                custom: ValueAssertion[ProgramResolver] = asrt.anything_goes(),
                                symbols: SymbolTable = None) -> ValueAssertion[rs.SymbolValueResolver]:
    return matches_resolver(is_resolver_of_program_type(),
                            references,
                            asrt.is_instance_with(ProgramValue, resolved_program_value),
                            custom,
                            symbol_table_from_none_or_value(symbols))
示例#39
0
def matches_resolver_of_line_matcher(references: ValueAssertion[Sequence[SymbolReference]],
                                     resolved_value: ValueAssertion[LineMatcherValue],
                                     custom: ValueAssertion[LineMatcherResolver] = asrt.anything_goes(),
                                     symbols: SymbolTable = None) -> ValueAssertion[rs.SymbolValueResolver]:
    return matches_resolver(is_resolver_of_line_matcher_type(),
                            references,
                            asrt.is_instance_with(LineMatcherValue, resolved_value),
                            custom,
                            symbol_table_from_none_or_value(symbols))
示例#40
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 is_type_category_restriction(expected: TypeCategory) -> ValueAssertion[ReferenceRestrictions]:
    """
    Assertion on a :class:`ReferenceRestrictions`,
    that it is a :class:`TypeCategoryRestriction`,
    with a given :class:`TypeCategory`.
    """
    return asrt.is_instance_with(TypeCategoryRestriction,
                                 asrt.sub_component('type_category',
                                                    TypeCategoryRestriction.type_category.fget,
                                                    asrt.is_(expected)))
示例#42
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)),
                                 ]))
示例#43
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)),
                                 ]))
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))
                                 ]))
def is_line_sequence(description: str = '') -> ValueAssertion[Any]:
    return asrt.is_instance_with(LineSequence,
                                 asrt.And([
                                     asrt.sub_component('line_number',
                                                        LineSequence.first_line_number.fget,
                                                        asrt.is_instance(int)),
                                     asrt.sub_component_list('lines',
                                                             LineSequence.lines.fget,
                                                             asrt.is_instance(str))
                                 ]),
                                 description)
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)
示例#47
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_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 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),
                                 ]))
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)),
        ])
    )
示例#51
0
def matches_file_matcher_value(
        primitive_value: ValueAssertion[FileMatcher] = asrt.anything_goes(),
        resolving_dependencies: ValueAssertion[Set[DirectoryStructurePartition]] = asrt.anything_goes(),
        validator: ValueAssertion[PreOrPostSdsValueValidator] = asrt.anything_goes(),
        tcds: HomeAndSds = fake_home_and_sds(),
) -> ValueAssertion[FileMatcherValue]:
    def resolve_primitive_value(value: FileMatcherValue):
        return value.value_of_any_dependency(tcds)

    def get_resolving_dependencies(value: FileMatcherValue):
        return value.resolving_dependencies()

    def get_validator(value: FileMatcherValue):
        return value.validator()

    return asrt.is_instance_with_many(
        FileMatcherValue,
        [
            asrt.sub_component_many(
                'resolving dependencies',
                get_resolving_dependencies,
                [
                    asrt.is_set_of(asrt.is_instance(DirectoryStructurePartition)),
                    resolving_dependencies,
                ]
            ),
            asrt.sub_component(
                'primitive value',
                resolve_primitive_value,
                asrt.is_instance_with(FileMatcher,
                                      primitive_value)
            ),
            asrt.sub_component(
                'validator',
                get_validator,
                asrt.is_instance_with(PreOrPostSdsValueValidator,
                                      validator)
            ),
        ]
    )
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),
                                 ]))
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 section_contents_matches(initial_paragraphs: ValueAssertion[Sequence[ParagraphItem]] = asrt.anything_goes(),
                             sections: ValueAssertion[Sequence[SectionItem]] = asrt.anything_goes()
                             ) -> ValueAssertion[SectionContents]:
    return asrt.is_instance_with(
        SectionContents,
        asrt.And([
            asrt.sub_component('initial_paragraphs',
                               doc.SectionContents.initial_paragraphs.fget,
                               initial_paragraphs),
            asrt.sub_component('sections',
                               doc.SectionContents.sections.fget,
                               sections)
        ]))
示例#55
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)),
                                 ]))
示例#56
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_symbol(expected: su.SymbolDefinition,
                  ignore_source_line: bool = True) -> ValueAssertion[su.SymbolDefinition]:
    return asrt.is_instance_with(su.SymbolDefinition,
                                 asrt.And([
                                     asrt.sub_component('name',
                                                        su.SymbolDefinition.name.fget,
                                                        asrt.equals(expected.name)),
                                     asrt.sub_component('resolver_container',
                                                        su.SymbolDefinition.resolver_container.fget,
                                                        equals_container(expected.resolver_container,
                                                                         ignore_source_line)),

                                 ])
                                 )
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))
示例#59
0
def is_resolver_of_logic_type(logic_value_type: LogicValueType,
                              value_type: ValueType) -> ValueAssertion[rs.SymbolValueResolver]:
    return asrt.is_instance_with(LogicValueResolver,
                                 asrt.and_([
                                     asrt.sub_component('type_category',
                                                        rs.get_type_category,
                                                        asrt.is_(TypeCategory.LOGIC)),

                                     asrt.sub_component('logic_value_type',
                                                        get_logic_value_type,
                                                        asrt.is_(logic_value_type)),

                                     asrt.sub_component('value_type',
                                                        rs.get_value_type,
                                                        asrt.is_(value_type)),
                                 ]))
示例#60
0
def is_resolver_of_data_type(data_value_type: DataValueType,
                             value_type: ValueType) -> ValueAssertion[rs.SymbolValueResolver]:
    return asrt.is_instance_with(DataValueResolver,
                                 asrt.and_([
                                     asrt.sub_component('type_category',
                                                        rs.get_type_category,
                                                        asrt.is_(TypeCategory.DATA)),

                                     asrt.sub_component('data_value_type',
                                                        get_data_value_type,
                                                        asrt.is_(data_value_type)),

                                     asrt.sub_component('value_type',
                                                        rs.get_value_type,
                                                        asrt.is_(value_type)),
                                 ]))