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))
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 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))
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_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_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_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_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 _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))
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)
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)
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))
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))
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))
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)
def parse_list_from_first_item_line( self, item_line_prefix: str, list_type: lists.ListType) -> lists.HeaderContentList: items = [ self.parse_list_item_from_item_line(self.consume_current_line(), item_line_prefix) ] while self.has_more_lines() and self.lines[0].startswith( item_line_prefix): next_item = self.parse_list_item_from_item_line( self.consume_current_line(), item_line_prefix) items.append(next_item) return lists.HeaderContentList(items, self._list_format(list_type))
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))
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 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)
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))
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 _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))
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_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)
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_as_last_line(self): expected = [lists.HeaderContentList([_list_item('item')], self.EXPECTED_LIST_FORMAT)] actual = sut.parse([' 1. item']) check(self, expected, actual)
def list_for_items(items): return lists.HeaderContentList( items, lists.Format( lists.ListType.VARIABLE_LIST, custom_separations=docs.SEPARATION_OF_HEADER_AND_CONTENTS))
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))
def simple_list(items: Iterable[lists.HeaderContentListItem], list_type: lists.ListType) -> lists.HeaderContentList: return lists.HeaderContentList(items, lists.Format(list_type))