Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a8e57ae

Browse files
Using pytest [assertListEqual]
1 parent 4afbe00 commit a8e57ae

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

tests/test_simple.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,12 @@ def test_transactions(self):
347347
con.begin()
348348
con.execute('insert into test values (2)')
349349
res = con.execute('select * from test order by val asc')
350-
self.assertListEqual(res, [(1, ), (2, )])
350+
assert (res == [(1, ), (2, )])
351351
con.rollback()
352352

353353
con.begin()
354354
res = con.execute('select * from test')
355-
self.assertListEqual(res, [(1, )])
355+
assert (res == [(1, )])
356356
con.rollback()
357357

358358
con.begin()
@@ -392,7 +392,7 @@ def test_backup_simple(self):
392392
with master.backup(xlog_method='stream') as backup:
393393
with backup.spawn_primary().start() as slave:
394394
res = slave.execute('select * from test order by i asc')
395-
self.assertListEqual(res, [(1, ), (2, ), (3, ), (4, )])
395+
assert (res == [(1, ), (2, ), (3, ), (4, )])
396396

397397
def test_backup_multiple(self):
398398
with get_new_node() as node:
@@ -448,14 +448,14 @@ def test_replicate(self):
448448

449449
with node.replicate().start() as replica:
450450
res = replica.execute('select 1')
451-
self.assertListEqual(res, [(1, )])
451+
assert (res == [(1, )])
452452

453453
node.execute('create table test (val int)', commit=True)
454454

455455
replica.catchup()
456456

457457
res = node.execute('select * from test')
458-
self.assertListEqual(res, [])
458+
assert (res == [])
459459

460460
# @unittest.skipUnless(pg_version_ge('9.6'), 'requires 9.6+')
461461
def test_synchronous_replication(self):
@@ -522,7 +522,7 @@ def test_logical_replication(self):
522522
# wait until changes apply on subscriber and check them
523523
sub.catchup()
524524
res = node2.execute('select * from test')
525-
self.assertListEqual(res, [(1, 1), (2, 2)])
525+
assert (res == [(1, 1), (2, 2)])
526526

527527
# disable and put some new data
528528
sub.disable()
@@ -532,7 +532,7 @@ def test_logical_replication(self):
532532
sub.enable()
533533
sub.catchup()
534534
res = node2.execute('select * from test')
535-
self.assertListEqual(res, [(1, 1), (2, 2), (3, 3)])
535+
assert (res == [(1, 1), (2, 2), (3, 3)])
536536

537537
# Add new tables. Since we added "all tables" to publication
538538
# (default behaviour of publish() method) we don't need
@@ -546,7 +546,7 @@ def test_logical_replication(self):
546546
node1.safe_psql('insert into test2 values (\'a\'), (\'b\')')
547547
sub.catchup()
548548
res = node2.execute('select * from test2')
549-
self.assertListEqual(res, [('a', ), ('b', )])
549+
assert (res == [('a', ), ('b', )])
550550

551551
# drop subscription
552552
sub.drop()
@@ -560,7 +560,7 @@ def test_logical_replication(self):
560560
node1.safe_psql('insert into test values (4, 4)')
561561
sub.catchup()
562562
res = node2.execute('select * from test')
563-
self.assertListEqual(res, [(1, 1), (2, 2), (3, 3), (4, 4)])
563+
assert (res == [(1, 1), (2, 2), (3, 3), (4, 4)])
564564

565565
# explicitly add table
566566
with pytest.raises(expected_exception=ValueError):
@@ -569,7 +569,7 @@ def test_logical_replication(self):
569569
node1.safe_psql('insert into test2 values (\'c\')')
570570
sub.catchup()
571571
res = node2.execute('select * from test2')
572-
self.assertListEqual(res, [('a', ), ('b', )])
572+
assert (res == [('a', ), ('b', )])
573573

574574
# @unittest.skipUnless(pg_version_ge('10'), 'requires 10+')
575575
def test_logical_catchup(self):
@@ -593,10 +593,7 @@ def test_logical_catchup(self):
593593
node1.execute('insert into test values ({0}, {0})'.format(i))
594594
sub.catchup()
595595
res = node2.execute('select * from test')
596-
self.assertListEqual(res, [(
597-
i,
598-
i,
599-
)])
596+
assert (res == [(i,i,)])
600597
node1.execute('delete from test')
601598

602599
# @unittest.skipIf(pg_version_ge('10'), 'requires <10')
@@ -657,7 +654,7 @@ def test_dump(self):
657654
# restore dump
658655
node3.restore(filename=dump)
659656
res = node3.execute(query_select)
660-
self.assertListEqual(res, [(1, ), (2, )])
657+
assert (res == [(1, ), (2, )])
661658

662659
def test_users(self):
663660
with get_new_node().init().start() as node:

