def test_format_output_auto_expand(): table_results = format_output('Title', [('abc', 'def')], ['head1', 'head2'], 'test status', 'psql', max_width=100) table = ['Title', '+---------+---------+\n| head1 | head2 |\n|---------+---------|\n| abc | def |\n+---------+---------+', 'test status'] assert table_results == table expanded_results = format_output('Title', [('abc', 'def')], ['head1', 'head2'], 'test status', 'psql', max_width=1) expanded = ['Title', u'***************************[ 1. row ]***************************\nhead1 | abc\nhead2 | def\n', 'test status'] assert expanded_results == expanded
def run(executor, sql, join=False): " Return string output for the sql to be run " result = [] for title, rows, headers, status in executor.run(sql): result.extend(format_output(title, rows, headers, status, 'psql')) if join: result = '\n'.join(result) return result
def run(executor, sql, join=False): " Return string output for the sql to be run " result = [] for title, rows, headers, status in executor.run(sql): result.extend(format_output(title, rows, headers, status, 'psql', special.is_expanded_output())) if join: result = '\n'.join(result) return result
def test_format_output(): results = format_output('Title', [('abc', 'def')], ['head1', 'head2'], 'test status', 'psql') expected = [ 'Title', '+---------+---------+\n| head1 | head2 |\n|---------+---------|\n| abc | def |\n+---------+---------+', 'test status' ] assert results == expected
def test_format_output_no_table(): results = format_output('Title', [('abc', 'def')], ['head1', 'head2'], 'test status', None) expected = ['Title', 'head1\thead2', 'abc\tdef', 'test status'] assert results == expected
def test_format_output(): results = format_output('Title', [('abc', 'def')], ['head1', 'head2'], 'test status', 'psql') expected = ['Title', '+---------+---------+\n| head1 | head2 |\n|---------+---------|\n| abc | def |\n+---------+---------+', 'test status'] assert results == expected