def table_dumps(res): tab = Table(headers=[' name ', ' port ', 'status', 'container']) rows = [] for service_name, v in res.items(): rows.append([ service_name, str(v['ports'].keys()[0] if v['ports'] else ''), v['status'], v['container_id'] ]) rows.sort(key=lambda r: r[0]) tab.extend(rows) return tab.to_text()
def test_table_dicts(): data_dicts = [{'id': 1, 'name': 'John Doe'}, {'id': 2, 'name': 'Dale Simmons'}] t2 = Table.from_dict(data_dicts[0]) t3 = Table.from_dict(data_dicts) t3.extend([[3, 'Kurt Rose'], [4]]) assert set(t2.headers) == set(['id', 'name']) assert len(t2) == 1 # the sorted() stuff handles ordering differences between versions # TODO: should maybe change Table to sort the headers of dicts and such? assert sorted(t2.to_html()) == sorted(T2_REF_HTML) assert sorted(t3.to_html()) == sorted(T3_REF_HTML) assert t3.to_text()
def test_table_obj(): class TestType(object): def __init__(self): self.greeting = 'hi' t4 = Table.from_object(TestType()) assert len(t4) == 1 assert 'greeting' in t4.headers
def test_table_dicts(): data_dicts = [{ 'id': 1, 'name': 'John Doe' }, { 'id': 2, 'name': 'Dale Simmons' }] t2 = Table.from_dict(data_dicts[0]) t3 = Table.from_dict(data_dicts) t3.extend([[3, 'Kurt Rose'], [4]]) assert set(t2.headers) == set(['id', 'name']) assert len(t2) == 1 # the sorted() stuff handles ordering differences between versions # TODO: should maybe change Table to sort the headers of dicts and such? assert sorted(t2.to_html()) == sorted(T2_REF_HTML) assert sorted(t3.to_html()) == sorted(T3_REF_HTML) assert t3.to_text()
def __call__(self, context, _route): content_parts = [self._html_wrapper] if self._html_style_content: content_parts.extend(['<head><style type="text/css">', self._html_style_content, '</style></head>']) content_parts.append('<body>') title = self._html_format_ep(_route) content_parts.append(title) table = Table.from_data(context, max_depth=self.max_depth) table._html_table_tag = self._html_table_tag content = table.to_html(max_depth=self.max_depth, orientation=self.orientation) content_parts.append(content) content_parts.append('</body>') content_parts.append(self._html_wrapper_close) return Response('\n'.join(content_parts), mimetype='text/html')
def __call__(self, context, _route): content_parts = [self._html_wrapper] if self._html_style_content: content_parts.extend([ '<head><style type="text/css">', self._html_style_content, '</style></head>' ]) content_parts.append('<body>') title = self._html_format_ep(_route) content_parts.append(title) table = Table.from_data(context, max_depth=self.max_depth) table._html_table_tag = self._html_table_tag content = table.to_html(max_depth=self.max_depth, orientation=self.orientation) content_parts.append(content) content_parts.append('</body>') content_parts.append(self._html_wrapper_close) return Response('\n'.join(content_parts), mimetype='text/html')
def test_table_lists(): data_lists = [['id', 'name'], [1, 'John Doe'], [2, 'Dale Simmons']] t1 = Table(data_lists) assert set(t1.headers) == set(['id', 'name']) assert len(t1) == 2 assert 'John Doe' in repr(t1)