Ejemplo n.º 1
0
 def testIncludesIndentLength(self, constructor, column_widths_getter):
     marker = constructor(
         [cp.Table([('aaa', 'aa', 'a')]),
          cp.Table([('bb', 'bbbb', 'b')])])
     column_widths = marker.CalculateColumnWidths(indent_length=2)
     self.assertEqual(column_widths_getter(marker, column_widths),
                      [5, 4, 0])
Ejemplo n.º 2
0
 def testOverridesMaxColumnWidth(self):
   section = cp.Section(
       [cp.Table([('aaa', 'aa', 'a')]),
        cp.Table([('bb', 'bbbb', 'b')])],
       max_column_width=3)
   section.CalculateColumnWidths(2)
   self.assertEqual(section._column_widths.widths, [3, 3, 0])
Ejemplo n.º 3
0
 def testMarkersAndNonMarkers(self, constructor, column_widths_getter):
   marker = constructor([
       cp.Table([('aaa', 'aa', 'a')]), 'line2',
       cp.Table([('bb', 'bbbb', 'b')])
   ])
   column_widths = marker.CalculateColumnWidths()
   self.assertEqual(column_widths_getter(marker, column_widths), [3, 4, 0])
Ejemplo n.º 4
0
 def testRestrictsToMaxColumnWidth(self, constructor, column_widths_getter):
     marker = constructor(
         [cp.Table([('aaa', 'aa', 'a')]),
          cp.Table([('bb', 'bbbb', 'b')])])
     column_widths = marker.CalculateColumnWidths(3)
     self.assertEqual(column_widths_getter(marker, column_widths),
                      [3, 3, 0])
Ejemplo n.º 5
0
def _TransformTrafficPairs(traffic_pairs, service_url, service_ingress=None):
  """Transforms a List[TrafficTargetPair] into a marker class structure."""
  traffic_section = cp.Section(
      [cp.Table(_TransformTrafficPair(p) for p in traffic_pairs)])
  route_section = [cp.Labeled([('URL', service_url)])]
  if service_ingress is not None:
    route_section.append(cp.Labeled([('Ingress', service_ingress)]))
  route_section.append(cp.Labeled([('Traffic', traffic_section)]))
  return cp.Section(route_section, max_column_width=60)
Ejemplo n.º 6
0
def _ComponentTable(components):
    """Format component to table."""
    con = console_attr.GetConsoleAttr()
    rows = []
    for component in components:
        status_symbol = pretty_print.GetReadySymbol(component.deployment_state)
        status_color = pretty_print.GetReadyColor(component.deployment_state)
        rows.append((con.Colorize(status_symbol, status_color), component.name,
                     component.deployment_reason, component.commit_id[:6],
                     component.deployment_time, component.url))

    return cp.Table(
        [('', 'NAME', 'REASON', 'COMMIT', 'LAST-DEPLOYED', 'URL')] + rows,
        console_attr=con)
Ejemplo n.º 7
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
     """))
Ejemplo n.º 8
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
     """))
Ejemplo n.º 9
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])
Ejemplo n.º 10
0
 def testComputesNestedColumnWidthsNestedLessColumns(self):
   column_widths = cp.ColumnWidths(
       row=('bb', 'bbbbbb', 'bb', cp.Table([('ccc', 'cc')])))
   self.assertEqual(column_widths.widths, [5, 6, 0])
Ejemplo n.º 11
0
 def testRejectsNestedNotLastColumn(self):
   with self.assertRaises(TypeError):
     cp.ColumnWidths(row=('aaaa', cp.Table([('1', '2')]), 'bb'))
Ejemplo n.º 12
0
 def testReturnsEmptyColumnWidths(self):
   section = cp.Section(
       [cp.Table([('aaa', 'aa', 'a')]),
        cp.Table([('bb', 'bbbb', 'b')])])
   column_widths = section.CalculateColumnWidths()
   self.assertEqual(column_widths.widths, [])
Ejemplo n.º 13
0
      """))

  def testPrinterSkipsEmpty(self):
    with io.StringIO() as out:
      p = MockPrinter(out=out)
      p.AddRecord('')
      self.assertEqual(out.getvalue(),
                       textwrap.dedent("""\
      ------
      """))

  def testPrinterAlignsTablesInLines(self):
    case = cp.Lines([
        'title',
        cp.Table([
            ('aaa', 'bbbbbbbb', 'c'),
            ('a', 'bb', 'ccc'),
        ]),
        'middle',
        cp.Table([
            ('a', 'b', 'c'),
            ('a', 'b', 'c'),
        ]),
        'end',
    ])
    with io.StringIO() as out:
      p = MockPrinter(out=out)
      p.AddRecord(case)
      self.assertEqual(
          out.getvalue(),
          textwrap.dedent("""\
      title
Ejemplo n.º 14
0
 def _ComponentTable(self, record):
     rows = [(x.name, str(x.event_input), x.description)
             for x in record.components]
     return cp.Table([('NAME', 'TAKES CE-INPUT', 'DESCRIPTION')] + rows)
Ejemplo n.º 15
0
def _TransformTrafficPairs(traffic_pairs, service_url):
  """Transforms a List[TrafficTargetPair] into a marker class structure."""
  traffic_section = cp.Section(
      [cp.Table(_TransformTrafficPair(p) for p in traffic_pairs)])
  return cp.Table([('Traffic:', service_url, traffic_section)])
Ejemplo n.º 16
0
def _TransformTrafficPair(pair):
  """Transforms a single TrafficTargetPair into a marker class structure."""
  console = console_attr.GetConsoleAttr()
  return (pair.displayPercent, console.Emphasize(pair.displayRevisionId),
          cp.Table([('', _GetTagAndStatus(t), t.url) for t in pair.tags]))