Пример #1
0
 def testPrintRejectsMarkerNotInLastColumn(self, constructor):
   marker = constructor([
       ('aa', 'aaa', 'a'),
       ('bbbb', constructor([('ab', 'cd')]), 'bb'),
   ])
   with io.StringIO() as out, self.assertRaises(TypeError):
     marker.Print(out, 0, cp.ColumnWidths(row=('4444', '333', '22')))
Пример #2
0
 def testPrintIncludesSeparator(self):
   labeled = cp.Labeled([
       ('aa', 'aaa'),
       ('bbbb', 'bb'),
       ('ccc', 'cc'),
   ])
   with io.StringIO() as out:
     labeled.Print(out, 0, cp.ColumnWidths(row=('55555', '333')))
     self.assertEqual(out.getvalue(), textwrap.dedent("""\
     aa:   aaa
     bbbb: bb
     ccc:  cc
     """))
Пример #3
0
 def testPrintSkipsFollowedByEmpty(self):
   labeled = cp.Labeled([
       ('aa', 'aaa'),
       ('bbbb', 'bb'),
       ('cc', ''),
       ('ddd', 'dd'),
   ])
   with io.StringIO() as out:
     labeled.Print(out, 0, cp.ColumnWidths(row=('55555', '333')))
     self.assertEqual(out.getvalue(), textwrap.dedent("""\
     aa:   aaa
     bbbb: bb
     ddd:  dd
     """))
Пример #4
0
 def testPrintWithNonMarkerValues(self, constructor):
   marker = constructor([
       'line 1',
       'line 2',
       'line 3',
   ])
   with io.StringIO() as out:
     marker.Print(out, 0, cp.ColumnWidths())
     self.assertEqual(
         out.getvalue(),
         textwrap.dedent("""\
     line 1
     line 2
     line 3
     """))
Пример #5
0
 def testPrintSkipsEmpty(self, constructor):
   marker = constructor([
       ('aa', 'aaa', 'a'),
       ('bbbb', 'bb', 'bb'),
       (),
       ('ddd', 'dd', 'dd', 'dd'),
   ])
   with io.StringIO() as out:
     marker.Print(out, 0, cp.ColumnWidths(row=('4444', '333', '22', '22')))
     self.assertEqual(
         out.getvalue(),
         textwrap.dedent("""\
     aa   aaa a
     bbbb bb  bb
     ddd  dd  dd dd
     """))
Пример #6
0
 def testPrintIncludesFollowedByMarkerWithOutput(self):
     labeled = cp.Labeled([
         ('aa', 'aaa'),
         ('bbbb', 'bb'),
         ('cc', cp.Labeled([('e', 'eee')])),
         ('ddd', 'dd'),
     ])
     with io.StringIO() as out:
         labeled.Print(out, 0, cp.ColumnWidths(row=('55555', '333')))
         self.assertEqual(
             out.getvalue(),
             textwrap.dedent("""\
   aa:   aaa
   bbbb: bb
   cc:
     e:  eee
   ddd:  dd
   """))
Пример #7
0
 def testPrintWithIndentation(self, constructor):
   marker = constructor([
       'line 1',
       'line 2',
       'line 3',
   ])
   with io.StringIO() as out:
     out.write('prefix\n')
     marker.Print(out, 2, cp.ColumnWidths())
     out.write('suffix\n')
     self.assertEqual(
         out.getvalue(),
         textwrap.dedent("""\
     prefix
       line 1
       line 2
       line 3
     suffix
     """))
Пример #8
0
 def testPrintNestedMarker(self, constructor):
   marker = constructor([
       ('aa', 'aaa', 'a'),
       ('bbbb', 'bb', 'bb'),
       ('cc', constructor([
           ('xxx', 'xx', 'x'),
           ('yyyy', 'yy', 'yyy')
       ])),
       ('ddd', 'dd', 'dd', 'dd'),
   ])
   with io.StringIO() as out:
     marker.Print(out, 0, cp.ColumnWidths(row=('666666', '333', '22', '22')))
     self.assertEqual(out.getvalue(), textwrap.dedent("""\
     aa     aaa a
     bbbb   bb  bb
     cc
       xxx  xx  x
       yyyy yy  yyy
     ddd    dd  dd dd
     """))
