def test_format_output_auto_expand(): settings = OutputSettings( table_format='psql', dcmlfmt='d', floatfmt='g', max_width=100) table_results = format_output('Title', [('abc', 'def')], ['head1', 'head2'], 'test status', settings) table = [ 'Title', '+---------+---------+', '| head1 | head2 |', '|---------+---------|', '| abc | def |', '+---------+---------+', 'test status' ] assert list(table_results) == table expanded_results = format_output( 'Title', [('abc', 'def')], ['head1', 'head2'], 'test status', settings._replace(max_width=1) ) expanded = [ 'Title', '-[ RECORD 1 ]-------------------------', 'head1 | abc', 'head2 | def', 'test status' ] assert '\n'.join(expanded_results) == '\n'.join(expanded)
def test_format_output_auto_expand(): settings = OutputSettings( table_format='psql', dcmlfmt='d', floatfmt='g', max_width=100) table_results = format_output('Title', [('abc', 'def')], ['head1', 'head2'], 'test status', settings) table = [ 'Title', '+---------+---------+', '| head1 | head2 |', '|---------+---------|', '| abc | def |', '+---------+---------+', 'test status' ] assert list(table_results) == table expanded_results = format_output( 'Title', [('abc', 'def')], ['head1', 'head2'], 'test status', settings._replace(max_width=1) ) expanded = [ 'Title', '-[ RECORD 1 ]-------------------------', 'head1 | abc', 'head2 | def', 'test status' ] assert '\n'.join(expanded_results) == '\n'.join(expanded)
def test_format_output_auto_expand(): settings = OutputSettings( table_format="psql", dcmlfmt="d", floatfmt="g", max_width=100 ) table_results = format_output( "Title", [("abc", "def")], ["head1", "head2"], "test status", settings ) table = [ "Title", "+---------+---------+", "| head1 | head2 |", "|---------+---------|", "| abc | def |", "+---------+---------+", "test status", ] assert list(table_results) == table expanded_results = format_output( "Title", [("abc", "def")], ["head1", "head2"], "test status", settings._replace(max_width=1), ) expanded = [ "Title", "-[ RECORD 1 ]-------------------------", "head1 | abc", "head2 | def", "test status", ] assert "\n".join(expanded_results) == "\n".join(expanded)
def test_format_output_auto_expand(): settings = OutputSettings(table_format='psql', dcmlfmt='d', floatfmt='g', max_width=100) table_results = format_output('Title', [('abc', 'def')], ['head1', 'head2'], 'test status', settings) 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', settings._replace(max_width=1)) expanded = ['Title', u'-[ RECORD 0 ]-------------------------\nhead1 | abc\nhead2 | def\n', 'test status'] assert expanded_results == expanded
def test_format_output(): settings = OutputSettings(table_format='psql', dcmlfmt='d', floatfmt='g') results = format_output('Title', [('abc', 'def')], ['head1', 'head2'], 'test status', settings) expected = [ 'Title', '+---------+---------+', '| head1 | head2 |', '|---------+---------|', '| abc | def |', '+---------+---------+', 'test status' ] assert list(results) == expected
def test_format_output_truncate_off(): settings = OutputSettings(table_format="psql", dcmlfmt="d", floatfmt="g", max_field_width=None) long_field_value = ("first field " * 100).strip() results = format_output(None, [(long_field_value, )], ["head1"], None, settings) lines = list(results) assert lines[3] == f"| {long_field_value} |"
def test_format_output(): settings = OutputSettings(table_format="psql", dcmlfmt="d", floatfmt="g") results = format_output("Title", [("abc", "def")], ["head1", "head2"], "test status", settings) expected = [ "Title", "+-------+-------+", "| head1 | head2 |", "|-------+-------|", "| abc | def |", "+-------+-------+", "test status", ] assert list(results) == expected
def run(executor, sql, join=False, expanded=False, pgspecial=None, exception_formatter=None): " Return string output for the sql to be run " results = executor.run(sql, pgspecial, exception_formatter) formatted = [] settings = OutputSettings(table_format='psql', dcmlfmt='d', floatfmt='g', expanded=expanded) for title, rows, headers, status, sql, success in results: formatted.extend(format_output(title, rows, headers, status, settings)) if join: formatted = '\n'.join(formatted) return formatted
def test_format_output_truncate_on(): settings = OutputSettings(table_format="psql", dcmlfmt="d", floatfmt="g", max_field_width=10) results = format_output( None, [("first field value", "second field value")], ["head1", "head2"], None, settings, ) expected = [ "+------------+------------+", "| head1 | head2 |", "|------------+------------|", "| first f... | second ... |", "+------------+------------+", ] assert list(results) == expected