diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 13:21:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 13:21:43 +0000 |
commit | 98038631ba9672eafb28f518ff30db76d5954d81 (patch) | |
tree | 01c930bf54ae05bd6fb271c7161086f0eaf4da47 /tests/test_pgexecute.py | |
parent | Adding upstream version 4.0.1. (diff) | |
download | pgcli-98038631ba9672eafb28f518ff30db76d5954d81.tar.xz pgcli-98038631ba9672eafb28f518ff30db76d5954d81.zip |
Adding upstream version 4.1.0.upstream/4.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_pgexecute.py')
-rw-r--r-- | tests/test_pgexecute.py | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/tests/test_pgexecute.py b/tests/test_pgexecute.py index 636795b..f1cadfd 100644 --- a/tests/test_pgexecute.py +++ b/tests/test_pgexecute.py @@ -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 @@ -691,6 +717,38 @@ def test_function_definition(executor): @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)") run(executor, "create view vw1 AS SELECT * FROM tbl1") @@ -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: |