def syntax_element_description_list() -> ParagraphItem:
     items = []
     for sed in syntax_element_descriptions:
         variants_list_paragraphs = []
         if sed.invokation_variants:
             variants_list_paragraphs = [variants_list(None,
                                                       sed.invokation_variants,
                                                       True,
                                                       custom_separations=BLANK_LINE_BETWEEN_ELEMENTS)]
         separator_paras = (
             [FORMS_PARA]
             if sed.invokation_variants and invokation_variants_are_surrounded_by_text(sed)
             else []
         )
         contents = (
                 list(sed.before_invokation_variants) +
                 separator_paras +
                 variants_list_paragraphs +
                 list(sed.after_invokation_variants)
         )
         items.append(docs.list_item(syntax_text(sed.element_name),
                                     contents))
     return lists.HeaderContentList(items,
                                    lists.Format(lists.ListType.VARIABLE_LIST,
                                                 custom_indent_spaces=_custom_list_indent(True),
                                                 custom_separations=BLANK_LINE_BETWEEN_ELEMENTS))
Example #2
0
def simple_list_with_space_between_elements_and_content(
        items: Iterable[lists.HeaderContentListItem],
        list_type: lists.ListType) -> lists.HeaderContentList:
    return lists.HeaderContentList(
        items,
        lists.Format(list_type,
                     custom_separations=SEPARATION_OF_HEADER_AND_CONTENTS))
Example #3
0
 def custom_indent(self):
     formatter = sut.Formatter(CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                               sut.Wrapper(page_width=100),
                               list_formats=self.LIST_FORMATS)
     actual = formatter.resolve_list_format(
         lists.Format(lists.ListType.VARIABLE_LIST,
                      custom_indent_spaces=10))
     self.assertEqual(10 * ' ', actual.indent_str)
Example #4
0
class TestOrderedAndItemizedLists(unittest.TestCase):
    EXPECTED_ORDERED_LIST_FORMAT = lists.Format(lists.ListType.ORDERED_LIST,
                                                custom_indent_spaces=sut.DEFAULT_LIST_SETTINGS.custom_indent_spaces,
                                                custom_separations=sut.DEFAULT_LIST_SETTINGS.custom_separations)

    EXPECTED_ITEMIZED_LIST_FORMAT = lists.Format(lists.ListType.ITEMIZED_LIST,
                                                 custom_indent_spaces=sut.DEFAULT_LIST_SETTINGS.custom_indent_spaces,
                                                 custom_separations=sut.DEFAULT_LIST_SETTINGS.custom_separations)

    def test_nested_lists(self):
        expected = [
            lists.HeaderContentList([
                _list_item('itemized item 1',
                           [
                               Paragraph([StringText('item 1 contents paragraph')]),
                               lists.HeaderContentList(
                                   [
                                       _list_item('ordered item 1/1',
                                                  [
                                                      Paragraph([StringText('item 1/1 contents paragraph')]),
                                                  ]),
                                       _list_item('ordered item 1/2',
                                                  []),
                                   ],
                                   self.EXPECTED_ORDERED_LIST_FORMAT),
                           ]),
                _list_item('itemized item 2',
                           []),
            ],
                self.EXPECTED_ITEMIZED_LIST_FORMAT),
        ]
        actual = sut.parse(['  * itemized item 1',
                            '',
                            '    item 1 contents paragraph',
                            '',
                            '',
                            '      1. ordered item 1/1',
                            '',
                            '         item 1/1 contents paragraph',
                            '',
                            '      1. ordered item 1/2',
                            '',
                            '  * itemized item 2',
                            ])
        check(self, expected, actual)
Example #5
0
 def test_ordered_list(self):
     items = [header_only_item('header')]
     formatter = sut.Formatter(CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                               sut.Wrapper(page_width=100),
                               list_formats=self.LIST_FORMATS)
     actual = formatter.format_header_content_list(
         lists.HeaderContentList(items,
                                 lists.Format(lists.ListType.ORDERED_LIST)))
     self.assertEqual(['1. header'], actual)
Example #6
0
 def custom_separation(self):
     custom_separations = lists.Separations(10, 20)
     formatter = sut.Formatter(CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                               sut.Wrapper(page_width=100),
                               list_formats=self.LIST_FORMATS)
     actual = formatter.resolve_list_format(
         lists.Format(lists.ListType.VARIABLE_LIST,
                      custom_separations=custom_separations))
     self.assertIs(custom_separations, actual.separations)
