def test(self): # ARRANGE # root_element_to_mutate = Element('root') section_header_text = 'section header' article_header_text = 'article header' sc = SectionContents([], [ Section(StringText(section_header_text), SectionContents([], [])), Article(StringText(article_header_text), ArticleContents([], SectionContents([], []))), ]) expected_element = element( root_element_to_mutate.tag, children=[ element('section', children=[ _header_w_h(section_header_text, 'h3'), ]), element('article', children=[ _header_w_h(article_header_text), ]), ]) # ACT # ret_val = TEST_RENDERER.render_section_contents( sut.Environment(2), root_element_to_mutate, sc) # ASSERT # assert_contents_and_that_last_child_is_returned( expected_element, root_element_to_mutate, ret_val, self)
def test(self): # ARRANGE # root_element_to_mutate = Element('root') header_1_text = 'header 1' header_2_text = 'header 2' sc = SectionContents([], [ Section(StringText(header_1_text), SectionContents([], [])), Section(StringText(header_2_text), SectionContents([], [])), ]) expected_element = element(root_element_to_mutate.tag, children=[ element('section', children=[ _header_w_h(header_1_text), ]), element('section', children=[ _header_w_h(header_2_text), ]), ]) # ACT # ret_val = TEST_RENDERER.render_section_contents( sut.Environment(0), root_element_to_mutate, sc) # ASSERT # assert_contents_and_that_last_child_is_returned( expected_element, root_element_to_mutate, ret_val, self)
def test_complex_structure_with_reset_of_section_level(self): # ARRANGE # s = Article( StringText('article header'), ArticleContents( [para('para in abstract')], SectionContents([para('initial para in contents')], [ Section( StringText('header 1/1'), SectionContents([para('para 1/1')], [ Section(StringText('header 1/1/1'), SectionContents([para('para 1/1/1')], [])) ])) ]))) for section_level in range(3): with self.subTest('section level = ' + str(section_level)): root = Element('root') environment = sut.Environment(section_level) # ACT # ret_val = TEST_RENDERER.render_section_item( environment, root, s) # ASSERT # expected_element = element( 'root', children=[ element('article', children=[ element( 'header', children=[ element('h1', text='article header'), element('p', text='para in abstract'), ], ), element('p', text='initial para in contents'), element( 'section', children=[ _header_w_h('header 1/1'), element('p', text='para 1/1'), element( 'section', children=[ _header_w_h( 'header 1/1/1', 'h2'), element('p', text='para 1/1/1'), ]) ]) ]) ]) assert_contents_and_that_last_child_is_returned( expected_element, root, ret_val, self)
def __init__(self, singular_name: str, act_phase_contents: SectionContents = SectionContents([]), act_phase_contents_syntax: SectionContents = SectionContents( []), see_also_specific: list = None): super().__init__( name_and_ref_target(singular_name, 'single line description str')) self._act_phase_contents = act_phase_contents self._act_phase_contents_syntax = act_phase_contents_syntax self.__see_also_specific = [] if see_also_specific is None else see_also_specific
def test_section_content_indent__for_nested_sections(self): paragraph_item_formatter = paragraph_item.Formatter( CROSS_REF_TITLE_ONLY_TEXT_FORMATTER, paragraph_item.Wrapper(page_width=100), num_item_separator_lines=0) content_indent = ' ' formatter = sut.Formatter( paragraph_item_formatter, section_content_indent_str=content_indent, separation=sut.Separation( between_sections=1, between_header_and_content=2, between_initial_paragraphs_and_sub_sections=3)) header = text('Section 1') contents = SectionContents([], [ Section( text('Section 1.1'), SectionContents( [single_text_para('paragraph in section 1.1')], [ Section( text('Section 1.1.1'), SectionContents([ single_text_para('paragraph in section 1.1.1') ], [])) ])) ]) cases = [ ('section', Section(header, contents)), ('article', Article(header, ArticleContents([], contents))), ] for test_case_name, section_item in cases: with self.subTest(test_case_name): # ACT # actual = formatter.format_section_item(section_item) # ASSERT # self.assertEqual([ 'Section 1', BLANK_LINE, BLANK_LINE, (1 * content_indent) + 'Section 1.1', BLANK_LINE, BLANK_LINE, (2 * content_indent) + 'paragraph in section 1.1', BLANK_LINE, BLANK_LINE, BLANK_LINE, (2 * content_indent) + 'Section 1.1.1', BLANK_LINE, BLANK_LINE, (3 * content_indent) + 'paragraph in section 1.1.1', ], actual)
def notes(self) -> SectionContents: paragraphs = self._notes__specific() if self._is_in_assert_phase: paragraphs += self._tp.fnap(_NOT_AN_ASSERTION_IN_ASSERT_PHASE) return SectionContents(paragraphs)
def test_separation_between_header_and_content__with_both_initial_paragraphs_and_sub_sections( self): paragraph_item_formatter = paragraph_item.Formatter( CROSS_REF_TITLE_ONLY_TEXT_FORMATTER, paragraph_item.Wrapper(page_width=100), num_item_separator_lines=0) formatter = sut.Formatter( paragraph_item_formatter, sut.Separation(between_sections=1, between_header_and_content=2, between_initial_paragraphs_and_sub_sections=3)) header_string = 'Section Header' contents = SectionContents([single_text_para('initial paragraph')], [empty_section('Content Section Header')]) cases = [ ('section', Section(text(header_string), contents)), ('article', Article(text(header_string), ArticleContents([], contents))), ] for test_case_name, section_item in cases: with self.subTest(test_case_name): # ACT # actual = formatter.format_section_item(section_item) # ASSERT # self.assertEqual([ header_string, BLANK_LINE, BLANK_LINE, 'initial paragraph', BLANK_LINE, BLANK_LINE, BLANK_LINE, 'Content Section Header', ], actual)
def test_multiple_and_nested_sub_sections(self): paragraph_item_formatter = paragraph_item.Formatter( CROSS_REF_TITLE_ONLY_TEXT_FORMATTER, paragraph_item.Wrapper(page_width=100), num_item_separator_lines=0) formatter = sut.Formatter( paragraph_item_formatter, sut.Separation(between_sections=1, between_header_and_content=2, between_initial_paragraphs_and_sub_sections=3)) section_contents = SectionContents([], [ empty_section('Section 1'), sut.Section( text('Section 2'), sut.SectionContents([], [empty_article('Section 2.1')])) ]) actual = formatter.format_section_contents(section_contents) self.assertEqual([ 'Section 1', BLANK_LINE, 'Section 2', BLANK_LINE, BLANK_LINE, 'Section 2.1', ], actual)
def purpose(self) -> DescriptionWithSubSections: tp = TextParser({ 'cd_concept': formatting.concept(self.singular_name()), 'CD': self.acronym(), 'program_name': formatting.program_name(program_info.PROGRAM_NAME), 'sds_concept': formatting.concept_(concepts.SDS_CONCEPT_INFO), 'act_sub_dir': SUB_DIRECTORY__ACT + '/', 'path_type': formatting.symbol_type_(types.PATH_TYPE_INFO), 'act_phase': phase_names.ACT.emphasis, 'rel_cd_option': formatting.cli_option(path.REL_CWD_OPTION), 'cd_instruction': InstructionName(instruction_names.CHANGE_DIR_INSTRUCTION_NAME), 'def_instruction': InstructionName(instruction_names.SYMBOL_DEFINITION_INSTRUCTION_NAME), 'instruction': concepts.INSTRUCTION_CONCEPT_INFO.name, 'os_process': misc_texts.OS_PROCESS_NAME, }) return DescriptionWithSubSections( self.single_line_description(), SectionContents( tp.fnap(_INITIAL_PARAGRAPHS), [ docs.section( tp.text(_USING_THE_CD_HEADER), tp.fnap(_USING_THE_CD) ), docs.section( tp.text(_DESCRIPTION_DEF_INSTRUCTION_HEADER), cd_instruction_section_on_def_instruction() ), ] ))
def test_article_separation_between_header_and_content(self): # ARRANGE # paragraph_item_formatter = paragraph_item.Formatter( CROSS_REF_TITLE_ONLY_TEXT_FORMATTER, paragraph_item.Wrapper(page_width=100), num_item_separator_lines=0) formatter = sut.Formatter( paragraph_item_formatter, sut.Separation(between_sections=1, between_header_and_content=2, between_initial_paragraphs_and_sub_sections=3)) header = text('Article Header') cases = [ ('single abstract para / no contents para', Article( header, ArticleContents([single_text_para('abstract paragraph')], empty_section_contents())), [ 'Article Header', BLANK_LINE, BLANK_LINE, 'abstract paragraph', ]), ('single abstract para / single contents para', Article( header, ArticleContents([single_text_para('abstract paragraph')], single_para_contents('contents paragraph'))), [ 'Article Header', BLANK_LINE, BLANK_LINE, 'abstract paragraph', 'contents paragraph', ]), ('single abstract para / single contents para', Article( header, ArticleContents( [single_text_para('abstract paragraph')], SectionContents([], [empty_section('Sub Section Header')]))), [ 'Article Header', BLANK_LINE, BLANK_LINE, 'abstract paragraph', BLANK_LINE, BLANK_LINE, BLANK_LINE, 'Sub Section Header', ]), ] for test_case_name, article, expected_lines in cases: with self.subTest(test_case_name): # ACT # actual = formatter.format_section_item(article) # ASSERT # self.assertEqual(expected_lines, actual)
def purpose(self) -> DescriptionWithSubSections: rest_paragraphs = self._parser.fnap(_REST_DESCRIPTION) sub_sections = [ docs.section('Definition', self._parser.fnap(_DEFINITION)), docs.section('Reference', self._reference_paragraphs()), ] return DescriptionWithSubSections( self.single_line_description(), SectionContents(rest_paragraphs, sub_sections))
def test_section_content_indent_w_literal_layout_indent(self): ll_indent = 'LLI ' content_indent = 'CI ' paragraph_item_formatter = paragraph_item.Formatter( CROSS_REF_TITLE_ONLY_TEXT_FORMATTER, paragraph_item.Wrapper(page_width=100), num_item_separator_lines=0, literal_layout_indent=ll_indent) formatter = sut.Formatter( paragraph_item_formatter, section_content_indent_str=content_indent, separation=sut.Separation( between_sections=1, between_header_and_content=2, between_initial_paragraphs_and_sub_sections=3)) header = text('Section Header') contents = SectionContents([LiteralLayout('literal layout 1')], [ Section(text('Sub Section Header'), SectionContents([LiteralLayout('literal layout 2')])) ]) cases = [ ('section', Section(header, contents)), ('article', Article(header, ArticleContents([], contents))), ] for test_case_name, section_item in cases: with self.subTest(test_case_name): # ACT # actual = formatter.format_section_item(section_item) # ASSERT # self.assertEqual([ 'Section Header', BLANK_LINE, BLANK_LINE, content_indent + ll_indent + 'literal layout 1', BLANK_LINE, BLANK_LINE, BLANK_LINE, content_indent + 'Sub Section Header', BLANK_LINE, BLANK_LINE, content_indent * 2 + ll_indent + 'literal layout 2', ], actual)
def purpose(self) -> DescriptionWithSubSections: rest_paragraphs = self._parser.fnap(_REST__BEFORE_CATEGORY_LIST) rest_paragraphs.append(_types_categories_list(self._parser)) rest_paragraphs += (self._parser.fnap(_REST__AFTER_CATEGORY_LIST)) sub_sections = [ docs.section(self._parser.text('Summary of {type:s}'), [_types_list()]) ] return DescriptionWithSubSections( self.single_line_description(), SectionContents(rest_paragraphs, sub_sections))
def test_empty(self): # ARRANGE # root = Element('root') sc = SectionContents([], []) # ACT # ret_val = TEST_RENDERER.render_section_contents( sut.Environment(0), root, sc) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root />', xml_string) self.assertIs(root, ret_val)
def test_single_sub_section_with_initial_paras_everywhere(self): # ARRANGE # root_element_to_mutate = Element('root') para_0_text = 'para 0' header_1_text = 'header 1' para_1_text = 'para 1' header_1_1_text = 'header 1/1' para_2_text = 'para 2' sc = SectionContents([para(para_0_text)], [ Section( StringText(header_1_text), SectionContents([para(para_1_text)], [ Section(StringText(header_1_1_text), SectionContents([para(para_2_text)], [])) ])) ]) expected_element = element( root_element_to_mutate.tag, children=[ element('p', text=para_0_text), element('section', children=[ _header_w_h(header_1_text), element('p', text=para_1_text), element('section', children=[ _header_w_h(header_1_1_text, 'h2'), element('p', text=para_2_text), ]) ]), ]) # ACT # ret_val = TEST_RENDERER.render_section_contents( sut.Environment(0), root_element_to_mutate, sc) # ASSERT # assert_contents_and_that_last_child_is_returned( expected_element, root_element_to_mutate, ret_val, self)
def syntax_element_documentation( type_category: Optional[TypeCategory], name_and_cross_ref_target: SingularNameAndCrossReferenceId, main_description_rest: Sequence[ParagraphItem], main_description_rest_sub_sections: Sequence[SectionItem], invokation_variants: List[InvokationVariant], syntax_element_descriptions: List[SyntaxElementDescription], see_also_targets: List[SeeAlsoTarget], notes: SectionContents = SectionContents.empty(), ) -> SyntaxElementDocumentation: return SyntaxElementDocumentationWithConstantValues( type_category, name_and_cross_ref_target, main_description_rest, main_description_rest_sub_sections, notes, invokation_variants, syntax_element_descriptions, see_also_targets)
def test_single_paragraph_item(self): # ARRANGE # root = Element('root') paragraph_text = 'the only para' sc = SectionContents([para(paragraph_text)], []) expected_element = element( root.tag, children=[element('p', text=paragraph_text)]) # ACT # ret_val = TEST_RENDERER.render_section_contents( sut.Environment(0), root, sc) # ASSERT # assert_contents_and_that_last_child_is_returned( expected_element, root, ret_val, self)
def test_section_with_single_initial_para(self): # ARRANGE # root_element_to_mutate = Element('root') section_header_text = 'section header' initial_para_text = 'initial para' sc = SectionContents([], [ Section(StringText(section_header_text), SectionContents([para(initial_para_text)], [])) ]) expected_element = element( root_element_to_mutate.tag, children=[ element('section', children=[ _header_w_h(section_header_text), element('p', text=initial_para_text) ]) ]) # ACT # ret_val = TEST_RENDERER.render_section_contents( sut.Environment(0), root_element_to_mutate, sc) # ASSERT # assert_contents_and_that_last_child_is_returned( expected_element, root_element_to_mutate, ret_val, self)
def test_multiple_paragraph_items(self): # ARRANGE # root_element_to_mutate = Element('root') paragraph_1_text = 'para 1' paragraph_2_text = 'para 2' sc = SectionContents([para(paragraph_1_text), para(paragraph_2_text)], []) expected_element = element(root_element_to_mutate.tag, children=[ element('p', text=paragraph_1_text), element('p', text=paragraph_2_text), ]) # ACT # ret_val = TEST_RENDERER.render_section_contents( sut.Environment(0), root_element_to_mutate, sc) # ASSERT # assert_contents_and_that_last_child_is_returned( expected_element, root_element_to_mutate, ret_val, self)
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_initial_paragraph_and_single_sub_section(self): paragraph_item_formatter = paragraph_item.Formatter( CROSS_REF_TITLE_ONLY_TEXT_FORMATTER, paragraph_item.Wrapper(page_width=100), num_item_separator_lines=0) formatter = sut.Formatter( paragraph_item_formatter, sut.Separation(between_sections=1, between_header_and_content=2, between_initial_paragraphs_and_sub_sections=3)) section_contents = SectionContents( [single_text_para('initial paragraph')], [empty_section('Section Header')]) actual = formatter.format_section_contents(section_contents) self.assertEqual([ 'initial paragraph', BLANK_LINE, BLANK_LINE, BLANK_LINE, 'Section Header', ], actual)