Пример #9
0
 def testOverridesColumnWidths(self):
   section = cp.Section([
       'line 1',
       'line 2',
       cp.Table([
           ('a', 'aaa', 'a'),
           ('bb', 'bb', 'b'),
       ]),
       'line 3',
   ])
   with io.StringIO() as out:
     section.Print(out, 0, cp.ColumnWidths(row=('1', '1', '1')))
     self.assertEqual(
         out.getvalue(),
         textwrap.dedent("""\
     line 1
     line 2
     a  aaa a
     bb bb  b
     line 3
     """))
Пример #10
0
 def testPrintWithMarkerValues(self, constructor):
   marker = constructor([
       'line 1',
       'line 2',
       cp.Table([
           ('a', 'aaa', 'a'),
           ('bb', 'bb', 'b'),
       ]),
       'line 3',
   ])
   with io.StringIO() as out:
     marker.Print(out, 0, cp.ColumnWidths(row=('22', '333', '1')))
     self.assertEqual(
         out.getvalue(),
         textwrap.dedent("""\
     line 1
     line 2
     a  aaa a
     bb bb  b
     line 3
     """))
Пример #11
0
 def testPrintIndents(self, constructor):
   marker = constructor([
       ('aa', 'aaa', 'a'),
       ('bbbb', 'bb', 'bb'),
       ('cc',),
       ('ddd', 'dd', 'dd', 'dd'),
   ])
   with io.StringIO() as out:
     out.write('prefix\n')
     marker.Print(
         out, 2,
         cp.ColumnWidths(row=('4444', '333', '22', '22'), indent_length=2))
     out.write('suffix\n')
     self.assertEqual(
         out.getvalue(),
         textwrap.dedent("""\
     prefix
       aa   aaa a
       bbbb bb  bb
       cc
       ddd  dd  dd dd
     suffix
     """))
Пример #12
0
 def testRestrictsIndentLengthToMaxColumnWidth(self):
   column_widths = cp.ColumnWidths(
       row=('a', 'aa', 'aaaa'), indent_length=10, max_column_width=4)
   self.assertEqual(column_widths.widths, [4, 2, 0])
Пример #13
0
 def testComputesNestedColumnWidthsNestedLessColumns(self):
   column_widths = cp.ColumnWidths(
       row=('bb', 'bbbbbb', 'bb', cp.Table([('ccc', 'cc')])))
   self.assertEqual(column_widths.widths, [5, 6, 0])
Пример #14
0
 def testRejectsNestedNotLastColumn(self):
   with self.assertRaises(TypeError):
     cp.ColumnWidths(row=('aaaa', cp.Table([('1', '2')]), 'bb'))
Пример #15
0
 def testAddsIndentLengthToFirstColumnWidth(self):
   column_widths = cp.ColumnWidths(row=('a', 'aa', 'aaaa'), indent_length=2)
   self.assertEqual(column_widths.widths, [3, 2, 0])
Пример #16
0
 def testReprIncludesWidths(self):
   column_widths = cp.ColumnWidths(row=('bb', 'bbb'))
   self.assertEqual(repr(column_widths), '<widths: [2, 0]>')
Пример #17
0
 def testRestrictsWidthsToMaxColumnWidth(self):
   column_widths = cp.ColumnWidths(
       row=('a', 'aa', 'aaaa', 'a'), max_column_width=2)
   self.assertEqual(column_widths.widths, [1, 2, 2, 0])