Example #7
0
 def _list(
         items: List[lists.HeaderContentListItem]
 ) -> lists.HeaderContentList:
     return lists.HeaderContentList(
         items,
         lists.Format(
             lists.ListType.VARIABLE_LIST,
             custom_indent_spaces=0,
             custom_separations=docs.SEPARATION_OF_HEADER_AND_CONTENTS))
Example #8
0
def _directory_structure_list(
        dir_with_sub_dir_list: List[DirWithSubDirs]) -> ParagraphItem:
    items = []
    for dir_wsd in dir_with_sub_dir_list:
        sub_dirs_items = []
        if dir_wsd.sub_dirs:
            sub_dirs_items = [_directory_structure_list(dir_wsd.sub_dirs)]
        items.append(
            docs.list_item(dir_name_text(dir_wsd.name), sub_dirs_items))
    return lists.HeaderContentList(items,
                                   lists.Format(lists.ListType.ITEMIZED_LIST))
Example #9
0
def toc_list(target_info_hierarchy: Sequence[TargetInfoNode],
             list_type: lists.ListType) -> doc.ParagraphItem:
    items = []
    for node in target_info_hierarchy:
        sub_lists = []
        if node.children:
            sub_lists = [toc_list(node.children, list_type)]
        item = docs.list_item(
            docs.cross_reference(node.data.presentation_text,
                                 node.data.target), sub_lists)
        items.append(item)
    return lists.HeaderContentList(items, lists.Format(list_type))
Example #10
0
 def test_visit_list(self):
     # ARRANGE #
     list_item = lists.HeaderContentListItem(core.StringText('item text'),
                                             [])
     item = lists.HeaderContentList([list_item],
                                    lists.Format(
                                        lists.ListType.ITEMIZED_LIST))
     visitor = AVisitorThatRecordsVisitedMethods()
     # ACT #
     ret_val = visitor.visit(item)
     # ASSERT #
     self.assertEqual([lists.HeaderContentList], visitor.visited_types)
     self.assertIs(item, ret_val)
Example #11
0
 def _sorted_entities_list(
         self, entities: Iterable[EntityDocumentation]
 ) -> lists.HeaderContentList:
     items = [
         docs.list_item(entity.singular_name(),
                        self.entity_2_summary_paragraphs(entity))
         for entity in (sorted_entity_list(entities))
     ]
     return lists.HeaderContentList(
         items,
         lists.Format(lists.ListType.VARIABLE_LIST,
                      custom_indent_spaces=0,
                      custom_separations=SEPARATION_OF_HEADER_AND_CONTENTS))
Example #12
0
    def instruction_set_list(self,
                             instructions: Sequence[InstructionDocumentation],
                             environment: ConstructionEnvironment) -> ParagraphItem:
        instruction_list_items = [
            instruction_set_list_item(doc, self.name_2_name_text_fun)
            for doc in instructions
        ]
        instr_list = lists.HeaderContentList(instruction_list_items,
                                             lists.Format(lists.ListType.VARIABLE_LIST,
                                                          custom_indent_spaces=0))

        if environment.construct_simple_header_value_lists_as_tables:
            return transform_list_to_table(instr_list)
        else:
            return instr_list
def variants_list(instruction_name: Optional[str],
                  invokation_variants: Iterable[InvokationVariant],
                  indented: bool = False,
                  custom_separations: lists.Separations = None) -> ParagraphItem:
    title_prefix = instruction_name + ' ' if instruction_name else ''
    items = []
    for x in invokation_variants:
        assert isinstance(x, InvokationVariant)
        title = title_prefix + x.syntax
        items.append(docs.list_item(syntax_text(title),
                                    list(x.description_rest)))
    return lists.HeaderContentList(items,
                                   lists.Format(lists.ListType.VARIABLE_LIST,
                                                custom_indent_spaces=_custom_list_indent(indented),
                                                custom_separations=custom_separations))
