mirror of https://github.com/dbcli/pgcli
Port auto_vertical feature test from mycli to pgcli
This commit is contained in:
parent
8c8b6816ca
commit
ca88e62a17
|
@ -15,6 +15,7 @@ Internal changes:
|
|||
* Preliminary work for a future change in outputting results that uses less memory. (Thanks: `Dick Marinus`_)
|
||||
* Remove import workaround for OrderedDict, required for python < 2.7. (Thanks: `Andrew Speed`_)
|
||||
* Use less memory when formatting results for display (Thanks: `Dick Marinus`_).
|
||||
* Port auto_vertical feature test from mycli to pgcli. (Thanks: `Dick Marinus`_)
|
||||
|
||||
Bug Fixes:
|
||||
----------
|
||||
|
|
|
@ -119,7 +119,8 @@ class PGCli(object):
|
|||
|
||||
def __init__(self, force_passwd_prompt=False, never_passwd_prompt=False,
|
||||
pgexecute=None, pgclirc_file=None, row_limit=None,
|
||||
single_connection=False, less_chatty=None, prompt=None):
|
||||
single_connection=False, less_chatty=None, prompt=None,
|
||||
auto_vertical_output=False):
|
||||
|
||||
self.force_passwd_prompt = force_passwd_prompt
|
||||
self.never_passwd_prompt = never_passwd_prompt
|
||||
|
@ -138,7 +139,8 @@ class PGCli(object):
|
|||
self.multi_line = c['main'].as_bool('multi_line')
|
||||
self.multiline_mode = c['main'].get('multi_line_mode', 'psql')
|
||||
self.vi_mode = c['main'].as_bool('vi')
|
||||
self.auto_expand = c['main'].as_bool('auto_expand')
|
||||
self.auto_expand = auto_vertical_output or c['main'].as_bool(
|
||||
'auto_expand')
|
||||
self.expanded_output = c['main'].as_bool('expand')
|
||||
self.pgspecial.timing_enabled = c['main'].as_bool('timing')
|
||||
if row_limit is not None:
|
||||
|
@ -820,11 +822,13 @@ class PGCli(object):
|
|||
@click.option('--prompt', help='Prompt format (Default: "\\u@\\h:\\d> ").')
|
||||
@click.option('-l', '--list', 'list_databases', is_flag=True, help='list '
|
||||
'available databases, then exit.')
|
||||
@click.option('--auto-vertical-output', is_flag=True,
|
||||
help='Automatically switch to vertical output mode if the result is wider than the terminal width.')
|
||||
@click.argument('database', default=lambda: None, envvar='PGDATABASE', nargs=1)
|
||||
@click.argument('username', default=lambda: None, envvar='PGUSER', nargs=1)
|
||||
def cli(database, username_opt, host, port, prompt_passwd, never_prompt,
|
||||
single_connection, dbname, username, version, pgclirc, dsn, row_limit,
|
||||
less_chatty, prompt, list_databases):
|
||||
less_chatty, prompt, list_databases, auto_vertical_output):
|
||||
|
||||
if version:
|
||||
print('Version:', __version__)
|
||||
|
@ -848,7 +852,8 @@ def cli(database, username_opt, host, port, prompt_passwd, never_prompt,
|
|||
|
||||
pgcli = PGCli(prompt_passwd, never_prompt, pgclirc_file=pgclirc,
|
||||
row_limit=row_limit, single_connection=single_connection,
|
||||
less_chatty=less_chatty, prompt=prompt)
|
||||
less_chatty=less_chatty, prompt=prompt,
|
||||
auto_vertical_output=auto_vertical_output)
|
||||
|
||||
# Choose which ever one has a valid value.
|
||||
database = database or dbname
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
Feature: auto_vertical mode:
|
||||
on, off
|
||||
|
||||
Scenario: auto_vertical on with small query
|
||||
When we run dbcli with --auto-vertical-output
|
||||
and we execute a small query
|
||||
then we see small results in horizontal format
|
||||
|
||||
Scenario: auto_vertical on with large query
|
||||
When we run dbcli with --auto-vertical-output
|
||||
and we execute a large query
|
||||
then we see large results in vertical format
|
|
@ -0,0 +1,92 @@
|
|||
# -*- coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
from textwrap import dedent
|
||||
|
||||
from behave import then, when
|
||||
|
||||
import wrappers
|
||||
|
||||
|
||||
@when('we run dbcli with {arg}')
|
||||
def step_run_cli_with_arg(context, arg):
|
||||
wrappers.run_cli(context, run_args=arg.split('='))
|
||||
|
||||
|
||||
@when('we execute a small query')
|
||||
def step_execute_small_query(context):
|
||||
context.cli.sendline('select 1')
|
||||
|
||||
|
||||
@when('we execute a large query')
|
||||
def step_execute_large_query(context):
|
||||
context.cli.sendline(
|
||||
'select {}'.format(','.join([str(n) for n in range(1, 50)])))
|
||||
|
||||
|
||||
@then('we see small results in horizontal format')
|
||||
def step_see_small_results(context):
|
||||
wrappers.expect_pager(context, dedent("""\
|
||||
+------------+\r
|
||||
| ?column? |\r
|
||||
|------------|\r
|
||||
| 1 |\r
|
||||
+------------+\r
|
||||
SELECT 1\r
|
||||
"""), timeout=5)
|
||||
|
||||
|
||||
@then('we see large results in vertical format')
|
||||
def step_see_large_results(context):
|
||||
wrappers.expect_pager(context, dedent("""\
|
||||
-[ RECORD 1 ]-------------------------\r
|
||||
?column? | 1\r
|
||||
?column? | 2\r
|
||||
?column? | 3\r
|
||||
?column? | 4\r
|
||||
?column? | 5\r
|
||||
?column? | 6\r
|
||||
?column? | 7\r
|
||||
?column? | 8\r
|
||||
?column? | 9\r
|
||||
?column? | 10\r
|
||||
?column? | 11\r
|
||||
?column? | 12\r
|
||||
?column? | 13\r
|
||||
?column? | 14\r
|
||||
?column? | 15\r
|
||||
?column? | 16\r
|
||||
?column? | 17\r
|
||||
?column? | 18\r
|
||||
?column? | 19\r
|
||||
?column? | 20\r
|
||||
?column? | 21\r
|
||||
?column? | 22\r
|
||||
?column? | 23\r
|
||||
?column? | 24\r
|
||||
?column? | 25\r
|
||||
?column? | 26\r
|
||||
?column? | 27\r
|
||||
?column? | 28\r
|
||||
?column? | 29\r
|
||||
?column? | 30\r
|
||||
?column? | 31\r
|
||||
?column? | 32\r
|
||||
?column? | 33\r
|
||||
?column? | 34\r
|
||||
?column? | 35\r
|
||||
?column? | 36\r
|
||||
?column? | 37\r
|
||||
?column? | 38\r
|
||||
?column? | 39\r
|
||||
?column? | 40\r
|
||||
?column? | 41\r
|
||||
?column? | 42\r
|
||||
?column? | 43\r
|
||||
?column? | 44\r
|
||||
?column? | 45\r
|
||||
?column? | 46\r
|
||||
?column? | 47\r
|
||||
?column? | 48\r
|
||||
?column? | 49\r
|
||||
SELECT 1\r
|
||||
"""), timeout=5)
|
|
@ -21,10 +21,13 @@ def expect_pager(context, expected, timeout):
|
|||
context.conf['pager_boundary'], expected), timeout=timeout)
|
||||
|
||||
|
||||
def run_cli(context):
|
||||
def run_cli(context, run_args=None):
|
||||
"""Run the process using pexpect."""
|
||||
run_args = run_args or []
|
||||
cli_cmd = context.conf.get('cli_command')
|
||||
context.cli = pexpect.spawnu(cli_cmd, cwd=context.package_root)
|
||||
cmd_parts = [cli_cmd] + run_args
|
||||
cmd = ' '.join(cmd_parts)
|
||||
context.cli = pexpect.spawnu(cmd, cwd=context.package_root)
|
||||
context.exit_sent = False
|
||||
context.currentdb = context.conf['dbname']
|
||||
|
||||
|
|
Loading…
Reference in New Issue