Пример #1
0
def entity_list_hierarchy(entity_type_identifier: str,
                          mk_article_constructor: Callable[[EntityDocumentation], ArticleContentsConstructor],
                          header: str,
                          entities: List[EntityDocumentation]
                          ) -> SectionHierarchyGenerator:
    def entity_node(entity: EntityDocumentation) -> SectionHierarchyGenerator:
        additional_tags = {
            std_tags.ENTITY,
            entity_type_identifier,
        }
        return h.with_fixed_root_target(
            entity.cross_reference_target(),
            h.leaf_article(
                entity.singular_name_text,
                mk_article_constructor(entity),
                additional_tags)
        )

    return h.hierarchy(
        header,
        paragraphs.empty(),
        [
            entity_node(entity)
            for entity in sorted_entity_list(entities)
        ]
    )
Пример #2
0
    def test_with_fixed_root_target(self):
        # ARRANGE #

        root_header = StringText('root header')
        sub_header = StringText('sub header')
        sub_local_target_name = 'should not be used'

        fixed_target = CustomCrossReferenceTargetTestImpl('the fixed root target')

        default_target = CustomCrossReferenceTargetTestImpl('default target component')

        target_factory = ConstantTargetInfoFactoryTestImpl(default_target)

        unadjusted_object = sut.hierarchy(root_header,
                                          paragraphs.empty(),
                                          [sut.child(sub_local_target_name,
                                                     sut.leaf(sub_header.value,
                                                              section_contents(doc.empty_section_contents())))
                                           ]
                                          )
        adjusted_object = sut.with_fixed_root_target(fixed_target,
                                                     unadjusted_object)

        # EXPECTATION #

        expected_root_target_info = TargetInfo(root_header,
                                               fixed_target)

        expected_sub_target_info = TargetInfo(sub_header,
                                              default_target)

        target_info_node_assertion = equals_target_info_node(
            TargetInfoNode(expected_root_target_info,
                           [target_info_leaf(expected_sub_target_info)]),
            mk_equals_cross_ref_id=equals_custom_cross_ref_test_impl)

        section_assertion = section_matches(
            target=equals_custom_cross_ref_test_impl(fixed_target),
            header=asrt_para.equals_text(expected_root_target_info.presentation_text),
            contents=section_contents_matches(
                initial_paragraphs=asrt.is_empty_sequence,
                sections=asrt.matches_sequence([
                    section_matches(
                        target=equals_custom_cross_ref_test_impl(default_target),
                        header=asrt_para.equals_text(sub_header),
                        contents=section_contents_matches(
                            initial_paragraphs=asrt.is_empty_sequence,
                            sections=asrt.is_empty_sequence
                        )
                    )
                ])
            ))

        # ACT & ASSERT #

        self._act_and_assert(adjusted_object,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion)
Пример #3
0
    def test_with_fixed_root_target(self):
        # ARRANGE #

        root_header = StringText('root header')
        sub_header = StringText('sub header')
        sub_local_target_name = 'should not be used'

        fixed_target = CustomCrossReferenceTargetTestImpl('the fixed root target')

        default_target = CustomCrossReferenceTargetTestImpl('default target component')

        target_factory = ConstantTargetInfoFactoryTestImpl(default_target)

        unadjusted_object = sut.hierarchy(root_header,
                                          paragraphs.empty(),
                                          [sut.child(sub_local_target_name,
                                                     sut.leaf(sub_header.value,
                                                              section_contents(doc.empty_section_contents())))
                                           ]
                                          )
        adjusted_object = sut.with_fixed_root_target(fixed_target,
                                                     unadjusted_object)

        # EXPECTATION #

        expected_root_target_info = TargetInfo(root_header,
                                               fixed_target)

        expected_sub_target_info = TargetInfo(sub_header,
                                              default_target)

        target_info_node_assertion = equals_target_info_node(
            TargetInfoNode(expected_root_target_info,
                           [target_info_leaf(expected_sub_target_info)]),
            mk_equals_cross_ref_id=equals_custom_cross_ref_test_impl)

        section_assertion = section_matches(
            target=equals_custom_cross_ref_test_impl(fixed_target),
            header=asrt_para.equals_text(expected_root_target_info.presentation_text),
            contents=section_contents_matches(
                initial_paragraphs=asrt.is_empty_sequence,
                sections=asrt.matches_sequence([
                    section_matches(
                        target=equals_custom_cross_ref_test_impl(default_target),
                        header=asrt_para.equals_text(sub_header),
                        contents=section_contents_matches(
                            initial_paragraphs=asrt.is_empty_sequence,
                            sections=asrt.is_empty_sequence
                        )
                    )
                ])
            ))

        # ACT & ASSERT #

        self._act_and_assert(adjusted_object,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion)
