summaryrefslogtreecommitdiffstats
path: root/tests/test_main.py
diff options
context:
space:
mode:
authorAmjith Ramanujam <amjith.r@gmail.com>2015-11-22 05:46:06 -0800
committerAmjith Ramanujam <amjith.r@gmail.com>2015-11-22 05:46:06 -0800
commitb68c2ab38c5d0376f7e318bec3a2ca02837c8613 (patch)
tree67233fe83030d704f5870f930b22089cc77dac89 /tests/test_main.py
parent5762dda31478d16d9ddeeb11ec2beb68de12a98e (diff)
Add tests for the format_output.
Diffstat (limited to 'tests/test_main.py')
-rw-r--r--tests/test_main.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/test_main.py b/tests/test_main.py
index 0d026994..1642d1f5 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -4,7 +4,7 @@ try:
import setproctitle
except ImportError:
setproctitle = None
-from pgcli.main import obfuscate_process_password
+from pgcli.main import obfuscate_process_password, format_output
@pytest.mark.skipif(platform.system() == 'Windows',
@@ -39,3 +39,22 @@ def test_obfuscate_process_password():
assert title == expected
setproctitle.setproctitle(original_title)
+
+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_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'-[ RECORD 0 ]-------------------------\nhead1 | abc\nhead2 | def\n', 'test status']
+ assert expanded_results == expanded