Example #14
0
 def processing_step_list(self) -> docs.ParagraphItem:
     items = [
         docs.list_item(
             processing.STEP_PRE_PROCESSING.singular.capitalize(),
             step_with_single_exit_value(
                 self._tp.fnap(PURPOSE_OF_PREPROCESSING),
                 self._tp.para(FAILURE_CONDITION_OF_PREPROCESSING),
                 exit_values.NO_EXECUTION__PRE_PROCESS_ERROR)),
         docs.list_item(
             self._tp.text('Syntax checking and {directive:s} processing'),
             step_with_multiple_exit_values(
                 self._tp.fnap(PURPOSE_OF_SYNTAX_CHECKING),
                 self._tp.fnap(FAILURE_CONDITION_OF_SYNTAX_CHECKING),
                 [
                     NameAndValue('Syntax error',
                                  exit_values.NO_EXECUTION__SYNTAX_ERROR),
                     NameAndValue(
                         'File inclusion error',
                         exit_values.NO_EXECUTION__FILE_ACCESS_ERROR),
                 ],
             )),
         docs.list_item(
             self._tp.text(
                 '{validation:/u} and syntax checking of {act_phase:syntax}'
             ),
             step_with_multiple_exit_values(
                 self._tp.fnap(PURPOSE_OF_VALIDATION),
                 self._tp.fnap(FAILURE_CONDITION_OF_VALIDATION),
                 [
                     NameAndValue(
                         self._tp.text(
                             'Invalid syntax of {act_phase:syntax}'),
                         exit_values.EXECUTION__SYNTAX_ERROR),
                     NameAndValue(
                         self._tp.text(
                             'Invalid reference to {symbol} or external resource'
                         ), exit_values.EXECUTION__VALIDATION_ERROR),
                 ],
             )),
         docs.list_item(processing.STEP_EXECUTION.singular.capitalize(),
                        self._tp.fnap(EXECUTION_DESCRIPTION)),
     ]
     return lists.HeaderContentList(
         items,
         lists.Format(
             lists.ListType.ORDERED_LIST,
             custom_separations=docs.SEPARATION_OF_HEADER_AND_CONTENTS))
Example #15
0
def _sorted_conf_params_list() -> ParagraphItem:
    all_cfs = sorted(ALL_CONF_PARAM_INFOS,
                     key=SingularNameAndCrossReferenceId.singular_name.fget)
    items = [
        docs.list_item(
            docs.cross_reference(
                cf.configuration_parameter_name_text,
                cf.cross_reference_target,
                allow_rendering_of_visible_extra_target_text=False),
            docs.paras(cf.single_line_description_str)) for cf in all_cfs
    ]
    return lists.HeaderContentList(
        items,
        lists.Format(
            lists.ListType.VARIABLE_LIST,
            custom_indent_spaces=0,
            custom_separations=docs.SEPARATION_OF_HEADER_AND_CONTENTS))
Example #16
0
 def test_with_resolved_indent(self):
     format_indent_spaces = 2
     indent_str = format_indent_spaces * ' '
     list_format = lf.ListFormat(
         lf.HeaderAndIndentFormatPlain(contents_indent_spaces=4),
         NO_SEPARATIONS,
         indent_str=indent_str)
     items = [item('header', [single_text_para('contents')])]
     the_list = sut.HeaderContentList(
         items, lists.Format(lists.ListType.VARIABLE_LIST))
     formatter = sut.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         sut.Wrapper(page_width=100),
         list_formats=lf.ListFormats(variable_list_format=list_format))
     actual = formatter.format_header_content_list(the_list)
     self.assertEqual(
         [indent_str + 'header', indent_str + (4 * ' ') + 'contents'],
         actual)
Example #17
0
 def test_only_initial_paragraphs(self):
     paragraph_item_formatter = paragraph_item.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         paragraph_item.Wrapper(page_width=5),
         num_item_separator_lines=1,
         list_formats=lf.ListFormats(variable_list_format=lf.ListFormat(
             lf.HeaderAndIndentFormatPlain(),
             lists.Separations(0, 0),
             indent_str='')))
     formatter = sut.Formatter(paragraph_item_formatter)
     section_contents = SectionContents([
         single_text_para('12345 123 5'),
         lists.HeaderContentList(
             [header_only_item('12345 123')],
             lists.Format(lists.ListType.VARIABLE_LIST),
         )
     ], [])
     actual = formatter.format_section_contents(section_contents)
     self.assertEqual(['12345', '123 5', BLANK_LINE, '12345', '123'],
                      actual)
