def runTest(self): # ARRANGE # root = Element('root') table = Table(TableFormat(first_row_is_header=True), [ [text_cell('ignored'), cell([para('ignored'), para('ignored')])], [text_cell('ignored'), cell([para('ignored'), para('ignored')])], ]) # ACT # ret_val = sut.render(ConstantPRenderer('para text'), root, table) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<table>' '<tr>' '<th>para text</th>' '<th><p>para text</p><p>para text</p></th>' '</tr>' '<tr>' '<td>para text</td>' '<td><p>para text</p><p>para text</p></td>' '</tr>' '</table>' '</root>', xml_string) self.assertIs(list(root)[0], ret_val)
def test_simple_document(self): # ARRANGE # section_contents = SectionContents([para('para 0')], [ Section(StringText('header 1'), SectionContents([para('para 1'), para('')], [])) ]) document_setup = sut.DocumentSetup('page title') # ACT # output_file = io.StringIO() DOCUMENT_RENDERER.apply(output_file, document_setup, section_contents) actual = output_file.getvalue() # ASSERT # expected = (DOCTYPE_XHTML1_0 + '<html>' '<head>' '<title>page title</title>' '</head>' '<body>' '<p>para 0</p>' '<section>' '<header>' '<h1>header 1</h1>' '</header>' '<p>para 1</p>' '<p></p>' '</section>' '</body>' '</html>') self.assertEqual(expected, actual)
def runTest(self): # ARRANGE # root = Element('root') table = Table(TableFormat(first_row_is_header=True), [ [text_cell('ignored'), cell([para('ignored'), para('ignored')])], [text_cell('ignored'), cell([para('ignored'), para('ignored')])], ]) # ACT # ret_val = sut.render(ConstantPRenderer('para text'), root, table) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual( '<root>' '<table>' '<tr>' '<th>para text</th>' '<th><p>para text</p><p>para text</p></th>' '</tr>' '<tr>' '<td>para text</td>' '<td><p>para text</p><p>para text</p></td>' '</tr>' '</table>' '</root>', xml_string) self.assertIs(list(root)[0], ret_val)
def test_simple_document(self): # ARRANGE # section_contents = SectionContents( [para('para 0')], [Section(StringText('header 1'), SectionContents([para('para 1'), para('')], []))]) document_setup = sut.DocumentSetup('page title') # ACT # output_file = io.StringIO() DOCUMENT_RENDERER.apply(output_file, document_setup, section_contents) actual = output_file.getvalue() # ASSERT # expected = (DOCTYPE_XHTML1_0 + '<html>' '<head>' '<title>page title</title>' '</head>' '<body>' '<p>para 0</p>' '<section>' '<header>' '<h1>header 1</h1>' '</header>' '<p>para 1</p>' '<p></p>' '</section>' '</body>' '</html>') self.assertEqual(expected, actual)
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 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 # assert_contents_and_that_last_child_is_returned( '<root>' '<article>' '<header>' '<h1>article header</h1>' '<p>para in abstract</p>' '</header>' '<p>initial para in contents</p>' '<section>' '<header>' '<h1>header 1/1</h1>' '</header>' '<p>para 1/1</p>' '<section>' '<header>' '<h2>header 1/1/1</h2>' '</header>' '<p>para 1/1/1</p>' '</section>' '</section>' '</article>' '</root>' , root, ret_val, self)
def singe_exit_value_display(exit_value: ExitValue) -> ParagraphItem: return first_column_is_header_table([ [ cell([para(misc_texts.EXIT_CODE_TITLE)]), cell([para(str(exit_value.exit_code))]), ], [ cell([para(misc_texts.EXIT_IDENTIFIER_TITLE)]), cell([para(exit_value_text(exit_value))]), ], ])
def _dir_item(self, x: _DirInfo) -> HeaderContentListItem: def prop_row(header: str, value_str_or_text) -> List[docs.TableCell]: return [ docs.text_cell(header), docs.text_cell(value_str_or_text), ] from exactly_lib.tcfs.relative_path_options import REL_HDS_OPTIONS_MAP properties_table = docs.first_column_is_header_table([ prop_row('Default value', x.default_value_description), prop_row( concepts.CONFIGURATION_PARAMETER_CONCEPT_INFO.singular_name. capitalize(), x.conf_param.configuration_parameter_name_text), prop_row('Set by instruction', instruction_name_text(x.instruction_name)), prop_row( BUILTIN_SYMBOL_ENTITY_TYPE_NAMES.name.singular.capitalize(), REL_HDS_OPTIONS_MAP[ x.relativity_option_type].directory_symbol_name_text), prop_row( 'Path relativity option', REL_HDS_OPTIONS_MAP[ x.relativity_option_type].option_name_text), ]) paras = [ docs.para(x.conf_param.single_line_description_str), properties_table, ] return docs.list_item(self._tp.text(x.item_name), paras)
def instruction_set_list_item( description: InstructionDocumentation, name_2_name_text_fun: Callable[[str], docs.Text] ) -> lists.HeaderContentListItem: description_para = docs.para(description.single_line_description()) return docs.list_item(name_2_name_text_fun(description.instruction_name()), [description_para])
def test_simple_document(self): # ARRANGE # section_contents = SectionContents([para('para in contents')], []) populator = utils.ComplexElementPopulator([ SingleParaPopulator('para from pop 1'), SingleParaPopulator('para from pop 2') ]) document_setup = sut.DocumentSetup('page title', footer_populator=populator) # ACT # output_file = io.StringIO() DOCUMENT_RENDERER.apply(output_file, document_setup, section_contents) actual = output_file.getvalue() # ASSERT # expected = (DOCTYPE_XHTML1_0 + '<html>' '<head>' '<title>page title</title>' '</head>' '<body>' '<p>para in contents</p>' '<p>para from pop 1</p>' '<p>para from pop 2</p>' '</body>' '</html>') self.assertEqual(expected, actual)
def test_footer_populator(self): # ARRANGE # section_contents = SectionContents( [para('main contents')], []) footer_populator = SingleParaPopulator('footer contents') document_setup = sut.DocumentSetup('page title', footer_populator=footer_populator) # ACT # output_file = io.StringIO() DOCUMENT_RENDERER.apply(output_file, document_setup, section_contents) actual = output_file.getvalue() # ASSERT # expected = (DOCTYPE_XHTML1_0 + '<html>' '<head>' '<title>page title</title>' '</head>' '<body>' '<p>main contents</p>' '<p>footer contents</p>' '</body>' '</html>') self.assertEqual(expected, actual)
def _dir_item(self, x: _DirInfo) -> HeaderContentListItem: def prop_row(header: str, value_str_or_text) -> List[docs.TableCell]: return [docs.text_cell(header), docs.text_cell(value_str_or_text), ] from exactly_lib.test_case_file_structure.relative_path_options import REL_HOME_OPTIONS_MAP properties_table = docs.first_column_is_header_table( [ prop_row('Default value', x.default_value_description), prop_row(concepts.CONFIGURATION_PARAMETER_CONCEPT_INFO.singular_name.capitalize(), x.conf_param.configuration_parameter_name_text), prop_row('Set by instruction', instruction_name_text(x.instruction_name)), prop_row('Variable name', REL_HOME_OPTIONS_MAP[x.relativity_option_type].directory_variable_name_text), prop_row('Relativity option', REL_HOME_OPTIONS_MAP[x.relativity_option_type].option_name_text), ] ) paras = [ docs.para(x.conf_param.single_line_description_str), properties_table, ] return docs.list_item(self._tp.text(x.item_name), paras)
def _synopsis_list_item(self, synopsis: Synopsis) -> lists.HeaderContentListItem: header = self.cmd_line_syntax_renderer.apply(synopsis.command_line) content_paragraph_items = [] if synopsis.maybe_single_line_description: content_paragraph_items.append(docs.para(synopsis.maybe_single_line_description)) content_paragraph_items += synopsis.paragraphs return docs.list_item(header, content_paragraph_items)
def test_section_with_single_initial_para(self): # ARRANGE # root = Element('root') sc = SectionContents([], [Section(StringText('section header'), SectionContents([para('initial para')], []))]) # ACT # ret_val = TEST_RENDERER.render_section_contents(sut.Environment(0), root, sc) # ASSERT # assert_contents_and_that_last_child_is_returned( '<root>' '<section>' '<header>' '<h1>section header</h1>' '</header>' '<p>initial para</p>' '</section>' '</root>' , root, ret_val, self)
def _arg_description_list_item_contents(self, argument: DescribedArgument) -> List[docs.ParagraphItem]: ret_val = [] ret_val.extend(argument.description) if argument.see_also_items: ret_val.append(docs.para(SEE_ALSO_TITLE)) ret_val.append(see_also_items_paragraph(argument.see_also_items, self.environment)) return ret_val
def test_simple_document(self): # ARRANGE # section_contents = SectionContents( [para('para in contents')], []) populator = utils.ComplexElementPopulator([SingleParaPopulator('para from pop 1'), SingleParaPopulator('para from pop 2')]) document_setup = sut.DocumentSetup('page title', footer_populator=populator) # ACT # output_file = io.StringIO() DOCUMENT_RENDERER.apply(output_file, document_setup, section_contents) actual = output_file.getvalue() # ASSERT # expected = (DOCTYPE_XHTML1_0 + '<html>' '<head>' '<title>page title</title>' '</head>' '<body>' '<p>para in contents</p>' '<p>para from pop 1</p>' '<p>para from pop 2</p>' '</body>' '</html>') self.assertEqual(expected, actual)
def test_hierarchy_with_sub_sections(self): # ARRANGE # target_factory = TargetInfoFactoryTestImpl(['target_component']) expected_section_contents_object1 = doc.empty_section_contents() expected_section_contents_object2 = docs.section_contents(docs.paras('testing testing')) expected_root_initial_para = docs.para('root initial paras') expected_root_initial_paras = [expected_root_initial_para] root_header = StringText('root header') sub_section_header_1 = 'sub1' sub_section_header_2 = 'sub2' sub_section_local_target_1 = 'sub-target1' sub_section_local_target_2 = 'sub-target2' object_to_test = sut.hierarchy( root_header, paragraphs.constant(expected_root_initial_paras), [sut.child(sub_section_local_target_1, sut.leaf(sub_section_header_1, section_contents(expected_section_contents_object1))), sut.child(sub_section_local_target_2, sut.leaf(sub_section_header_2, section_contents(expected_section_contents_object2))) ]) # EXPECTATION # expected_root_target_info = target_factory.root(root_header) sub1_target = target_factory.sub(sub_section_header_1, sub_section_local_target_1) sub2_target = target_factory.sub(sub_section_header_2, sub_section_local_target_2) target_info_node_assertion = equals_target_info_node( TargetInfoNode(expected_root_target_info, [ target_info_leaf(sub1_target), target_info_leaf(sub2_target), ]), mk_equals_cross_ref_id=equals_custom_cross_ref_test_impl) section_assertion2 = section_matches( target=equals_custom_cross_ref_test_impl(expected_root_target_info.target), header=asrt_para.equals_text(expected_root_target_info.presentation_text), contents=section_contents_matches( initial_paragraphs=asrt.matches_sequence([asrt.Is(expected_root_initial_para)]), sections=asrt.matches_sequence([ section_matches( target=equals_custom_cross_ref_test_impl(sub1_target.target), header=asrt_para.equals_text(sub1_target.presentation_text), contents=asrt.Is(expected_section_contents_object1)), section_matches( target=equals_custom_cross_ref_test_impl(sub2_target.target), header=asrt_para.equals_text(sub2_target.presentation_text), contents=asrt.Is(expected_section_contents_object2)), ]))) # ACT & ASSERT # self._act_and_assert(object_to_test, target_factory, target_info_node_assertion, section_assertion2)
def test(self): cases = [ Case( 'test_singleton_element_without_contents', items= [HeaderContentListItem(text('header'))], expected= '<root>' '<dl>' '<dt>header</dt>' '</dl>' '</root>' ), Case( 'test_singleton_element_with_multiple_content_paragraphs', items= [HeaderContentListItem(text('header'), [para('ignored'), para('ignored')])], expected= '<root>' '<dl>' '<dt>header</dt>' '<dd>' '<p>every para text</p>' '<p>every para text</p>' '</dd>' '</dl>' '</root>' ), ] for case in cases: with self.subTest(case.name): root = Element('root') the_list = HeaderContentList(case.items, Format(ListType.VARIABLE_LIST)) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), ConstantPRenderer('every para text'), root, the_list) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual(case.expected, xml_string) self.assertIs(list(root)[0], ret_val)
def test_multiple_paragraph_items(self): # ARRANGE # root = Element('root') sc = SectionContents([para('para 1'), para('para 2')], []) # ACT # ret_val = TEST_RENDERER.render_section_contents(sut.Environment(0), root, sc) # ASSERT # assert_contents_and_that_last_child_is_returned( '<root>' '<p>para 1</p>' '<p>para 2</p>' '</root>' , root, ret_val, self)
def _dir_structure_item(self, dir_structure: SingularAndPluralNameAndCrossReferenceId, tc_dir_infos: List[TcDirInfo], ) -> lists.HeaderContentListItem: contents = [ docs.para(dir_structure.single_line_description), self._dirs_list(tc_dir_infos) ] return docs.list_item(dir_structure.singular_name.capitalize(), contents)
def _arg_description_list_item_contents( self, argument: DescribedArgument) -> List[docs.ParagraphItem]: ret_val = [] ret_val.extend(argument.description) if argument.see_also_items: ret_val.append(docs.para(SEE_ALSO_TITLE)) ret_val.append( see_also_items_paragraph(argument.see_also_items, self.environment)) return ret_val
def test_concept_with_complex_description(self): # ARRANGE # concept = PlainConceptTestImpl(a_name(Name('name', 'names')), Description(text('single line name'), [para('rest paragraph')])) renderer = sut.IndividualConceptConstructor(concept) # ACT # actual = renderer.apply(CONSTRUCTION_ENVIRONMENT) # ASSERT # struct_check.is_article_contents.apply(self, actual)
def _environment_variables_items(self) -> List[lists.HeaderContentListItem]: eei = self.doc.execution_environment_info() paragraphs = [] paragraphs += eei.environment_variables_prologue if eei.environment_variables: paragraphs.extend([docs.para('The following environment variables are set:'), self._environment_variables_list(eei.environment_variables)]) if self.doc.name.plain == ACT_PHASE_NAME: # FIXME Remove setting of env vars for the act phase. paragraphs.append(docs.para('NOTE: In future versions, ' 'these environment variables will not be available!')) if paragraphs: list_item = docs.list_item( '{ev:s/u}'.format(ev=concepts.ENVIRONMENT_VARIABLE_CONCEPT_INFO.name), paragraphs ) return [list_item] else: return []
def test_concept_with_complex_description(self): # ARRANGE # concept = PlainConceptTestImpl( a_name(Name('name', 'names')), Description(text('single line name'), [para('rest paragraph')])) renderer = sut.IndividualConceptConstructor(concept) # ACT # actual = renderer.apply(CONSTRUCTION_ENVIRONMENT) # ASSERT # struct_check.is_article_contents.apply(self, actual)
def _synopsis_list_items( self, synopsis: Synopsis) -> List[lists.HeaderContentListItem]: headers = list( map(self.cmd_line_syntax_renderer.apply, synopsis.command_lines)) content_paragraph_items = [] if synopsis.maybe_single_line_description: content_paragraph_items.append( docs.para(synopsis.maybe_single_line_description)) content_paragraph_items += synopsis.paragraphs return ([docs.list_item(header) for header in headers[:-1]] + [docs.list_item(headers[-1], content_paragraph_items)])
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_conf_param_with_complex_description(self): # ARRANGE # concept = ConfigurationParameterTestImpl('conf_param_name', Description(text('single line name'), [para('rest paragraph')]), 'default value') constructor = sut.IndividualConfParamConstructor(concept) # ACT # actual = constructor.apply(CONSTRUCTION_ENVIRONMENT) # ASSERT # struct_check.is_article_contents.apply(self, actual)
def test_conf_param_with_complex_description(self): # ARRANGE # concept = ConfigurationParameterTestImpl( 'conf_param_name', Description(text('single line name'), [para('rest paragraph')]), 'default value') constructor = sut.IndividualConfParamConstructor(concept) # ACT # actual = constructor.apply(CONSTRUCTION_ENVIRONMENT) # ASSERT # struct_check.is_article_contents.apply(self, actual)
def apply(self, environment: ConstructionEnvironment) -> doc.ArticleContents: initial_paragraphs = [] invokation_variants = self.syntax_element.invokation_variants() if len(invokation_variants) > 1: initial_paragraphs.append(docs.para(doc_format.text_as_header('Forms:'))) initial_paragraphs += invokation_variants_paragraphs(None, invokation_variants, self.syntax_element.syntax_element_descriptions()) return doc.ArticleContents(docs.paras(self.syntax_element.single_line_description()), doc.SectionContents(initial_paragraphs, self._sub_sections(environment)))
def apply(self, environment: ConstructionEnvironment) -> doc.SectionContents: sections = [] for phase_and_instruction_description in self.phase_and_instruction_description_list: man_page_renderer = render_instruction.instruction_doc_section_contents_constructor( phase_and_instruction_description[1]) phase_section = doc.Section(text(phase_and_instruction_description[0].syntax), man_page_renderer.apply(environment)) sections.append(phase_section) initial_paragraphs = [] if len(self.phase_and_instruction_description_list) > 1: initial_paragraphs = [para('The instruction "%s" exists in multiple phases.' % self.instruction_name)] return doc.SectionContents(initial_paragraphs, sections)
def apply(self, program: CliProgramSyntaxDocumentation) -> docs.SectionContents: initial_paragraphs = [docs.para(program.description().single_line_description)] initial_paragraphs += program.initial_paragraphs() sections = [self._synopsis_section(program)] sections += self._description_sections(program) sections += self._options_sections(program.argument_descriptions()) sections += self._files_sections(program.files()) sections += self._outcome_sections(program.outcome(self.environment)) sections += see_also_sections(program.see_also(), self.environment, True) return docs.SectionContents(initial_paragraphs, sections)
def test_single_sub_section_with_initial_paras_everywhere(self): # ARRANGE # root = Element('root') sc = SectionContents( [para('para 0')], [Section(StringText('header 1'), SectionContents([para('para 1')], [Section(StringText('header 1/1'), SectionContents([para('para 2')], []))]))]) # ACT # ret_val = TEST_RENDERER.render_section_contents(sut.Environment(0), root, sc) # ASSERT # assert_contents_and_that_last_child_is_returned( '<root>' '<p>para 0</p>' '<section>' '<header>' '<h1>header 1</h1>' '</header>' '<p>para 1</p>' '<section>' '<header>' '<h2>header 1/1</h2>' '</header>' '<p>para 2</p>' '</section>' '</section>' '</root>' , root, ret_val, self)
def test(self): cases = [ Case('test_singleton_element_without_contents', items=[HeaderContentListItem(text('header'))], expected='<root>' '<dl>' '<dt>header</dt>' '</dl>' '</root>'), Case('test_singleton_element_with_multiple_content_paragraphs', items=[ HeaderContentListItem( text('header'), [para('ignored'), para('ignored')]) ], expected='<root>' '<dl>' '<dt>header</dt>' '<dd>' '<p>every para text</p>' '<p>every para text</p>' '</dd>' '</dl>' '</root>'), ] for case in cases: with self.subTest(case.name): root = Element('root') the_list = HeaderContentList(case.items, Format(ListType.VARIABLE_LIST)) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), ConstantPRenderer('every para text'), root, the_list) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual(case.expected, xml_string) self.assertIs(list(root)[0], 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 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 _path_element_relativity_paragraphs( default_relativity: RelOptionType, options_list: lists.HeaderContentList, custom_paragraphs_before: Sequence[ParagraphItem], custom_paragraphs_after: Sequence[ParagraphItem] ) -> Sequence[ParagraphItem]: ret_val = [] ret_val += custom_paragraphs_before ret_val += [ docs.para('Accepted relativities (default is "{}"):'.format( REL_OPTIONS_MAP[default_relativity].informative_name)), transform_list_to_table(options_list), ] ret_val += custom_paragraphs_after return ret_val
def apply(self, program: CliProgramSyntaxDocumentation) -> docs.SectionContents: initial_paragraphs = [ docs.para(program.description().single_line_description) ] initial_paragraphs += program.initial_paragraphs() sections = [self._synopsis_section(program)] sections += self._description_sections(program) sections += self._options_sections(program.argument_descriptions()) sections += self._files_sections(program.files()) sections += self._outcome_sections(program.outcome(self.environment)) sections += see_also_sections(program.see_also(), self.environment, True) return docs.SectionContents(initial_paragraphs, sections)
def _path_element_description(path_arg_name: str, default_relativity: RelOptionType, options_list: lists.HeaderContentList, custom_paragraphs_before: Sequence[ParagraphItem], custom_paragraphs_after: Sequence[ParagraphItem]) -> SyntaxElementDescription: description_rest = [] description_rest += custom_paragraphs_before description_rest += [ docs.para('Accepted relativities (default is "{}"):'.format( REL_OPTIONS_MAP[default_relativity].informative_name )), transform_list_to_table(options_list), ] description_rest += custom_paragraphs_after return SyntaxElementDescription(path_arg_name, description_rest)
def apply(self, environment: ConstructionEnvironment) -> doc.SectionContents: sections = [] for phase_and_instruction_description in self.phase_and_instruction_description_list: man_page_renderer = render_instruction.instruction_doc_section_contents_constructor( phase_and_instruction_description[1]) phase_section = doc.Section( text(phase_and_instruction_description[0].syntax), man_page_renderer.apply(environment)) sections.append(phase_section) initial_paragraphs = [] if len(self.phase_and_instruction_description_list) > 1: initial_paragraphs = [ para('The instruction "%s" exists in multiple phases.' % self.instruction_name) ] return doc.SectionContents(initial_paragraphs, sections)
def test_footer_populator(self): # ARRANGE # section_contents = SectionContents([para('main contents')], []) footer_populator = SingleParaPopulator('footer contents') document_setup = sut.DocumentSetup('page title', footer_populator=footer_populator) # ACT # output_file = io.StringIO() DOCUMENT_RENDERER.apply(output_file, document_setup, section_contents) actual = output_file.getvalue() # ASSERT # expected = (DOCTYPE_XHTML1_0 + '<html>' '<head>' '<title>page title</title>' '</head>' '<body>' '<p>main contents</p>' '<p>footer contents</p>' '</body>' '</html>') self.assertEqual(expected, actual)
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 list_item(doc: SectionDocumentation) -> HeaderContentListItem: paras = [docs.para(doc.purpose().single_line_description)] add_default_info(doc, paras) return docs.list_item(doc.syntax_name_cross_ref_text, paras)
def _paragraphs() -> list: return [docs.para('paragraph text')]
def para( self, s: str, extra: Optional[Mapping[str, Any]] = None, ) -> docs.ParagraphItem: return docs.para(self.format(s, extra))
def instruction_set_list_item(description: InstructionDocumentation, name_2_name_text_fun: Callable[[str], docs.Text]) -> lists.HeaderContentListItem: description_para = docs.para(description.single_line_description()) return docs.list_item(name_2_name_text_fun(description.instruction_name()), [description_para])
return [] return [_WHERE_PARA, syntax_element_description_list() ] if not invokation_variants: return [] return ([variants_list(instruction_name_or_none, invokation_variants, custom_separations=docs.SEPARATION_OF_HEADER_AND_CONTENTS)] + syntax_element_description_paragraph_items()) def invokation_variants_content(instruction_name: Optional[str], invokation_variants: Sequence[InvokationVariant], syntax_element_descriptions: Iterable[SyntaxElementDescription] ) -> doc.SectionContents: return doc.SectionContents(invokation_variants_paragraphs(instruction_name, invokation_variants, syntax_element_descriptions ), []) _WHERE_PARA = docs.para(doc_format.text_as_header('where')) FORMS_PARA = docs.para(doc_format.text_as_header('Forms:')) def _custom_list_indent(indented: bool) -> int: return None if indented else 0
def _type_paragraph(self) -> docs.ParagraphItem: type_name = types.VALUE_TYPE_2_TYPES_INFO_DICT[ self.builtin_doc.value_type].name.singular return docs.para(': '.join( (concepts.TYPE_CONCEPT_INFO.singular_name.capitalize(), type_name)))
def cell_of_literal(text: str) -> docs.TableCell: return docs.cell([docs.para(doc_format.literal_text(text))])
def cell_of_name_part_name(text: str) -> docs.TableCell: return docs.cell([docs.para(text)])
def text_cell(content_str: str) -> TableCell: return single_paragraph_cell(para(content_str))
def default_section_para(section_concept_name: str = 'section') -> docs.ParagraphItem: return docs.para(_DEFAULT_SECTION_STRING.format(section_concept_name=section_concept_name))
def summary_paragraphs(self) -> List[ParagraphItem]: return [para(self.purpose().single_line_description)]
def test(self): # ARRANGE # cases = [ ('empty', Section( StringText('header 1'), empty_section_contents()), '<root>' '<section>' '<header>' '<h1>header 1</h1>' '</header>' '</section>' '</root>' ), ('empty with target', Section( StringText('header 1'), empty_section_contents(), target=CrossReferenceTargetTestImpl('section-target-name')), '<root>' '<section id="section-target-name">' '<header>' '<h1>header 1</h1>' '</header>' '</section>' '</root>' ), ('empty with tags', Section( StringText('header 1'), empty_section_contents(), tags={'first-label', 'second-label'}), '<root>' '<section class="first-label second-label">' '<header>' '<h1>header 1</h1>' '</header>' '</section>' '</root>' ), ('empty with target and tags', Section( StringText('header 1'), empty_section_contents(), target=CrossReferenceTargetTestImpl('t'), tags={'l1', 'l2'}), '<root>' '<section class="l1 l2" id="t">' '<header>' '<h1>header 1</h1>' '</header>' '</section>' '</root>' ), ('with contents', Section( StringText('header 1'), SectionContents( [para('para 1')], [Section( StringText('header 1/1'), SectionContents( [para('para 1/1')], []))]) ), '<root>' '<section>' '<header>' '<h1>header 1</h1>' '</header>' '<p>para 1</p>' '<section>' '<header>' '<h2>header 1/1</h2>' '</header>' '<p>para 1/1</p>' '</section>' '</section>' '</root>' ), ] for test_case_name, section, expected in cases: with self.subTest(test_case_name): root = Element('root') # ACT # ret_val = TEST_RENDERER.render_section_item(sut.Environment(0), root, section) # ASSERT # assert_contents_and_that_last_child_is_returned( expected, root, ret_val, self)
from exactly_lib.definitions import doc_format from exactly_lib.util.textformat.structure import structures as docs DESCRIPTION__HEADER__UPPERCASE = docs.text('DESCRIPTION') DESCRIPTION__HEADER__CAPITALIZED = docs.text('Description') NOTES__HEADER__UPPERCASE = docs.text('NOTES') NOTES__HEADER__CAPITALIZED = docs.text('Notes') NOTE_LINE_HEADER = 'Note:' OUTCOME__HEADER__UPPERCASE = docs.text('OUTCOME') SYNOPSIS_TEXT = docs.text('SYNOPSIS') WHERE_PARA = docs.para(doc_format.text_as_header('where')) FORMS_PARA = docs.para(doc_format.text_as_header('Forms:'))
def test_simple(self): cases = [ ('empty', Article(StringText('header'), ArticleContents([], empty_section_contents())), '<root>' '<article>' '<header>' '<h1>header</h1>' '</header>' '</article>' '</root>' ), ('empty with target', Article(StringText('header'), ArticleContents([], empty_section_contents()), target=CrossReferenceTargetTestImpl('target-name')), '<root>' '<article id="target-name">' '<header>' '<h1>header</h1>' '</header>' '</article>' '</root>' ), ('empty with tags', Article(StringText('header'), ArticleContents([], empty_section_contents()), tags={'label1', 'label2'}), '<root>' '<article class="label1 label2">' '<header>' '<h1>header</h1>' '</header>' '</article>' '</root>' ), ('empty with target and tags', Article(StringText('header'), ArticleContents([], empty_section_contents()), target=CrossReferenceTargetTestImpl('article-target'), tags={'label1', 'label2'}), '<root>' '<article class="label1 label2" id="article-target">' '<header>' '<h1>header</h1>' '</header>' '</article>' '</root>' ), ('single abstract paragraph', Article(StringText('header'), ArticleContents([para('abstract paragraph')], empty_section_contents())), '<root>' '<article>' '<header>' '<h1>header</h1>' '<p>abstract paragraph</p>' '</header>' '</article>' '</root>' ) ] for test_case_name, article, expected in cases: with self.subTest(test_case_name): root = Element('root') environment = sut.Environment(0) # ACT # ret_val = TEST_RENDERER.render_section_item(environment, root, article) # ASSERT # assert_contents_and_that_last_child_is_returned( expected, root, ret_val, self)