Пример #4
0
def hierarchy(
    header: StrOrStringText,
    initial_paragraphs: ParagraphItemsConstructor = paragraphs.empty(),
    children: Iterable[SectionHierarchyGenerator] = (),
) -> SectionHierarchyGenerator:
    """
    A section with sub sections that appear in the TOC/target hierarchy.
    """
    return _Hierarchy(docs.str_text(header), initial_paragraphs, children)
Пример #5
0
def hierarchy(header: StrOrStringText,
              initial_paragraphs: ParagraphItemsConstructor = paragraphs.empty(),
              children: Iterable[SectionHierarchyGenerator] = (),
              ) -> SectionHierarchyGenerator:
    """
    A section with sub sections that appear in the TOC/target hierarchy.
    """
    return _Hierarchy(docs.str_text(header),
                      initial_paragraphs,
                      children)
 def instructions_per_section(self,
                              header: str,
                              ) -> SectionHierarchyGenerator:
     return h.hierarchy(header,
                        paragraphs.empty(),
                        [
                            h.child(section.name.plain,
                                    _InstructionsInSection.hierarchy_for(self._section_concept_name,
                                                                         section),
                                    )
                            for section in self._sections
                            if section.has_instructions
                        ])
Пример #7
0
def entity_list_hierarchy(
        entity_type_identifier: str,
        mk_article_constructor: Callable[[EntityDocumentation],
                                         ArticleContentsConstructor],
        header: str,
        entities: List[EntityDocumentation]) -> SectionHierarchyGenerator:
    def entity_node(entity: EntityDocumentation) -> SectionHierarchyGenerator:
        additional_tags = {
            std_tags.ENTITY,
            entity_type_identifier,
        }
        return h.with_fixed_root_target(
            entity.cross_reference_target(),
            h.leaf_article(entity.singular_name_text,
                           mk_article_constructor(entity), additional_tags))

    return h.hierarchy(
        header, paragraphs.empty(),
        [entity_node(entity) for entity in sorted_entity_list(entities)])
 def custom_sections_list(self,
                          header: str,
                          sections: Sequence[SectionDocumentation]) -> SectionHierarchyGenerator:
     return h.hierarchy(
         header,
         paragraphs.empty(),
         [
             h.child(section.name.plain,
                     h.with_fixed_root_target(
                         section.section_info.cross_reference_target,
                         h.leaf_article(
                             section.syntax_name_text,
                             self._article_constructor_for_section(section),
                             tags={std_tags.SECTION},
                         )
                     ),
                     )
             for section in sections
         ]
     )
Пример #9
0
    def test_hierarchy_without_sub_sections(self):
        # ARRANGE #
        target_factory = TargetInfoFactoryTestImpl(['target_component'])
        root_header_text = StringText('root header')
        object_to_test = sut.hierarchy(root_header_text, paragraphs.empty(), [])
        # EXPECTATION #
        expected_target_info = target_factory.root(root_header_text)

        target_info_node_assertion = equals_target_info_node(
            target_info_leaf(expected_target_info),
            mk_equals_cross_ref_id=equals_custom_cross_ref_test_impl)

        section_assertion = section_matches(
            target=equals_custom_cross_ref_test_impl(expected_target_info.target),
            header=asrt_para.equals_text(expected_target_info.presentation_text),
            contents=asrt.sub_component('is_empty',
                                        doc.SectionContents.is_empty.fget,
                                        asrt.is_true))
        # ACT & ASSERT #
        self._act_and_assert(object_to_test,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion)
Пример #10
0
    def test_hierarchy_without_sub_sections(self):
        # ARRANGE #
        target_factory = TargetInfoFactoryTestImpl(['target_component'])
        root_header_text = StringText('root header')
        object_to_test = sut.hierarchy(root_header_text, paragraphs.empty(), [])
        # EXPECTATION #
        expected_target_info = target_factory.root(root_header_text)

        target_info_node_assertion = equals_target_info_node(
            target_info_leaf(expected_target_info),
            mk_equals_cross_ref_id=equals_custom_cross_ref_test_impl)

        section_assertion = section_matches(
            target=equals_custom_cross_ref_test_impl(expected_target_info.target),
            header=asrt_para.equals_text(expected_target_info.presentation_text),
            contents=asrt.sub_component('is_empty',
                                        doc.SectionContents.is_empty.fget,
                                        asrt.is_true))
        # ACT & ASSERT #
        self._act_and_assert(object_to_test,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion)
Пример #11
0
def contents(initial_paragraphs: ParagraphItemsConstructor = paragraphs.empty(),
             sub_sections: Iterable[SectionConstructor] = (),
             ) -> SectionContentsConstructor:
    return _SectionContents([initial_paragraphs],
                            sub_sections)
Пример #12
0
def contents(initial_paragraphs: ParagraphItemsConstructor = paragraphs.empty(),
             sub_sections: Iterable[SectionConstructor] = (),
             ) -> SectionContentsConstructor:
    return _SectionContents([initial_paragraphs],
                            sub_sections)