summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpgcli/main.py4
-rw-r--r--tests/test_pgexecute.py22
-rw-r--r--tests/utils.py5
3 files changed, 17 insertions, 14 deletions
diff --git a/pgcli/main.py b/pgcli/main.py
index 6a6899d0..10320c50 100755
--- a/pgcli/main.py
+++ b/pgcli/main.py
@@ -448,13 +448,13 @@ def cli(database, user, host, port, prompt_passwd, never_prompt, dbname,
pgcli.run_cli()
-def format_output(title, cur, headers, status, table_format):
+def format_output(title, cur, headers, status, table_format, expanded=False):
output = []
if title: # Only print the title if it's not None.
output.append(title)
if cur:
headers = [utf8tounicode(x) for x in headers]
- if special.is_expanded_output():
+ if expanded:
output.append(expanded_table(cur, headers))
else:
output.append(tabulate(cur, headers, tablefmt=table_format,
diff --git a/tests/test_pgexecute.py b/tests/test_pgexecute.py
index c8dee913..43cf88e0 100644
--- a/tests/test_pgexecute.py
+++ b/tests/test_pgexecute.py
@@ -96,13 +96,11 @@ def test_invalid_column_name(executor):
run(executor, 'select invalid command')
assert 'column "invalid" does not exist' in str(excinfo.value)
-@pytest.yield_fixture(params=[True, False])
-def expanded(request, executor):
- if request.param:
- run(executor, '\\x')
- yield request.param
- if request.param:
- run(executor, '\\x')
+
+@pytest.fixture(params=[True, False])
+def expanded(request):
+ return request.param
+
@dbtest
def test_unicode_support_in_output(executor, expanded):
@@ -110,7 +108,9 @@ def test_unicode_support_in_output(executor, expanded):
run(executor, "insert into unicodechars (t) values ('é')")
# See issue #24, this raises an exception without proper handling
- assert u'é' in run(executor, "select * from unicodechars", join=True)
+ assert u'é' in run(executor, "select * from unicodechars",
+ join=True, expanded=expanded)
+
@dbtest
def test_multiple_queries_same_line(executor):
@@ -158,7 +158,8 @@ def test_unicode_support_in_unknown_type(executor):
def test_json_renders_without_u_prefix(executor, expanded):
run(executor, "create table jsontest(d json)")
run(executor, """insert into jsontest (d) values ('{"name": "Éowyn"}')""")
- result = run(executor, "SELECT d FROM jsontest LIMIT 1", join=True)
+ result = run(executor, "SELECT d FROM jsontest LIMIT 1",
+ join=True, expanded=expanded)
assert u'{"name": "Éowyn"}' in result
@@ -167,7 +168,8 @@ def test_json_renders_without_u_prefix(executor, expanded):
def test_jsonb_renders_without_u_prefix(executor, expanded):
run(executor, "create table jsonbtest(d jsonb)")
run(executor, """insert into jsonbtest (d) values ('{"name": "Éowyn"}')""")
- result = run(executor, "SELECT d FROM jsonbtest LIMIT 1", join=True)
+ result = run(executor, "SELECT d FROM jsonbtest LIMIT 1",
+ join=True, expanded=expanded)
assert u'{"name": "Éowyn"}' in result
diff --git a/tests/utils.py b/tests/utils.py
index 5cdc8849..0287a2e9 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -58,11 +58,12 @@ def drop_tables(conn):
DROP SCHEMA IF EXISTS schema2 CASCADE''')
-def run(executor, sql, join=False):
+def run(executor, sql, join=False, expanded=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'))
+ result.extend(format_output(title, rows, headers, status, 'psql',
+ expanded=expanded))
if join:
result = '\n'.join(result)
return result