mirror of
https://github.com/dbcli/pgcli.git
synced 2024-10-06 02:07:53 +03:00
Merge pull request #344 from dbcli/j-bennet/fix-read-from-file
Added read_from_file back into iospecial.
This commit is contained in:
commit
e4c18532c3
@ -1,6 +1,8 @@
|
||||
import re
|
||||
import logging
|
||||
import click
|
||||
import io
|
||||
from os.path import expanduser
|
||||
from .namedqueries import namedqueries
|
||||
from . import export
|
||||
from .main import special_command
|
||||
@ -66,6 +68,11 @@ def open_external_editor(filename=None, sql=''):
|
||||
|
||||
return (query, message)
|
||||
|
||||
def read_from_file(path):
|
||||
with io.open(expanduser(path), encoding='utf-8') as f:
|
||||
contents = f.read()
|
||||
return contents
|
||||
|
||||
@special_command('\\n', '\\n[+] [name]', 'List or execute named queries.')
|
||||
def execute_named_query(cur, pattern, **_):
|
||||
"""Returns (title, rows, headers, status)"""
|
||||
|
@ -1,7 +1,6 @@
|
||||
Feature: manipulate tables:
|
||||
create, insert, update, select, delete from, drop
|
||||
|
||||
@wip
|
||||
Scenario: create, insert, select from, update, drop table
|
||||
Given we have pgcli installed
|
||||
when we run pgcli
|
||||
|
@ -16,6 +16,7 @@ def before_all(context):
|
||||
os.environ['LINES'] = "100"
|
||||
os.environ['COLUMNS'] = "100"
|
||||
os.environ['PAGER'] = 'cat'
|
||||
os.environ['EDITOR'] = 'nano'
|
||||
|
||||
context.exit_sent = False
|
||||
|
||||
@ -30,6 +31,7 @@ def before_all(context):
|
||||
'pass': context.config.userdata.get('pg_test_pass', None),
|
||||
'dbname': db_name_full,
|
||||
'dbname_tmp': db_name_full + '_tmp',
|
||||
'vi': vi
|
||||
}
|
||||
|
||||
# Store old env vars.
|
||||
@ -84,4 +86,4 @@ def after_scenario(context, _):
|
||||
if hasattr(context, 'cli') and not context.exit_sent:
|
||||
# Send Ctrl + D into cli
|
||||
context.cli.sendcontrol('d')
|
||||
context.cli.expect(pexpect.EOF)
|
||||
context.cli.expect(pexpect.EOF, timeout=5)
|
||||
|
11
tests/features/iocommands.feature
Normal file
11
tests/features/iocommands.feature
Normal file
@ -0,0 +1,11 @@
|
||||
Feature: I/O commands
|
||||
|
||||
@wip
|
||||
Scenario: edit sql in file with external editor
|
||||
Given we have pgcli installed
|
||||
when we run pgcli
|
||||
and we wait for prompt
|
||||
and we start external editor providing a file name
|
||||
and we type sql in the editor
|
||||
and we exit the editor
|
||||
then we see the sql in prompt
|
@ -8,6 +8,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import pip
|
||||
import pexpect
|
||||
import os
|
||||
|
||||
from behave import given, when, then
|
||||
|
||||
@ -133,6 +134,42 @@ def step_db_connect_test(context):
|
||||
context.cli.sendline('\connect {0}'.format(db_name))
|
||||
|
||||
|
||||
@when('we start external editor providing a file name')
|
||||
def step_edit_file(context):
|
||||
"""
|
||||
Edit file with external editor.
|
||||
"""
|
||||
context.editor_file_name = 'test_file_{0}.sql'.format(context.conf['vi'])
|
||||
if os.path.exists(context.editor_file_name):
|
||||
os.remove(context.editor_file_name)
|
||||
context.cli.sendline('\e {0}'.format(context.editor_file_name))
|
||||
context.cli.expect_exact('nano', timeout=2)
|
||||
|
||||
|
||||
@when('we type sql in the editor')
|
||||
def step_edit_type_sql(context):
|
||||
context.cli.sendline('select * from abc')
|
||||
# Write the file.
|
||||
context.cli.sendcontrol('o')
|
||||
# Confirm file name sending "enter".
|
||||
context.cli.sendcontrol('m')
|
||||
|
||||
|
||||
@when('we exit the editor')
|
||||
def step_edit_quit(context):
|
||||
context.cli.sendcontrol('x')
|
||||
|
||||
|
||||
@then('we see the sql in prompt')
|
||||
def step_edit_done_sql(context):
|
||||
context.cli.expect_exact('select * from abc', timeout=2)
|
||||
# Cleanup the command line.
|
||||
context.cli.sendcontrol('u')
|
||||
# Cleanup the edited file.
|
||||
if context.editor_file_name and os.path.exists(context.editor_file_name):
|
||||
os.remove(context.editor_file_name)
|
||||
|
||||
|
||||
@when('we connect to postgres')
|
||||
def step_db_connect_postgres(context):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user