tests/test_simple_remote.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,12 @@ def test_transactions(self):
402402
con.begin()
403403
con.execute('insert into test values (2)')
404404
res = con.execute('select * from test order by val asc')
405-
self.assertListEqual(res, [(1,), (2,)])
405+
assert (res == [(1,), (2,)])
406406
con.rollback()
407407

408408
con.begin()
409409
res = con.execute('select * from test')
410-
self.assertListEqual(res, [(1,)])
410+
assert (res == [(1,)])
411411
con.rollback()
412412

413413
con.begin()
@@ -445,7 +445,7 @@ def test_backup_simple(self):
445445
with master.backup(xlog_method='stream') as backup:
446446
with backup.spawn_primary().start() as slave:
447447
res = slave.execute('select * from test order by i asc')
448-
self.assertListEqual(res, [(1,), (2,), (3,), (4,)])
448+
assert (res == [(1,), (2,), (3,), (4,)])
449449

450450
def test_backup_multiple(self):
451451
with get_remote_node(conn_params=conn_params) as node:
@@ -501,14 +501,14 @@ def test_replicate(self):
501501

502502
with node.replicate().start() as replica:
503503
res = replica.execute('select 1')
504-
self.assertListEqual(res, [(1,)])
504+
assert (res == [(1,)])
505505

506506
node.execute('create table test (val int)', commit=True)
507507

508508
replica.catchup()
509509

510510
res = node.execute('select * from test')
511-
self.assertListEqual(res, [])
511+
assert (res == [])
512512

513513
# @unittest.skipUnless(pg_version_ge('9.6'), 'requires 9.6+')
514514
def test_synchronous_replication(self):
@@ -575,7 +575,7 @@ def test_logical_replication(self):
575575
# wait until changes apply on subscriber and check them
576576
sub.catchup()
577577
res = node2.execute('select * from test')
578-
self.assertListEqual(res, [(1, 1), (2, 2)])
578+
assert (res == [(1, 1), (2, 2)])
579579

580580
# disable and put some new data
581581
sub.disable()
@@ -585,7 +585,7 @@ def test_logical_replication(self):
585585
sub.enable()
586586
sub.catchup()
587587
res = node2.execute('select * from test')
588-
self.assertListEqual(res, [(1, 1), (2, 2), (3, 3)])
588+
assert (res == [(1, 1), (2, 2), (3, 3)])
589589

590590
# Add new tables. Since we added "all tables" to publication
591591
# (default behaviour of publish() method) we don't need
@@ -599,7 +599,7 @@ def test_logical_replication(self):
599599
node1.safe_psql('insert into test2 values (\'a\'), (\'b\')')
600600
sub.catchup()
601601
res = node2.execute('select * from test2')
602-
self.assertListEqual(res, [('a',), ('b',)])
602+
assert (res == [('a',), ('b',)])
603603

604604
# drop subscription
605605
sub.drop()
@@ -613,7 +613,7 @@ def test_logical_replication(self):
613613
node1.safe_psql('insert into test values (4, 4)')
614614
sub.catchup()
615615
res = node2.execute('select * from test')
616-
self.assertListEqual(res, [(1, 1), (2, 2), (3, 3), (4, 4)])
616+
assert (res == [(1, 1), (2, 2), (3, 3), (4, 4)])
617617

618618
# explicitly add table
619619
with pytest.raises(expected_exception=ValueError):
@@ -622,7 +622,7 @@ def test_logical_replication(self):
622622
node1.safe_psql('insert into test2 values (\'c\')')
623623
sub.catchup()
624624
res = node2.execute('select * from test2')
625-
self.assertListEqual(res, [('a',), ('b',)])
625+
assert (res == [('a',), ('b',)])
626626

627627
# @unittest.skipUnless(pg_version_ge('10'), 'requires 10+')
628628
def test_logical_catchup(self):
@@ -646,10 +646,7 @@ def test_logical_catchup(self):
646646
node1.execute('insert into test values ({0}, {0})'.format(i))
647647
sub.catchup()
648648
res = node2.execute('select * from test')
649-
self.assertListEqual(res, [(
650-
i,
651-
i,
652-
)])
649+
assert (res == [(i,i,)])
653650
node1.execute('delete from test')
654651

655652
# @unittest.skipIf(pg_version_ge('10'), 'requires <10')
@@ -710,7 +707,7 @@ def test_dump(self):
710707
# restore dump
711708
node3.restore(filename=dump)
712709
res = node3.execute(query_select)
713-
self.assertListEqual(res, [(1,), (2,)])
710+
assert (res == [(1,), (2,)])
714711

715712
def test_users(self):
716713
with get_remote_node(conn_params=conn_params).init().start() as node:

0 commit comments

Comments
 (0)