Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Proposal to fix #154 (v2)#161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
f9ddd04
Proposal to fix #154 (v2)
dmitry-lipetskDec 8, 2024
2bb38dc
[BUG FIX] PostgresNode::safe_psql did not respect "expect_error" para…
dmitry-lipetskDec 9, 2024
45b8dc0
[BUG FIX] A problem in psql/safe_psql and 'input' data was fixed [loc…
dmitry-lipetskDec 9, 2024
f848a63
PostgresNode::safe_psql raises InvalidOperationException
dmitry-lipetskDec 9, 2024
db0744e
A problem with InvalidOperationException and flake8 is fixed
dmitry-lipetskDec 9, 2024
5bb1510
A code style is fixed [flake8]
dmitry-lipetskDec 9, 2024
31c7bce
[BUG FIX] Wrappers for psql use subprocess.PIPE for stdout and stderr
dmitry-lipetskDec 9, 2024
b013801
[BUG FIX] TestgresTests::test_safe_psql__expect_error uses rm_carriag…
dmitry-lipetskDec 9, 2024
c49ee4c
node.py is updated [formatting]
dmitry-lipetskDec 10, 2024
6a0e714
Formatting
dmitry-lipetskDec 10, 2024
3cc19d2
raise_error.py is moved into testgres/operations from testgres/helpers
dmitry-lipetskDec 10, 2024
7b70e9e
Helpers.GetDefaultEncoding is added
dmitry-lipetskDec 10, 2024
cd0b5f8
Code normalization
dmitry-lipetskDec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
PostgresNode::safe_psql raises InvalidOperationException
If expect_error is True and no error is detected, safe_psql raises InvalidOperationException exception.Tests (local, remote) are added.
  • Loading branch information
@dmitry-lipetsk
dmitry-lipetsk committedDec 9, 2024
commitf848a63fd3dce4a50d1a994f2b5ee1ce9e15a7b6
3 changes: 2 additions & 1 deletiontestgres/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,8 @@
CatchUpException, \
StartNodeException, \
InitNodeException, \
BackupException
BackupException, \
InvalidOperationException

from .enums import \
XLogMethod, \
Expand Down
3 changes: 3 additions & 0 deletionstestgres/exceptions.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,3 +103,6 @@ class InitNodeException(TestgresException):

class BackupException(TestgresException):
pass

class InvalidOperationException(TestgresException):
pass
5 changes: 3 additions & 2 deletionstestgres/node.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -73,7 +73,8 @@
TimeoutException, \
InitNodeException, \
TestgresException, \
BackupException
BackupException, \
InvalidOperationException

from .logger import TestgresLogger

Expand DownExpand Up@@ -1089,7 +1090,7 @@ def safe_psql(self, query=None, expect_error=False, **kwargs):
return e.error

if expect_error:
assert False,"Exception was expected, but query finished successfully: `{}`".format(query)
raise InvalidOperationException("Exception was expected, but query finished successfully: `{}`.".format(query))

return out

Expand Down
21 changes: 20 additions & 1 deletiontests/test_simple.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,9 @@
BackupException, \
QueryException, \
TimeoutException, \
TestgresException, NodeApp
TestgresException, \
InvalidOperationException, \
NodeApp

from testgres import \
TestgresConfig, \
Expand DownExpand Up@@ -310,6 +312,23 @@ def test_psql(self):
with self.assertRaises(QueryException):
node.safe_psql('select 1')

def test_safe_psql__expect_error(self):
with get_new_node().init().start() as node:
err = node.safe_psql('select_or_not_select 1', expect_error=True)
self.assertTrue(type(err) == str) # noqa: E721
self.assertIn('select_or_not_select', err)
self.assertIn('ERROR: syntax error at or near "select_or_not_select"', err)

# ---------
with self.assertRaises(InvalidOperationException) as ctx:
node.safe_psql("select 1;", expect_error=True)

self.assertEqual(str(ctx.exception), "Exception was expected, but query finished successfully: `select 1;`.")

# ---------
res = node.safe_psql("select 1;", expect_error=False)
self.assertEqual(res, b'1\n')

def test_transactions(self):
with get_new_node().init().start() as node:

Expand Down
20 changes: 19 additions & 1 deletiontests/test_simple_remote.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,8 @@
BackupException, \
QueryException, \
TimeoutException, \
TestgresException
TestgresException, \
InvalidOperationException

from testgres.config import \
TestgresConfig, \
Expand DownExpand Up@@ -295,6 +296,23 @@ def test_psql(self):
with self.assertRaises(QueryException):
node.safe_psql('select 1')

def test_safe_psql__expect_error(self):
with get_remote_node(conn_params=conn_params).init().start() as node:
err = node.safe_psql('select_or_not_select 1', expect_error=True)
self.assertTrue(type(err) == str) # noqa: E721
self.assertIn('select_or_not_select', err)
self.assertIn('ERROR: syntax error at or near "select_or_not_select"', err)

# ---------
with self.assertRaises(InvalidOperationException) as ctx:
node.safe_psql("select 1;", expect_error=True)

self.assertEqual(str(ctx.exception), "Exception was expected, but query finished successfully: `select 1;`.")

# ---------
res = node.safe_psql("select 1;", expect_error=False)
self.assertEqual(res, b'1\n')

def test_transactions(self):
with get_remote_node(conn_params=conn_params).init().start() as node:
with node.connect() as con:
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp