def test_syntax_element_descriptions(self): syntax = sut.Syntax(test_grammars.GRAMMAR_WITH_ALL_COMPONENTS) actual = syntax.syntax_element_descriptions() self.assertGreater(len(actual), 0, 'number of syntax element descriptions') asrt.is_sequence_of( is_syntax_element_description).apply_without_message(self, actual)
def _apply(self, put: unittest.TestCase, value: SymbolDependentValue, message_builder: asrt.MessageBuilder): put.assertIsInstance(value, SymbolDependentValue, message_builder.apply("SDV type")) self.sdv_type.apply(put, value, message_builder) references__actual = value.references references__message_builder = message_builder.for_sub_component('references') asrt.is_sequence_of(asrt.is_instance(SymbolReference)).apply( put, references__actual, references__message_builder ) self.references.apply(put, references__actual, references__message_builder) self.custom.apply(put, value, message_builder) ddv = value.resolve(self.symbols) self.ddv.apply(put, ddv, message_builder.for_sub_component('ddv'))
def test_precedence_description_SHOULD_not_be_empty(self): cases = [ NameAndValue( 'grammar w just 2 infix OPs (of same precedence)', _grammar_with_operators( (), [[ test_grammars.infix_op_of('op_1', test_grammars.InfixOpA), test_grammars.infix_op_of('op_2', test_grammars.InfixOpA) ]], )), NameAndValue( 'grammar w just 2 infix OPs (of different precedences)', _grammar_with_operators( (), [ [ test_grammars.infix_op_of('op_1', test_grammars.InfixOpA) ], [ test_grammars.infix_op_of('op_2', test_grammars.InfixOpA) ], ], )), NameAndValue( 'grammar w 1 prefix OP & 1 infix OP', _grammar_with_operators( [ test_grammars.prefix_op('prefix_op', test_grammars.PrefixOpExprP) ], [[ test_grammars.infix_op_of('infix_op', test_grammars.InfixOpA) ]], )), ] for case in cases: syntax = sut.Syntax(case.value) with self.subTest(case.name): # ACT # actual = syntax.precedence_description() # ASSERT # self.assertGreater(len(actual), 0, 'number of paragraphs') asrt.is_sequence_of( asrt_struct.is_paragraph_item).apply_without_message( self, actual)
def test_builtin(self): # ACT # actual = sut.defined_at_line__err_msg_lines(None) # ASSERT # is_list_of_strings = asrt.is_sequence_of(asrt.is_instance(str)) is_list_of_strings.apply_without_message(self, actual)
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 _expect_failure_in(step_of_expected_failure: Step) -> Expectation: symbol_usages_expectation = asrt.is_sequence_of(asrt.is_instance(SymbolReference)) if step_of_expected_failure is Step.VALIDATE_PRE_SDS: return Expectation(validation_pre_sds=IS_FAILURE_OF_VALIDATION, symbol_usages=symbol_usages_expectation) else: return Expectation(main_result=IS_FAILURE, symbol_usages=symbol_usages_expectation)
def is_valid_source_location_info() -> Assertion[SourceLocationInfo]: is_valid_source_location = matches_source_location( source=is_line_sequence() ) return matches_source_location_info( source_location_path=matches_source_location_path( source_location=is_valid_source_location, file_inclusion_chain=asrt.is_sequence_of(is_valid_source_location) ) )
def test_user_defined(self): # ARRANGE # sli = SourceLocationInfo( Path.cwd(), SOURCE_LOCATION_PATH_WITH_INCLUSIONS_AND_FILE_NAMES) # ACT # actual = sut.defined_at_line__err_msg_lines(sli) # ASSERT # is_list_of_strings = asrt.is_sequence_of(asrt.is_instance(str)) is_list_of_strings.apply_without_message(self, actual)
def test_user_defined(self): # ARRANGE # sli = SourceLocationInfo(Path.cwd(), SOURCE_LOCATION_PATH_WITH_INCLUSIONS_AND_FILE_NAMES) # ACT # actual = sut.defined_at_line__err_msg_lines(sli) # ASSERT # is_list_of_strings = asrt.is_sequence_of(asrt.is_instance(str)) is_list_of_strings.apply_without_message(self, actual)
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 is_indented_detail( details: Assertion[Sequence[Detail]] = asrt.is_sequence_of( asrt.is_instance(Detail)), ) -> Assertion[Detail]: return asrt.is_instance_with__many( IndentedDetail, [ asrt.sub_component( 'values', IndentedDetail.details.fget, asrt.is_not_none_and(details), ), ], )
def matches_major_block( minor_blocks: Assertion[Sequence[MinorBlock]] = asrt.anything_goes(), properties: Assertion[ElementProperties] = matches_element_properties( )) -> Assertion[MajorBlock]: return asrt.is_instance_with__many(MajorBlock, [ asrt.sub_component( 'minor blocks', MajorBlock.parts.fget, asrt.and_([ asrt.is_sequence_of(matches_minor_block(asrt.anything_goes())), minor_blocks, ]), ), asrt.sub_component( 'properties', MajorBlock.properties.fget, properties, ), ])
def matches_source_location_path( source_location: Assertion[SourceLocation] = asrt.anything_goes(), file_inclusion_chain: Assertion[Sequence[SourceLocation]] = asrt.anything_goes(), ) -> Assertion[SourceLocationPath]: return asrt.is_instance_with( SourceLocationPath, asrt.and_([ asrt.sub_component('location', SourceLocationPath.location.fget, asrt.is_instance_with(SourceLocation, source_location), ), asrt.sub_component('file_inclusion_chain', SourceLocationPath.file_inclusion_chain.fget, asrt.and_([ asrt.is_sequence_of(asrt.is_instance(SourceLocation)), file_inclusion_chain, ]), ) ]))
def matches_minor_block( line_elements: Assertion[Sequence[LineElement]], properties: Assertion[ElementProperties] = matches_element_properties() ) -> Assertion[MinorBlock]: return asrt.is_instance_with__many(MinorBlock, [ asrt.sub_component( 'line elements', MinorBlock.parts.fget, asrt.and_([ asrt.is_sequence_of(matches_line_element( is_any_line_object())), line_elements, ]), ), asrt.sub_component( 'properties', MinorBlock.properties.fget, properties, ), ])
def is_header_and_value_detail( header: Assertion[ToStringObject] = asrt.anything_goes(), values: Assertion[Sequence[Detail]] = asrt.is_sequence_of( asrt.is_instance(Detail)), ) -> Assertion[Detail]: return asrt.is_instance_with__many( HeaderAndValueDetail, [ asrt.sub_component( 'header', HeaderAndValueDetail.header.fget, asrt.is_not_none_and(header), ), asrt.sub_component( 'values', HeaderAndValueDetail.values.fget, asrt.is_not_none_and(values), ), ], )
def _resolve(self, resolver: FileMatcherResolver, environment: PathResolvingEnvironmentPreOrPostSds) -> Tuple[FileMatcherValue, FileMatcher]: resolver_health_check = resolver_assertions.matches_resolver_of_file_matcher( resolved_value=matches_file_matcher_value( tcds=environment.home_and_sds ), references=asrt.is_sequence_of(asrt.is_instance(SymbolReference)), symbols=environment.symbols) resolver_health_check.apply_with_message(self.put, resolver, 'resolver structure') matcher_value = resolver.resolve(environment.symbols) assert isinstance(matcher_value, FileMatcherValue) matcher = matcher_value.value_of_any_dependency(environment.home_and_sds) assert isinstance(matcher, FileMatcher) return matcher_value, matcher
def _expect_failure_in( step_of_expected_failure: Step) -> MultiSourceExpectation: symbol_usages_expectation = asrt.is_sequence_of( asrt.is_instance(SymbolReference)) if step_of_expected_failure is Step.VALIDATE_PRE_SDS: return MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.pre_sds_fails__w_any_msg(), symbol_usages=symbol_usages_expectation, ) elif step_of_expected_failure is Step.VALIDATE_POST_SDS: return MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.post_sds_fails__w_any_msg(), symbol_usages=symbol_usages_expectation, ) elif step_of_expected_failure is Step.MAIN: return MultiSourceExpectation.phase_agnostic( main_result=IS_FAILURE, symbol_usages=symbol_usages_expectation, ) else: raise ValueError('Unknown {}: {}'.format(Step, step_of_expected_failure))
def __init__(self, expected_object_type: Type[FullDepsSdv]): self._is_valid_sdv = asrt_logic.matches_sdv_attributes( expected_object_type, asrt.is_sequence_of(asrt.is_instance(SymbolReference)) )
def visit_details(self, description: DetailsDescription) -> None: assertion = asrt.is_sequence_of(described_tree_assertions.is_any_detail()) actual_details = description.details().render() assertion.apply(self._put, actual_details, self._message_builder)
def _type_sanity_of_sequence_of_minor_blocks( ) -> Assertion[Sequence[MinorBlock]]: return asrt.is_sequence_of( asrt_struct.matches_minor_block(asrt.anything_goes()))
def _type_sanity_of_sequence_of_line_elements( ) -> Assertion[Sequence[LineElement]]: return asrt.is_sequence_of( asrt_struct.matches_line_element(asrt.anything_goes()))
def matches_details_renderer( rendered_details: Assertion[Sequence[Detail]] = asrt.is_sequence_of( described_tree_assertions.is_any_detail()) ) -> Assertion[DetailsRenderer]: return _MatchesDetailsRendererAssertion(rendered_details)
def test_syntax_descriptions(self): syntax = sut.Syntax(test_grammars.GRAMMAR_WITH_ALL_COMPONENTS) actual = syntax.syntax_description() self.assertGreater(len(actual), 0, 'number of paragraphs') asrt.is_sequence_of( asrt_struct.is_paragraph_item).apply_without_message(self, actual)
def test_invokation_variants(self): syntax = sut.Syntax(test_grammars.GRAMMAR_WITH_ALL_COMPONENTS) actual = syntax.invokation_variants() self.assertGreater(len(actual), 0, 'number of elements') asrt.is_sequence_of(is_invokation_variant).apply_without_message( self, actual)
def _get_source_block_source_location_info( block: sut.DefinitionSourceBlock) -> Optional[SourceLocationInfo]: return block.source_location def _get_source_block_phase_enum( block: sut.DefinitionSourceBlock) -> PhaseEnum: return block.phase_if_user_defined_symbol.the_enum def _get_reference_block_symbol_name( block: sut.ReferenceSourceLocationBlock) -> str: return block.reference.value().name IS_SEQUENCE_OF_MAJOR_BLOCKS = asrt.is_sequence_of( asrt_text_struct.matches_major_block()) _SOURCE_INFO_WITH_SOURCE = symbol_info.SourceInfo.of_lines( ['the reference source line']) _VALUE_CONTEXTS_OF_EVERY_TYPE = [ string.ARBITRARY_SYMBOL_VALUE_CONTEXT, list_.ARBITRARY_SYMBOL_VALUE_CONTEXT, path.ARBITRARY_SYMBOL_VALUE_CONTEXT, line_matcher.ARBITRARY_SYMBOL_VALUE_CONTEXT, string_matcher.ARBITRARY_SYMBOL_VALUE_CONTEXT, file_matcher.ARBITRARY_SYMBOL_VALUE_CONTEXT, files_matcher_sc.ARBITRARY_SYMBOL_VALUE_CONTEXT, files_condition.ARBITRARY_SYMBOL_VALUE_CONTEXT, st_symbol_context.ARBITRARY_SYMBOL_VALUE_CONTEXT, program.ARBITRARY_SYMBOL_VALUE_CONTEXT,