diff options
author | Darik Gamble <darik.gamble@gmail.com> | 2015-06-25 07:03:50 -0400 |
---|---|---|
committer | Darik Gamble <darik.gamble@gmail.com> | 2015-06-30 11:28:06 -0400 |
commit | 1355665270e3667e323b9a0dd1a24c57a41e46b9 (patch) | |
tree | b34857dba9703652e372127780a308665b6dca55 /tests | |
parent | adf9a455f65c92d4e7651dcd52a2a074ffdfaaf4 (diff) |
format_output takes an extra arg instead of referencing pgspecial directly
This also allows us to simplify some of the tests in test_pgexecute,
which tested with and without expanded output by first running '\x',
which is a pretty roundabout way of mutating a global variable
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_pgexecute.py | 22 | ||||
-rw-r--r-- | tests/utils.py | 5 |
2 files changed, 15 insertions, 12 deletions
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 |