def runTest(self): test_cases = [ ('minimal', ActorTestImpl('name')), ('with act_phase_contents', ActorTestImpl('name', act_phase_contents=_section_contents())), ('with act_phase_contents_syntax', ActorTestImpl('name', act_phase_contents_syntax=_section_contents())), ('see_also_specific', ActorTestImpl( 'name', see_also_specific=[ CustomCrossReferenceId('custom-cross-reference-target') ])), ('full', ActorTestImpl( 'name', act_phase_contents=_section_contents(), act_phase_contents_syntax=_section_contents(), see_also_specific=[ CustomCrossReferenceId('custom-cross-reference-target') ])), ] for test_case_name, documentation in test_cases: with self.subTest(test_case_name=test_case_name): # ARRANGE # renderer = sut.IndividualActorConstructor(documentation) # ACT # actual = renderer.apply(CONSTRUCTION_ENVIRONMENT) # ASSERT # struct_check.is_article_contents.apply(self, actual)
def test_union(self): cases = [ ( 'both sets are empty', sut.SeeAlsoSet([]), sut.SeeAlsoSet([]), 0, ), ( 'one empty and one non-empty', sut.SeeAlsoSet([CustomCrossReferenceId('an_element')]), sut.SeeAlsoSet([]), 1, ), ( 'two non-empty with different elements', sut.SeeAlsoSet([CustomCrossReferenceId('a')]), sut.SeeAlsoSet([CustomCrossReferenceId('b')]), 2, ), ( 'two non-empty with equal elements', sut.SeeAlsoSet([CustomCrossReferenceId('a')]), sut.SeeAlsoSet([CustomCrossReferenceId('a')]), 1, ), ] for name, a, b, expected_size in cases: with self.subTest(name=name): actual = a.union(b) self.assertEqual(expected_size, len(actual.see_also_items))
def test_elements_SHOULD_be_translated_to_see_also_items(self): cases = [ NameAndValue('empty', (sut.SeeAlsoSet([]), asrt.matches_sequence([]))), NameAndValue('single cross ref', (sut.SeeAlsoSet([CustomCrossReferenceId('target')]), asrt.matches_sequence([is_see_also_item]))), NameAndValue('single see also url info', (sut.SeeAlsoSet([sut.SeeAlsoUrlInfo('name', 'url')]), asrt.matches_sequence([is_see_also_item]))), NameAndValue(' see also url info and cross ref', (sut.SeeAlsoSet([ sut.SeeAlsoUrlInfo('name', 'url'), TestCasePhaseInstructionCrossReference('phase', 'instruction') ]), asrt.matches_sequence([is_see_also_item, is_see_also_item]))), ] for case in cases: see_also_set, assertion = case.value with self.subTest(name=case.name): # ACT # actual = see_also_set.see_also_items # ASSERT # assertion.apply_without_message(self, actual)
def root(self, presentation: core.StringText) -> TargetInfo: return TargetInfo(presentation, CustomCrossReferenceId(self.prefix))
def test_create_non_empty_with_duplicate_elements(self): element = CustomCrossReferenceId('an_element') actual = sut.SeeAlsoSet([element, element]) self.assertEqual(1, len(actual.see_also_items))
def test_cross_reference_id(self): self._check( sut.CrossReferenceIdSeeAlsoItem( CustomCrossReferenceId('target name')), sut.CrossReferenceIdSeeAlsoItem)
def instruction_cross_reference_target(self, instruction_name: str) -> CrossReferenceId: return CustomCrossReferenceId('section-instruction.test.impl.' + self.name.plain + '.' + instruction_name)
def cross_reference_target(self) -> CrossReferenceId: return CustomCrossReferenceId('section.test.impl.' + self.name.plain)
return PrimitiveWithArg(token.string) def parse_primitive_sans_arg(parser: TokenParser) -> PrimitiveSansArg: return PrimitiveSansArg() def parse_recursive_primitive_of_grammar_w_all_components( token_parser: TokenParser) -> PrimitiveRecursive: expr_parser = expression_parser.parsers(GRAMMAR_WITH_ALL_COMPONENTS, False).simple argument = expr_parser.parse_from_token_parser(token_parser) return PrimitiveRecursive(argument) CROSS_REF_ID = CustomCrossReferenceId('custom-target') PRIMITIVE_WITH_ARG = 'primitive_with_arg' PRIMITIVE_SANS_ARG = 'primitive_sans_arg' PRIMITIVE_RECURSIVE = 'primitive_recursive' NOT_A_PRIMITIVE_EXPR_NAME_AND_NOT_A_VALID_SYMBOL_NAME = 'not/a/primitive/expr/name/and/not/a/valid/symbol/name' PREFIX_P = '!' PREFIX_Q = 'prefix_q' INFIX_OP_A = 'infix_op_a' INFIX_OP_B_THAT_IS_NOT_A_VALID_SYMBOL_NAME = '||' def infix_op_of(
def runTest(self): for type_category in [None, TypeCategory.DATA]: nrt = name_and_ref_target('SE1', type_category, 'single line description of SE1') test_cases = [ ('minimal', syntax_element_documentation(nrt.type_category, nrt, [], (), [], [], [])), ('with main description rest', syntax_element_documentation(nrt.type_category, nrt, [docs.para('a paragraph')], (), [], [], [])), ('with main description rest sub sections', syntax_element_documentation(nrt.type_category, nrt, [], [ docs.section('a section header', docs.paras('section contents')) ], [], [], [])), ('with main description rest, and notes', syntax_element_documentation( nrt.type_category, nrt, [], [ docs.section('a section header', docs.paras('section contents')) ], [], [], [], docs.section_contents( docs.paras('notes section contents')), )), ('with invokation variants', syntax_element_documentation(nrt.type_category, nrt, [], (), syntax_parts.INVOKATION_VARIANTS, [], [])), ('with syntax element descriptions', syntax_element_documentation( nrt.type_category, nrt, [], (), [], syntax_parts.SYNTAX_ELEMENT_DESCRIPTIONS, [])), ('see also', syntax_element_documentation( nrt.type_category, nrt, [], (), [], [], [CustomCrossReferenceId('custom-target-name')], )), ('full', syntax_element_documentation( nrt.type_category, nrt, [docs.para('a paragraph')], [ docs.section('a section header', docs.paras('section contents')) ], [InvokationVariant('syntax', [docs.para('a paragraph')])], syntax_parts.SYNTAX_ELEMENT_DESCRIPTIONS, [CustomCrossReferenceId('custom-target-name')], docs.section_contents( docs.paras('notes section contents')))), ] for test_case_name, documentation in test_cases: with self.subTest(test_case_name=test_case_name, type_category=type_category): # ARRANGE # renderer = sut.IndividualSyntaxElementConstructor( documentation) # ACT # actual = renderer.apply(CONSTRUCTION_ENVIRONMENT) # ASSERT # struct_check.is_article_contents.apply(self, actual)
def _see_also_targets__specific(self) -> List[SeeAlsoTarget]: return [CustomCrossReferenceId('custom-cross-reference-target')]