Пример #18
0
 def testMergeRetrictsToLargerMaxColumnWidth(self):
   widths1 = cp.ColumnWidths(row=('aaa', 'aaaa', 'a'), max_column_width=3)
   widths2 = cp.ColumnWidths(row=('bb', 'bbbbb', 'bb'), max_column_width=2)
   merged = widths1.Merge(widths2)
   self.assertEqual(merged.widths, [3, 3, 0])
Пример #19
0
 def testMergeHandlesArgumentMoreColumns(self):
   widths1 = cp.ColumnWidths(row=('aaa', 'aaaa', 'aa'))
   widths2 = cp.ColumnWidths(row=('bb', 'bbbbb', 'bbbbbb', 'bb'))
   merged = widths1.Merge(widths2)
   self.assertEqual(merged.widths, [3, 5, 6, 0])
Пример #20
0
 def testPassesMaxColumnWidthToNestedTables(self):
   column_widths = cp.ColumnWidths(
       row=('b', 'bbbb', 'bb', cp.Table([('c', 'c', 'cc')])),
       max_column_width=2)
   self.assertEqual(column_widths.widths, [2, 2, 0])
Пример #21
0
 def testHandlesEmptyLastColumn(self):
   column_widths = cp.ColumnWidths(row=('aaa', 'bbbbb', 'c', ''))
   self.assertEqual(column_widths.widths, [3, 5, 1, 0])
Пример #22
0
 def testHandlesEmptyInteriorColumn(self):
   column_widths = cp.ColumnWidths(row=('aaa', '', 'bbbbb', 'c'))
   self.assertEqual(column_widths.widths, [3, 0, 5, 0])
Пример #23
0
 def testIgnoresEmptyRow(self):
   column_widths = cp.ColumnWidths(row=())
   self.assertEqual(column_widths.widths, [])
Пример #24
0
 def testComputesWidthsIgnoringLastColumn(self):
   column_widths = cp.ColumnWidths(row=('aaa', 'aa', 'aaaa', 'a'))
   self.assertEqual(column_widths.widths, [3, 2, 4, 0])
Пример #25
0
 def testMergeTakesMaxWidthInEachColumn(self):
   widths1 = cp.ColumnWidths(row=('aaa', 'aaaa', 'a'))
   widths2 = cp.ColumnWidths(row=('bb', 'bbbbb', 'bb'))
   merged = widths1.Merge(widths2)
   self.assertEqual(merged.widths, [3, 5, 0])
Пример #26
0
 def testSkipsEmptyLastColumnWhenSpecified(self):
   column_widths = cp.ColumnWidths(row=('aaa', 'bbbbb', ''), skip_empty=True)
   self.assertEqual(column_widths.widths, [3, 0, 0])
Пример #27
0
 def testMergeSetsMaxColumnWidthToUnlimitedIfOneUnlimited(self):
   widths1 = cp.ColumnWidths(row=('aaa', 'aaaa', 'a'))
   widths2 = cp.ColumnWidths(row=('bb', 'bbbbb', 'bb'), max_column_width=2)
   merged = widths1.Merge(widths2)
   self.assertEqual(merged.widths, [3, 4, 0])
Пример #28
0
 def testSkipsMultipleEmptyEndingColumnsWhenSpecified(self):
   column_widths = cp.ColumnWidths(
       row=('aaa', 'bbbbb', '', ''), skip_empty=True)
   self.assertEqual(column_widths.widths, [3, 0, 0, 0])
Пример #29
0
 def testIncludesSeparatorWidth(self):
   column_widths = cp.ColumnWidths(row=('aaa', 'aa'), separator=':')
   self.assertEqual(column_widths.widths, [4, 0])
Пример #30
0
 def testIncludesEmptyInteriorColumnsWhenSkipEmptySpecified(self):
   column_widths = cp.ColumnWidths(
       row=('aaa', '', 'bbbbb', 'c'), skip_empty=True)
   self.assertEqual(column_widths.widths, [3, 0, 5, 0])