Exemplo n.º 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')))
Exemplo n.º 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
     """))
Exemplo n.º 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
     """))
Exemplo n.º 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
     """))
Exemplo n.º 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
     """))
Exemplo n.º 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
   """))
Exemplo n.º 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
     """))
Exemplo n.º 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
     """))
Exemplo n.º 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
     """))
Exemplo n.º 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
     """))
Exemplo n.º 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
     """))
Exemplo n.º 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])
Exemplo n.º 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])
Exemplo n.º 14
0
 def testRejectsNestedNotLastColumn(self):
   with self.assertRaises(TypeError):
     cp.ColumnWidths(row=('aaaa', cp.Table([('1', '2')]), 'bb'))
Exemplo n.º 15
0
 def testAddsIndentLengthToFirstColumnWidth(self):
   column_widths = cp.ColumnWidths(row=('a', 'aa', 'aaaa'), indent_length=2)
   self.assertEqual(column_widths.widths, [3, 2, 0])
Exemplo n.º 16
0
 def testReprIncludesWidths(self):
   column_widths = cp.ColumnWidths(row=('bb', 'bbb'))
   self.assertEqual(repr(column_widths), '<widths: [2, 0]>')
Exemplo n.º 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])
Exemplo n.º 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])
Exemplo n.º 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])
Exemplo n.º 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])
Exemplo n.º 21
0
 def testHandlesEmptyLastColumn(self):
   column_widths = cp.ColumnWidths(row=('aaa', 'bbbbb', 'c', ''))
   self.assertEqual(column_widths.widths, [3, 5, 1, 0])
Exemplo n.º 22
0
 def testHandlesEmptyInteriorColumn(self):
   column_widths = cp.ColumnWidths(row=('aaa', '', 'bbbbb', 'c'))
   self.assertEqual(column_widths.widths, [3, 0, 5, 0])
Exemplo n.º 23
0
 def testIgnoresEmptyRow(self):
   column_widths = cp.ColumnWidths(row=())
   self.assertEqual(column_widths.widths, [])
Exemplo n.º 24
0
 def testComputesWidthsIgnoringLastColumn(self):
   column_widths = cp.ColumnWidths(row=('aaa', 'aa', 'aaaa', 'a'))
   self.assertEqual(column_widths.widths, [3, 2, 4, 0])
Exemplo n.º 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])
Exemplo n.º 26
0
 def testSkipsEmptyLastColumnWhenSpecified(self):
   column_widths = cp.ColumnWidths(row=('aaa', 'bbbbb', ''), skip_empty=True)
   self.assertEqual(column_widths.widths, [3, 0, 0])
Exemplo n.º 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])
Exemplo n.º 28
0
 def testSkipsMultipleEmptyEndingColumnsWhenSpecified(self):
   column_widths = cp.ColumnWidths(
       row=('aaa', 'bbbbb', '', ''), skip_empty=True)
   self.assertEqual(column_widths.widths, [3, 0, 0, 0])
Exemplo n.º 29
0
 def testIncludesSeparatorWidth(self):
   column_widths = cp.ColumnWidths(row=('aaa', 'aa'), separator=':')
   self.assertEqual(column_widths.widths, [4, 0])
Exemplo n.º 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])