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])
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])
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])
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])
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)
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)
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 """))
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 """))
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])
def testComputesNestedColumnWidthsNestedLessColumns(self): column_widths = cp.ColumnWidths( row=('bb', 'bbbbbb', 'bb', cp.Table([('ccc', 'cc')]))) self.assertEqual(column_widths.widths, [5, 6, 0])
def testRejectsNestedNotLastColumn(self): with self.assertRaises(TypeError): cp.ColumnWidths(row=('aaaa', cp.Table([('1', '2')]), 'bb'))
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, [])
""")) 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
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)
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)])
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]))