Adding upstream version 4.1.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
5f14fad9bf
commit
be6a09053d
14 changed files with 456 additions and 36 deletions
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
from textwrap import dedent
|
||||
|
||||
import psycopg
|
||||
|
@ -6,7 +7,7 @@ from unittest.mock import patch, MagicMock
|
|||
from pgspecial.main import PGSpecial, NO_QUERY
|
||||
from utils import run, dbtest, requires_json, requires_jsonb
|
||||
|
||||
from pgcli.main import PGCli
|
||||
from pgcli.main import PGCli, exception_formatter as main_exception_formatter
|
||||
from pgcli.packages.parseutils.meta import FunctionMetadata
|
||||
|
||||
|
||||
|
@ -219,8 +220,33 @@ def test_database_list(executor):
|
|||
|
||||
@dbtest
|
||||
def test_invalid_syntax(executor, exception_formatter):
|
||||
result = run(executor, "invalid syntax!", exception_formatter=exception_formatter)
|
||||
result = run(
|
||||
executor,
|
||||
"invalid syntax!",
|
||||
exception_formatter=lambda x: main_exception_formatter(x, verbose_errors=False),
|
||||
)
|
||||
assert 'syntax error at or near "invalid"' in result[0]
|
||||
assert "SQLSTATE" not in result[0]
|
||||
|
||||
|
||||
@dbtest
|
||||
def test_invalid_syntax_verbose(executor):
|
||||
result = run(
|
||||
executor,
|
||||
"invalid syntax!",
|
||||
exception_formatter=lambda x: main_exception_formatter(x, verbose_errors=True),
|
||||
)
|
||||
fields = r"""
|
||||
Severity: ERROR
|
||||
Severity \(non-localized\): ERROR
|
||||
SQLSTATE code: 42601
|
||||
Message: syntax error at or near "invalid"
|
||||
Position: 1
|
||||
File: scan\.l
|
||||
Line: \d+
|
||||
Routine: scanner_yyerror
|
||||
""".strip()
|
||||
assert re.search(fields, result[0])
|
||||
|
||||
|
||||
@dbtest
|
||||
|
@ -690,6 +716,38 @@ def test_function_definition(executor):
|
|||
result = executor.function_definition("the_number_three")
|
||||
|
||||
|
||||
@dbtest
|
||||
def test_function_notice_order(executor):
|
||||
run(
|
||||
executor,
|
||||
"""
|
||||
CREATE OR REPLACE FUNCTION demo_order() RETURNS VOID AS
|
||||
$$
|
||||
BEGIN
|
||||
RAISE NOTICE 'first';
|
||||
RAISE NOTICE 'second';
|
||||
RAISE NOTICE 'third';
|
||||
RAISE NOTICE 'fourth';
|
||||
RAISE NOTICE 'fifth';
|
||||
RAISE NOTICE 'sixth';
|
||||
END;
|
||||
$$
|
||||
LANGUAGE plpgsql;
|
||||
""",
|
||||
)
|
||||
|
||||
executor.function_definition("demo_order")
|
||||
|
||||
result = run(executor, "select demo_order()")
|
||||
assert "first\nsecond\nthird\nfourth\nfifth\nsixth" in result[0]
|
||||
assert "+------------+" in result[1]
|
||||
assert "| demo_order |" in result[2]
|
||||
assert "|------------|" in result[3]
|
||||
assert "| |" in result[4]
|
||||
assert "+------------+" in result[5]
|
||||
assert "SELECT 1" in result[6]
|
||||
|
||||
|
||||
@dbtest
|
||||
def test_view_definition(executor):
|
||||
run(executor, "create table tbl1 (a text, b numeric)")
|
||||
|
@ -721,6 +779,10 @@ def test_short_host(executor):
|
|||
executor, "host", "localhost1.example.org,localhost2.example.org"
|
||||
):
|
||||
assert executor.short_host == "localhost1"
|
||||
with patch.object(executor, "host", "ec2-11-222-333-444.compute-1.amazonaws.com"):
|
||||
assert executor.short_host == "ec2-11-222-333-444"
|
||||
with patch.object(executor, "host", "1.2.3.4"):
|
||||
assert executor.short_host == "1.2.3.4"
|
||||
|
||||
|
||||
class VirtualCursor:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue