@@ -210,10 +210,10 @@ def test_restart(self):
210
210
211
211
# restart, ok
212
212
res = node .execute ('select 1' )
213
- self . assertEqual (res , [(1 , )])
213
+ assert (res == [(1 , )])
214
214
node .restart ()
215
215
res = node .execute ('select 2' )
216
- self . assertEqual (res , [(2 , )])
216
+ assert (res == [(2 , )])
217
217
218
218
# restart, fail
219
219
with pytest .raises (expected_exception = StartNodeException ):
@@ -233,7 +233,7 @@ def test_reload(self):
233
233
234
234
# check new value
235
235
cmm_new = node .execute ('show client_min_messages' )
236
- self . assertEqual ('debug1' , cmm_new [0 ][0 ].lower ())
236
+ assert ('debug1' == cmm_new [0 ][0 ].lower ())
237
237
self .assertNotEqual (cmm_old , cmm_new )
238
238
239
239
def test_pg_ctl (self ):
@@ -250,62 +250,62 @@ def test_status(self):
250
250
251
251
# check statuses after each operation
252
252
with get_new_node () as node :
253
- self . assertEqual (node .pid , 0 )
254
- self . assertEqual (node .status (), NodeStatus .Uninitialized )
253
+ assert (node .pid == 0 )
254
+ assert (node .status () == NodeStatus .Uninitialized )
255
255
256
256
node .init ()
257
257
258
- self . assertEqual (node .pid , 0 )
259
- self . assertEqual (node .status (), NodeStatus .Stopped )
258
+ assert (node .pid == 0 )
259
+ assert (node .status () == NodeStatus .Stopped )
260
260
261
261
node .start ()
262
262
263
263
self .assertNotEqual (node .pid , 0 )
264
- self . assertEqual (node .status (), NodeStatus .Running )
264
+ assert (node .status () == NodeStatus .Running )
265
265
266
266
node .stop ()
267
267
268
- self . assertEqual (node .pid , 0 )
269
- self . assertEqual (node .status (), NodeStatus .Stopped )
268
+ assert (node .pid == 0 )
269
+ assert (node .status () == NodeStatus .Stopped )
270
270
271
271
node .cleanup ()
272
272
273
- self . assertEqual (node .pid , 0 )
274
- self . assertEqual (node .status (), NodeStatus .Uninitialized )
273
+ assert (node .pid == 0 )
274
+ assert (node .status () == NodeStatus .Uninitialized )
275
275
276
276
def test_psql (self ):
277
277
with get_new_node ().init ().start () as node :
278
278
279
279
# check returned values (1 arg)
280
280
res = node .psql ('select 1' )
281
- self . assertEqual (rm_carriage_returns (res ), (0 , b'1\n ' , b'' ))
281
+ assert (rm_carriage_returns (res ) == (0 , b'1\n ' , b'' ))
282
282
283
283
# check returned values (2 args)
284
284
res = node .psql ('postgres' , 'select 2' )
285
- self . assertEqual (rm_carriage_returns (res ), (0 , b'2\n ' , b'' ))
285
+ assert (rm_carriage_returns (res ) == (0 , b'2\n ' , b'' ))
286
286
287
287
# check returned values (named)
288
288
res = node .psql (query = 'select 3' , dbname = 'postgres' )
289
- self . assertEqual (rm_carriage_returns (res ), (0 , b'3\n ' , b'' ))
289
+ assert (rm_carriage_returns (res ) == (0 , b'3\n ' , b'' ))
290
290
291
291
# check returned values (1 arg)
292
292
res = node .safe_psql ('select 4' )
293
- self . assertEqual (rm_carriage_returns (res ), b'4\n ' )
293
+ assert (rm_carriage_returns (res ) == b'4\n ' )
294
294
295
295
# check returned values (2 args)
296
296
res = node .safe_psql ('postgres' , 'select 5' )
297
- self . assertEqual (rm_carriage_returns (res ), b'5\n ' )
297
+ assert (rm_carriage_returns (res ) == b'5\n ' )
298
298
299
299
# check returned values (named)
300
300
res = node .safe_psql (query = 'select 6' , dbname = 'postgres' )
301
- self . assertEqual (rm_carriage_returns (res ), b'6\n ' )
301
+ assert (rm_carriage_returns (res ) == b'6\n ' )
302
302
303
303
# check feeding input
304
304
node .safe_psql ('create table horns (w int)' )
305
305
node .safe_psql ('copy horns from stdin (format csv)' ,
306
306
input = b"1\n 2\n 3\n \\ .\n " )
307
307
_sum = node .safe_psql ('select sum(w) from horns' )
308
- self . assertEqual (rm_carriage_returns (_sum ), b'6\n ' )
308
+ assert (rm_carriage_returns (_sum ) == b'6\n ' )
309
309
310
310
# check psql's default args, fails
311
311
with pytest .raises (expected_exception = QueryException ):
@@ -333,7 +333,7 @@ def test_safe_psql__expect_error(self):
333
333
334
334
# ---------
335
335
res = node .safe_psql ("select 1;" , expect_error = False )
336
- self . assertEqual (rm_carriage_returns (res ), b'1\n ' )
336
+ assert (rm_carriage_returns (res ) == b'1\n ' )
337
337
338
338
def test_transactions (self ):
339
339
with get_new_node ().init ().start () as node :
@@ -475,11 +475,11 @@ def test_synchronous_replication(self):
475
475
standby2 .start ()
476
476
477
477
# check formatting
478
- self . assertEqual (
479
- '1 ("{}", "{}")' .format (standby1 .name , standby2 .name ),
478
+ assert (
479
+ '1 ("{}", "{}")' .format (standby1 .name , standby2 .name ) ==
480
480
str (First (1 , (standby1 , standby2 )))) # yapf: disable
481
- self . assertEqual (
482
- 'ANY 1 ("{}", "{}")' .format (standby1 .name , standby2 .name ),
481
+ assert (
482
+ 'ANY 1 ("{}", "{}")' .format (standby1 .name , standby2 .name ) ==
483
483
str (Any (1 , (standby1 , standby2 )))) # yapf: disable
484
484
485
485
# set synchronous_standby_names
@@ -498,7 +498,7 @@ def test_synchronous_replication(self):
498
498
master .safe_psql (
499
499
'insert into abc select generate_series(1, 1000000)' )
500
500
res = standby1 .safe_psql ('select count(*) from abc' )
501
- self . assertEqual (rm_carriage_returns (res ), b'1000000\n ' )
501
+ assert (rm_carriage_returns (res ) == b'1000000\n ' )
502
502
503
503
# @unittest.skipUnless(pg_version_ge('10'), 'requires 10+')
504
504
def test_logical_replication (self ):
@@ -638,7 +638,7 @@ def test_promotion(self):
638
638
# make standby becomes writable master
639
639
replica .safe_psql ('insert into abc values (1)' )
640
640
res = replica .safe_psql ('select * from abc' )
641
- self . assertEqual (rm_carriage_returns (res ), b'1\n ' )
641
+ assert (rm_carriage_returns (res ) == b'1\n ' )
642
642
643
643
def test_dump (self ):
644
644
query_create = 'create table test as select generate_series(1, 2) as val'
@@ -664,7 +664,7 @@ def test_users(self):
664
664
node .psql ('create role test_user login' )
665
665
value = node .safe_psql ('select 1' , username = 'test_user' )
666
666
value = rm_carriage_returns (value )
667
- self . assertEqual (value , b'1\n ' )
667
+ assert (value == b'1\n ' )
668
668
669
669
def test_poll_query_until (self ):
670
670
with get_new_node () as node :
@@ -804,7 +804,7 @@ def test_pg_config(self):
804
804
# check same instances
805
805
a = get_pg_config ()
806
806
b = get_pg_config ()
807
- self . assertEqual (id (a ), id (b ))
807
+ assert (id (a ) == id (b ))
808
808
809
809
# save right before config change
810
810
c1 = get_pg_config ()
@@ -839,7 +839,7 @@ def test_config_stack(self):
839
839
d2 = 'dummy_def'
840
840
841
841
with scoped_config (cached_initdb_dir = d1 ) as c1 :
842
- self . assertEqual (c1 .cached_initdb_dir , d1 )
842
+ assert (c1 .cached_initdb_dir == d1 )
843
843
844
844
with scoped_config (cached_initdb_dir = d2 ) as c2 :
845
845
stack_size = len (testgres .config .config_stack )
@@ -849,12 +849,12 @@ def test_config_stack(self):
849
849
with scoped_config (dummy = True ):
850
850
pass
851
851
852
- self . assertEqual (c2 .cached_initdb_dir , d2 )
853
- self . assertEqual (len (testgres .config .config_stack ), stack_size )
852
+ assert (c2 .cached_initdb_dir == d2 )
853
+ assert (len (testgres .config .config_stack ) == stack_size )
854
854
855
- self . assertEqual (c1 .cached_initdb_dir , d1 )
855
+ assert (c1 .cached_initdb_dir == d1 )
856
856
857
- self . assertEqual (TestgresConfig .cached_initdb_dir , d0 )
857
+ assert (TestgresConfig .cached_initdb_dir == d0 )
858
858
859
859
def test_unix_sockets (self ):
860
860
with get_new_node () as node :
@@ -897,13 +897,13 @@ def test_file_tail(self):
897
897
898
898
f .seek (0 )
899
899
lines = file_tail (f , 3 )
900
- self . assertEqual (lines [0 ], s1 )
901
- self . assertEqual (lines [1 ], s2 )
902
- self . assertEqual (lines [2 ], s3 )
900
+ assert (lines [0 ] == s1 )
901
+ assert (lines [1 ] == s2 )
902
+ assert (lines [2 ] == s3 )
903
903
904
904
f .seek (0 )
905
905
lines = file_tail (f , 1 )
906
- self . assertEqual (lines [0 ], s3 )
906
+ assert (lines [0 ] == s3 )
907
907
908
908
def test_isolation_levels (self ):
909
909
with get_new_node ().init ().start () as node :
@@ -926,19 +926,19 @@ def test_isolation_levels(self):
926
926
927
927
def test_ports_management (self ):
928
928
# check that no ports have been bound yet
929
- self . assertEqual (len (bound_ports ), 0 )
929
+ assert (len (bound_ports ) == 0 )
930
930
931
931
with get_new_node () as node :
932
932
# check that we've just bound a port
933
- self . assertEqual (len (bound_ports ), 1 )
933
+ assert (len (bound_ports ) == 1 )
934
934
935
935
# check that bound_ports contains our port
936
936
port_1 = list (bound_ports )[0 ]
937
937
port_2 = node .port
938
- self . assertEqual (port_1 , port_2 )
938
+ assert (port_1 == port_2 )
939
939
940
940
# check that port has been freed successfully
941
- self . assertEqual (len (bound_ports ), 0 )
941
+ assert (len (bound_ports ) == 0 )
942
942
943
943
def test_exceptions (self ):
944
944
str (StartNodeException ('msg' , [('file' , 'lines' )]))
@@ -972,7 +972,7 @@ def test_version_management(self):
972
972
with get_new_node () as node :
973
973
assert (isinstance (version , six .string_types ))
974
974
assert (isinstance (node .version , PgVer ))
975
- self . assertEqual (node .version , PgVer (version ))
975
+ assert (node .version == PgVer (version ))
976
976
977
977
def test_child_pids (self ):
978
978
master_processes = [
@@ -1018,10 +1018,10 @@ def test_child_pids(self):
1018
1018
self .assertIn (ptype , replica_pids )
1019
1019
1020
1020
# there should be exactly 1 source walsender for replica
1021
- self . assertEqual (len (master_pids [ProcessType .WalSender ]), 1 )
1021
+ assert (len (master_pids [ProcessType .WalSender ]) == 1 )
1022
1022
pid1 = master_pids [ProcessType .WalSender ][0 ]
1023
1023
pid2 = replica .source_walsender .pid
1024
- self . assertEqual (pid1 , pid2 )
1024
+ assert (pid1 == pid2 )
1025
1025
1026
1026
replica .stop ()
1027
1027
@@ -1034,7 +1034,7 @@ def test_child_process_dies(self):
1034
1034
cmd = ["timeout" , "60" ] if os .name == 'nt' else ["sleep" , "60" ]
1035
1035
1036
1036
with subprocess .Popen (cmd , shell = True ) as process : # shell=True might be needed on Windows
1037
- self . assertEqual (process .poll (), None )
1037
+ assert (process .poll () == None )
1038
1038
# collect list of processes currently running
1039
1039
children = psutil .Process (os .getpid ()).children ()
1040
1040
# kill a process, so received children dictionary becomes invalid
@@ -1070,13 +1070,13 @@ def test_the_same_port(self):
1070
1070
with get_new_node () as node :
1071
1071
node .init ().start ()
1072
1072
assert (node ._should_free_port )
1073
- self . assertEqual (type (node .port ), int )
1073
+ assert (type (node .port ) == int )
1074
1074
node_port_copy = node .port
1075
- self . assertEqual (rm_carriage_returns (node .safe_psql ("SELECT 1;" )), b'1\n ' )
1075
+ assert (rm_carriage_returns (node .safe_psql ("SELECT 1;" )) == b'1\n ' )
1076
1076
1077
1077
with get_new_node (port = node .port ) as node2 :
1078
- self . assertEqual (type (node2 .port ), int )
1079
- self . assertEqual (node2 .port , node .port )
1078
+ assert (type (node2 .port ) == int )
1079
+ assert (node2 .port == node .port )
1080
1080
assert not (node2 ._should_free_port )
1081
1081
1082
1082
with pytest .raises (
@@ -1086,9 +1086,9 @@ def test_the_same_port(self):
1086
1086
node2 .init ().start ()
1087
1087
1088
1088
# node is still working
1089
- self . assertEqual (node .port , node_port_copy )
1089
+ assert (node .port == node_port_copy )
1090
1090
assert (node ._should_free_port )
1091
- self . assertEqual (rm_carriage_returns (node .safe_psql ("SELECT 3;" )), b'3\n ' )
1091
+ assert (rm_carriage_returns (node .safe_psql ("SELECT 3;" )) == b'3\n ' )
1092
1092
1093
1093
class tagPortManagerProxy :
1094
1094
sm_prev_testgres_reserve_port = None
@@ -1194,30 +1194,30 @@ def test_port_rereserve_during_node_start(self):
1194
1194
with get_new_node () as node1 :
1195
1195
node1 .init ().start ()
1196
1196
assert (node1 ._should_free_port )
1197
- self . assertEqual (type (node1 .port ), int ) # noqa: E721
1197
+ assert (type (node1 .port ) == int ) # noqa: E721
1198
1198
node1_port_copy = node1 .port
1199
- self . assertEqual (rm_carriage_returns (node1 .safe_psql ("SELECT 1;" )), b'1\n ' )
1199
+ assert (rm_carriage_returns (node1 .safe_psql ("SELECT 1;" )) == b'1\n ' )
1200
1200
1201
1201
with __class__ .tagPortManagerProxy (node1 .port , C_COUNT_OF_BAD_PORT_USAGE ):
1202
1202
assert __class__ .tagPortManagerProxy .sm_DummyPortNumber == node1 .port
1203
1203
with get_new_node () as node2 :
1204
1204
assert (node2 ._should_free_port )
1205
- self . assertEqual (node2 .port , node1 .port )
1205
+ assert (node2 .port == node1 .port )
1206
1206
1207
1207
node2 .init ().start ()
1208
1208
1209
1209
self .assertNotEqual (node2 .port , node1 .port )
1210
1210
assert (node2 ._should_free_port )
1211
- self . assertEqual (__class__ .tagPortManagerProxy .sm_DummyPortCurrentUsage , 0 )
1212
- self . assertEqual (__class__ .tagPortManagerProxy .sm_DummyPortTotalUsage , C_COUNT_OF_BAD_PORT_USAGE )
1211
+ assert (__class__ .tagPortManagerProxy .sm_DummyPortCurrentUsage == 0 )
1212
+ assert (__class__ .tagPortManagerProxy .sm_DummyPortTotalUsage == C_COUNT_OF_BAD_PORT_USAGE )
1213
1213
assert (node2 .is_started )
1214
1214
1215
- self . assertEqual (rm_carriage_returns (node2 .safe_psql ("SELECT 2;" )), b'2\n ' )
1215
+ assert (rm_carriage_returns (node2 .safe_psql ("SELECT 2;" )) == b'2\n ' )
1216
1216
1217
1217
# node1 is still working
1218
- self . assertEqual (node1 .port , node1_port_copy )
1218
+ assert (node1 .port == node1_port_copy )
1219
1219
assert (node1 ._should_free_port )
1220
- self . assertEqual (rm_carriage_returns (node1 .safe_psql ("SELECT 3;" )), b'3\n ' )
1220
+ assert (rm_carriage_returns (node1 .safe_psql ("SELECT 3;" )) == b'3\n ' )
1221
1221
1222
1222
def test_port_conflict (self ):
1223
1223
assert testgres .PostgresNode ._C_MAX_START_ATEMPTS > 1
@@ -1227,35 +1227,35 @@ def test_port_conflict(self):
1227
1227
with get_new_node () as node1 :
1228
1228
node1 .init ().start ()
1229
1229
assert (node1 ._should_free_port )
1230
- self . assertEqual (type (node1 .port ), int ) # noqa: E721
1230
+ assert (type (node1 .port ) == int ) # noqa: E721
1231
1231
node1_port_copy = node1 .port
1232
- self . assertEqual (rm_carriage_returns (node1 .safe_psql ("SELECT 1;" )), b'1\n ' )
1232
+ assert (rm_carriage_returns (node1 .safe_psql ("SELECT 1;" )) == b'1\n ' )
1233
1233
1234
1234
with __class__ .tagPortManagerProxy (node1 .port , C_COUNT_OF_BAD_PORT_USAGE ):
1235
1235
assert __class__ .tagPortManagerProxy .sm_DummyPortNumber == node1 .port
1236
1236
with get_new_node () as node2 :
1237
1237
assert (node2 ._should_free_port )
1238
- self . assertEqual (node2 .port , node1 .port )
1238
+ assert (node2 .port == node1 .port )
1239
1239
1240
1240
with pytest .raises (
1241
1241
expected_exception = StartNodeException ,
1242
1242
match = re .escape ("Cannot start node after multiple attempts" )
1243
1243
):
1244
1244
node2 .init ().start ()
1245
1245
1246
- self . assertEqual (node2 .port , node1 .port )
1246
+ assert (node2 .port == node1 .port )
1247
1247
assert (node2 ._should_free_port )
1248
- self . assertEqual (__class__ .tagPortManagerProxy .sm_DummyPortCurrentUsage , 1 )
1249
- self . assertEqual (__class__ .tagPortManagerProxy .sm_DummyPortTotalUsage , C_COUNT_OF_BAD_PORT_USAGE )
1248
+ assert (__class__ .tagPortManagerProxy .sm_DummyPortCurrentUsage == 1 )
1249
+ assert (__class__ .tagPortManagerProxy .sm_DummyPortTotalUsage == C_COUNT_OF_BAD_PORT_USAGE )
1250
1250
assert not (node2 .is_started )
1251
1251
1252
1252
# node2 must release our dummyPort (node1.port)
1253
- self . assertEqual (__class__ .tagPortManagerProxy .sm_DummyPortCurrentUsage , 0 )
1253
+ assert (__class__ .tagPortManagerProxy .sm_DummyPortCurrentUsage == 0 )
1254
1254
1255
1255
# node1 is still working
1256
- self . assertEqual (node1 .port , node1_port_copy )
1256
+ assert (node1 .port == node1_port_copy )
1257
1257
assert (node1 ._should_free_port )
1258
- self . assertEqual (rm_carriage_returns (node1 .safe_psql ("SELECT 3;" )), b'3\n ' )
1258
+ assert (rm_carriage_returns (node1 .safe_psql ("SELECT 3;" )) == b'3\n ' )
1259
1259
1260
1260
def test_simple_with_bin_dir (self ):
1261
1261
with get_new_node () as node :
0 commit comments