1
0
Fork 0

Fix issues pointed out in pull request comments.

This commit is contained in:
Karl-Aksel Puulmann 2015-01-08 11:58:02 +02:00 committed by Amjith Ramanujam
parent 8307a7e642
commit b7f9c00c21
5 changed files with 13 additions and 9 deletions

View File

@ -181,7 +181,7 @@ def format_output(rows, headers, status):
output.append(tabulate(rows, headers, tablefmt='psql'))
if status: # Only print the status if it's not None.
output.append(status)
return '\n'.join(output)
return output
def need_completion_refresh(sql):
try:

View File

@ -65,7 +65,7 @@ class PGExecute(object):
FROM pg_catalog.pg_database d
ORDER BY 1;"""
def __init__(self, database=None, user=None, password=None, host=None, port=None):
def __init__(self, database, user, password, host, port):
(self.dbname, self.user, self.password, self.host, self.port) = \
_parse_dsn(database, default_user=user,
default_password=password, default_host=host,

View File

@ -21,4 +21,5 @@ def cursor(connection):
@pytest.fixture
def executor(connection):
return PGExecute(database='_test_db', user=POSTGRES_USER, host=POSTGRES_HOST)
return PGExecute(database='_test_db', user=POSTGRES_USER, host=POSTGRES_HOST,
password=None, port=None)

View File

@ -34,7 +34,7 @@ def test__parse_dsn():
# Full dsn with all components but with postgresql:// prefix.
('postgresql://user:password@host:5432/dbname',
('dbname', 'user', 'password', 'host', '5432'))
('dbname', 'user', 'password', 'host', '5432')),
]
for dsn, expected in test_cases:
@ -44,7 +44,7 @@ def test__parse_dsn():
def test_conn(executor):
run(executor, '''create table test(a text)''')
run(executor, '''insert into test values('abc')''')
assert run(executor, '''select * from test''') == dedent("""\
assert run(executor, '''select * from test''', join=True) == dedent("""\
+-----+
| a |
|-----|

View File

@ -35,8 +35,11 @@ def drop_tables(conn):
cur.execute('''DROP SCHEMA public CASCADE; CREATE SCHEMA public''')
def run(executor, sql):
def run(executor, sql, join=False):
" Return string output for the sql to be run "
data = executor.run(sql)
assert len(data) == 1 # current code does that
return format_output(*data[0])
result = []
for rows, headers, status in executor.run(sql):
result.extend(format_output(rows, headers, status))
if join:
result = '\n'.join(result)
return result