Example #18
0
class TestOrderedList(unittest.TestCase):
    EXPECTED_LIST_FORMAT = lists.Format(lists.ListType.ORDERED_LIST,
                                        custom_indent_spaces=sut.DEFAULT_LIST_SETTINGS.custom_indent_spaces,
                                        custom_separations=sut.DEFAULT_LIST_SETTINGS.custom_separations)

    def test_single_list_with_single_item_as_last_line(self):
        expected = [lists.HeaderContentList([_list_item('item')],
                                            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  1. item'])
        check(self, expected, actual)

    def test_single_list_with_single_item_with_contents_on_next_line(self):
        expected = [lists.HeaderContentList([
            _list_item('item',
                       [
                           Paragraph([StringText('contents')]),
                       ])],
            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  1. item',
                            '     contents',
                            ])
        check(self, expected, actual)
Example #19
0
 def test_with_custom_indent(self):
     custom_indent_spaces = 5
     custom_indent_str = custom_indent_spaces * ' '
     content_indent_spaces = 4
     content_indent_str = content_indent_spaces * ' '
     list_format = lf.ListFormat(
         lf.HeaderAndIndentFormatPlain(
             contents_indent_spaces=content_indent_spaces),
         NO_SEPARATIONS,
         indent_str='should not be used since overridden by custom indent')
     items = [item('header', [single_text_para('contents')])]
     the_list = sut.HeaderContentList(
         items,
         lists.Format(lists.ListType.VARIABLE_LIST,
                      custom_indent_spaces=custom_indent_spaces))
     formatter = sut.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         sut.Wrapper(page_width=100),
         list_formats=lf.ListFormats(variable_list_format=list_format))
     actual = formatter.format_header_content_list(the_list)
     self.assertEqual([
         custom_indent_str + 'header',
         custom_indent_str + content_indent_str + 'contents'
     ], actual)
Example #20
0
class TestItemizedList(unittest.TestCase):
    EXPECTED_LIST_FORMAT = lists.Format(lists.ListType.ITEMIZED_LIST,
                                        custom_indent_spaces=sut.DEFAULT_LIST_SETTINGS.custom_indent_spaces,
                                        custom_separations=sut.DEFAULT_LIST_SETTINGS.custom_separations)

    def test_single_list_with_single_item_as_last_line(self):
        expected = [lists.HeaderContentList([_list_item('item')],
                                            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  * item'])
        check(self, expected, actual)

    def test_single_list_with_single_item_followed_by_empty_line(self):
        expected = [lists.HeaderContentList([_list_item('item')],
                                            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  * item',
                            ''])
        check(self, expected, actual)

    def test_single_list_with_single_item_with_contents_on_next_line(self):
        expected = [lists.HeaderContentList([
            _list_item('item',
                       [
                           Paragraph([StringText('contents')]),
                       ])],
            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  * item',
                            '    contents',
                            ])
        check(self, expected, actual)

    def test_single_list_with_single_item_with_contents_on_line_after_separator(self):
        expected = [lists.HeaderContentList([
            _list_item('item',
                       [
                           Paragraph([StringText('contents')]),
                       ])],
            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  * item',

                            '    contents',
                            ])
        check(self, expected, actual)

    def test_single_list_with_with_contents(self):
        expected = [lists.HeaderContentList([
            _list_item('item 1',
                       [
                           Paragraph([StringText('contents 1')]),
                       ]),
            _list_item('item 2',
                       [
                           Paragraph([StringText('contents 2')]),
                       ]),
        ],
            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  * item 1',

                            '    contents 1',
                            '  * item 2',
                            '    contents 2',
                            ])
        check(self, expected, actual)

    def test_single_list_with_multiple_items(self):
        expected = [lists.HeaderContentList([_list_item('item 1'),
                                             _list_item('item 2')],
                                            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  * item 1',
                            '  * item 2'])
        check(self, expected, actual)

    def test_single_list_with_multiple_items_with_other_indentation_level(self):
        expected = [lists.HeaderContentList([_list_item('item 1'),
                                             _list_item('item 2')],
                                            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['    * item 1',
                            '    * item 2'])
        check(self, expected, actual)

    def test_single_list_with_multiple_items_separated_by_empty_line(self):
        expected = [lists.HeaderContentList([_list_item('item 1'),
                                             _list_item('item 2')],
                                            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  * item 1',
                            '',
                            '  * item 2'])
        check(self, expected, actual)

    def test_spaces_around_header_string_SHOULD_not_appear_in_header(self):
        expected = [lists.HeaderContentList([_list_item('item 1'),
                                             _list_item('item 2')],
                                            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  *   item 1',
                            '  *  item 2   '])
        check(self, expected, actual)

    def test_single_list_with_multiple_items_with_initial_blank_lines(self):
        expected = [lists.HeaderContentList([_list_item('item 1'),
                                             _list_item('item 2')],
                                            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['',
                            '  * item 1',
                            '  * item 2'])
        check(self, expected, actual)

    def test_single_list_with_multiple_items_with_trailing_blank_lines(self):
        expected = [lists.HeaderContentList([_list_item('item 1'),
                                             _list_item('item 2')],
                                            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  * item 1',
                            '  * item 2',
                            ''])
        check(self, expected, actual)

    def test_list_in_middle_of_paragraphs(self):
        expected = [
            Paragraph([StringText('first paragraph')]),
            lists.HeaderContentList([_list_item('item 1'),
                                     _list_item('item 2')],
                                    self.EXPECTED_LIST_FORMAT),
            Paragraph([StringText('last paragraph')]),
        ]
        actual = sut.parse(['first paragraph',
                            '',
                            '',
                            '  * item 1',
                            '  * item 2',
                            '',
                            '',
                            'last paragraph'])
        check(self, expected, actual)

    def test_list_with_item_contents_in_middle_of_paragraphs(self):
        expected = [
            Paragraph([StringText('first paragraph')]),
            lists.HeaderContentList([
                _list_item('item 1',
                           [
                               Paragraph([StringText('item contents paragraph')]),
                           ]),
            ],
                self.EXPECTED_LIST_FORMAT),
            Paragraph([StringText('last paragraph')]),
        ]
        actual = sut.parse(['first paragraph',
                            '',
                            '',
                            '  * item 1',
                            '',
                            '    item contents paragraph',
                            '',
                            '',
                            'last paragraph'])
        check(self, expected, actual)

    def test_list_with_item_multiple_paragraphs_contents_in_middle_of_paragraphs(self):
        expected = [
            Paragraph([StringText('first paragraph')]),
            lists.HeaderContentList([
                _list_item('item 1',
                           [
                               Paragraph([StringText('line 1 in contents paragraph 1'),
                                          StringText('line 2 in contents paragraph 1')]),
                               Paragraph([StringText('line 1 in contents paragraph 2')]),
                           ]),
            ],
                self.EXPECTED_LIST_FORMAT),
            Paragraph([StringText('last paragraph')]),
        ]
        actual = sut.parse(['first paragraph',
                            '',
                            '',
                            '  * item 1',
                            '',
                            '    line 1 in contents paragraph 1',
                            '',
                            '    line 2 in contents paragraph 1',
                            '',
                            '',
                            '    line 1 in contents paragraph 2',
                            '',
                            '',
                            'last paragraph'])
        check(self, expected, actual)

    def test_list_with_item_multiple_paragraphs_contents_before_other_item(self):
        expected = [
            lists.HeaderContentList([
                _list_item('item 1',
                           [
                               Paragraph([StringText('item 1 contents paragraph 1')]),
                               Paragraph([StringText('item 1 contents paragraph 2')]),
                           ]),
                _list_item('item 2',
                           [
                               Paragraph([StringText('item 2 contents paragraph 1')]),
                           ]),
            ],
                self.EXPECTED_LIST_FORMAT),
            Paragraph([StringText('last paragraph')]),
        ]
        actual = sut.parse(['  * item 1',
                            '',
                            '    item 1 contents paragraph 1',
                            '',
                            '',
                            '    item 1 contents paragraph 2',
                            '',
                            '  * item 2',
                            '',
                            '    item 2 contents paragraph 1',
                            '',
                            'last paragraph'])
        check(self, expected, actual)

    def test_nested_lists(self):
        expected = [
            lists.HeaderContentList([
                _list_item('item 1',
                           [
                               Paragraph([StringText('item 1 contents paragraph')]),
                               lists.HeaderContentList(
                                   [
                                       _list_item('item 1/1',
                                                  [
                                                      Paragraph([StringText('item 1/1 contents paragraph')]),
                                                  ]),
                                       _list_item('item 1/2',
                                                  []),
                                   ],
                                   self.EXPECTED_LIST_FORMAT),
                           ]),
                _list_item('item 2',
                           []),
            ],
                self.EXPECTED_LIST_FORMAT),
        ]
        actual = sut.parse(['  * item 1',
                            '',
                            '    item 1 contents paragraph',
                            '',
                            '',
                            '      * item 1/1',
                            '',
                            '        item 1/1 contents paragraph',
                            '',
                            '      * item 1/2',
                            '',
                            '  * item 2',
                            ])
        check(self, expected, actual)
Example #21
0
 def _list_format(self, list_type: lists.ListType) -> lists.Format:
     return lists.Format(
         list_type,
         custom_indent_spaces=self.list_settings.custom_indent_spaces,
         custom_separations=self.list_settings.custom_separations)
 def list_for_items(items):
     return lists.HeaderContentList(
         items,
         lists.Format(
             lists.ListType.VARIABLE_LIST,
             custom_separations=docs.SEPARATION_OF_HEADER_AND_CONTENTS))
Example #23
0
def simple_header_only_list(
        str_or_text_headers: Iterable[StrOrText],
        list_type: lists.ListType) -> lists.HeaderContentList:
    items = [header_only_item(header) for header in str_or_text_headers]
    return lists.HeaderContentList(items, lists.Format(list_type))
Example #24
0
def simple_list(items: Iterable[lists.HeaderContentListItem],
                list_type: lists.ListType) -> lists.HeaderContentList:
    return lists.HeaderContentList(items, lists.Format(list_type))