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

Commitf848a63

Browse files
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.
1 parent45b8dc0 commitf848a63

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

‎testgres/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
CatchUpException, \
2424
StartNodeException, \
2525
InitNodeException, \
26-
BackupException
26+
BackupException, \
27+
InvalidOperationException
2728

2829
from .enumsimport \
2930
XLogMethod, \

‎testgres/exceptions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,6 @@ class InitNodeException(TestgresException):
103103

104104
classBackupException(TestgresException):
105105
pass
106+
107+
classInvalidOperationException(TestgresException):
108+
pass

‎testgres/node.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
TimeoutException, \
7474
InitNodeException, \
7575
TestgresException, \
76-
BackupException
76+
BackupException, \
77+
InvalidOperationException
7778

7879
from .loggerimportTestgresLogger
7980

@@ -1089,7 +1090,7 @@ def safe_psql(self, query=None, expect_error=False, **kwargs):
10891090
returne.error
10901091

10911092
ifexpect_error:
1092-
assertFalse,"Exception was expected, but query finished successfully: `{}`".format(query)
1093+
raiseInvalidOperationException("Exception was expected, but query finished successfully: `{}`.".format(query))
10931094

10941095
returnout
10951096

‎tests/test_simple.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
BackupException, \
2424
QueryException, \
2525
TimeoutException, \
26-
TestgresException,NodeApp
26+
TestgresException, \
27+
InvalidOperationException, \
28+
NodeApp
2729

2830
fromtestgresimport \
2931
TestgresConfig, \
@@ -310,6 +312,23 @@ def test_psql(self):
310312
withself.assertRaises(QueryException):
311313
node.safe_psql('select 1')
312314

315+
deftest_safe_psql__expect_error(self):
316+
withget_new_node().init().start()asnode:
317+
err=node.safe_psql('select_or_not_select 1',expect_error=True)
318+
self.assertTrue(type(err)==str)# noqa: E721
319+
self.assertIn('select_or_not_select',err)
320+
self.assertIn('ERROR: syntax error at or near "select_or_not_select"',err)
321+
322+
# ---------
323+
withself.assertRaises(InvalidOperationException)asctx:
324+
node.safe_psql("select 1;",expect_error=True)
325+
326+
self.assertEqual(str(ctx.exception),"Exception was expected, but query finished successfully: `select 1;`.")
327+
328+
# ---------
329+
res=node.safe_psql("select 1;",expect_error=False)
330+
self.assertEqual(res,b'1\n')
331+
313332
deftest_transactions(self):
314333
withget_new_node().init().start()asnode:
315334

‎tests/test_simple_remote.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
BackupException, \
2424
QueryException, \
2525
TimeoutException, \
26-
TestgresException
26+
TestgresException, \
27+
InvalidOperationException
2728

2829
fromtestgres.configimport \
2930
TestgresConfig, \
@@ -295,6 +296,23 @@ def test_psql(self):
295296
withself.assertRaises(QueryException):
296297
node.safe_psql('select 1')
297298

299+
deftest_safe_psql__expect_error(self):
300+
withget_remote_node(conn_params=conn_params).init().start()asnode:
301+
err=node.safe_psql('select_or_not_select 1',expect_error=True)
302+
self.assertTrue(type(err)==str)# noqa: E721
303+
self.assertIn('select_or_not_select',err)
304+
self.assertIn('ERROR: syntax error at or near "select_or_not_select"',err)
305+
306+
# ---------
307+
withself.assertRaises(InvalidOperationException)asctx:
308+
node.safe_psql("select 1;",expect_error=True)
309+
310+
self.assertEqual(str(ctx.exception),"Exception was expected, but query finished successfully: `select 1;`.")
311+
312+
# ---------
313+
res=node.safe_psql("select 1;",expect_error=False)
314+
self.assertEqual(res,b'1\n')
315+
298316
deftest_transactions(self):
299317
withget_remote_node(conn_params=conn_params).init().start()asnode:
300318
withnode.connect()ascon:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp