1
1
mirror of https://github.com/dbcli/pgcli.git synced 2024-09-11 13:56:36 +03:00

Added test for '\?'.

This commit is contained in:
Iryna Cherniavska 2015-06-22 12:26:24 -07:00
parent c31269cc78
commit 52c98d4d2d
6 changed files with 87 additions and 3 deletions

View File

@ -68,7 +68,7 @@ def drop_db(hostname='localhost', username=None, password=None,
with cn.cursor() as cr:
cr.execute('drop database %s', (AsIs(dbname),))
cn.close()
close_cn(cn)
def close_cn(cn=None):

View File

@ -5,14 +5,17 @@ from __future__ import print_function
import os
import pexpect
import db_utils as dbutils
import fixture_utils as fixutils
def before_all(context):
"""
Set env parameters.
"""
os.environ['LINES'] = "50"
os.environ['COLUMNS'] = "120"
os.environ['LINES'] = "100"
os.environ['COLUMNS'] = "100"
os.environ['PAGER'] = 'cat'
context.exit_sent = False
# Store get params from config.
@ -44,6 +47,8 @@ def before_all(context):
context.conf['pass'],
context.conf['dbname'])
context.fixture_data = fixutils.read_fixture_files()
def after_all(context):
"""

View File

@ -0,0 +1,24 @@
+--------------------------+-----------------------------------------------+
| Command | Description |
|--------------------------+-----------------------------------------------|
| \# | Refresh auto-completions. |
| \? | Show Help. |
| \c[onnect] database_name | Change to a new database. |
| \d [pattern] | List or describe tables, views and sequences. |
| \dT[S+] [pattern] | List data types |
| \df[+] [pattern] | List functions. |
| \di[+] [pattern] | List indexes. |
| \dn[+] [pattern] | List schemas. |
| \ds[+] [pattern] | List sequences. |
| \dt[+] [pattern] | List tables. |
| \du[+] [pattern] | List roles. |
| \dv[+] [pattern] | List views. |
| \e [file] | Edit the query with external editor. |
| \l | List databases. |
| \n[+] [name] | List or execute named queries. |
| \nd [name [query]] | Delete a named query. |
| \ns [name [query]] | Save a named query. |
| \refresh | Refresh auto-completions. |
| \timing | Toggle timing of commands. |
| \x | Toggle expanded output. |
+--------------------------+-----------------------------------------------+

34
features/fixture_utils.py Normal file
View File

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
import os
import codecs
def read_fixture_lines(filename):
"""
Read lines of text from file.
:param filename: string name
:return: list of strings
"""
lines = []
for line in codecs.open(filename, 'r', encoding='utf-8'):
lines.append(line.strip())
return lines
def read_fixture_files():
"""
Read all files inside fixture_data directory.
"""
fixture_dict = {}
current_dir = os.path.dirname(__file__)
fixture_dir = os.path.join(current_dir, 'fixture_data/')
for filename in os.listdir(fixture_dir):
if filename not in ['.', '..']:
fullname = os.path.join(fixture_dir, filename)
fixture_dict[filename] = read_fixture_lines(fullname)
return fixture_dict

View File

@ -7,6 +7,13 @@ Feature: run the cli,
when we run pgcli
then we see pgcli prompt
Scenario: run "\?" command
Given we have pgcli installed
when we run pgcli
and we wait for prompt
and we send "\?" command
then we see help output
Scenario: run the cli and exit
Given we have pgcli installed
when we run pgcli

View File

@ -46,6 +46,14 @@ def step_ctrl_d(context):
context.exit_sent = True
@when('we send "\?" command')
def step_send_help(context):
"""
Send \? to see help.
"""
context.cli.sendline('\?')
@then('pgcli exits')
def step_wait_exit(context):
"""
@ -60,3 +68,9 @@ def step_see_prompt(context):
Wait to see the prompt.
"""
context.cli.expect('{0}> '.format(context.conf['dbname']))
@then('we see help output')
def step_see_help(context):
for expected_line in context.fixture_data['help.txt']:
context.cli.expect_exact(expected_line)