def test_with_given_indent(self): indent_str = '[INDENT]' list_format = lf.ListFormat( lf.HeaderAndIndentFormatPlain(contents_indent_spaces=4), NO_SEPARATIONS, indent_str=indent_str) items = [item('header', [single_text_para('contents')])] formatter = formatter_with_page_width(100) actual = formatter.format_header_value_list_according_to_format( items, list_format) self.assertEqual( [indent_str + 'header', indent_str + (4 * ' ') + 'contents'], actual)
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)
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_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)
class TestResolveListFormat(unittest.TestCase): LIST_FORMATS = lf.ListFormats( itemized_list_format=lf.ListFormat( lf.HeaderAndIndentFormatWithMarker('*'), NO_SEPARATIONS, indent_str=''), ordered_list_format=lf.ListFormat( lf.HeaderAndIndentFormatWithNumbering(), NO_SEPARATIONS, indent_str=''), variable_list_format=lf.ListFormat(lf.HeaderAndIndentFormatPlain(), NO_SEPARATIONS, indent_str='')) def test_itemized_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.ITEMIZED_LIST))) self.assertEqual(['* header'], actual) 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_variable_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.VARIABLE_LIST))) self.assertEqual(['header'], actual) 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) 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)
def test_following_header_lines_indent(self): formatter = sut.HeaderAndIndentFormatPlain(contents_indent_spaces=5) actual = formatter.following_header_lines_indent(1, 10) self.assertEqual('', actual)
def test_value_indent(self): formatter = sut.HeaderAndIndentFormatPlain(contents_indent_spaces=7) actual = formatter.contents_indent(1) self.assertEqual(7 * ' ', actual)
def test_header_text(self): formatter = sut.HeaderAndIndentFormatPlain(contents_indent_spaces=5) actual = formatter.header_text(1, 1, CROSS_REF_TITLE_ONLY_TEXT_FORMATTER, text('header')) self.assertEqual('header', actual)