From e599da6308b348fe843c533da97e3d0cc4215952 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 6 Feb 2017 18:56:50 +0000 Subject: [PATCH] assertDsnEqual moved as TestSuite method --- tests/test_async_keyword.py | 12 ++++++------ tests/test_connection.py | 10 +++++----- tests/test_module.py | 14 +++++++------- tests/testutils.py | 11 +++++++---- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/tests/test_async_keyword.py b/tests/test_async_keyword.py index 3b20e8d6..37a61dbd 100755 --- a/tests/test_async_keyword.py +++ b/tests/test_async_keyword.py @@ -27,8 +27,8 @@ import psycopg2 from psycopg2 import extras from testconfig import dsn -from testutils import (ConnectingTestCase, unittest, skip_before_postgres, - assertDsnEqual) +from testutils import ConnectingTestCase, unittest, skip_before_postgres + from test_replication import ReplicationTestCase, skip_repl_if_green from psycopg2.extras import LogicalReplicationConnection, StopReplication @@ -143,23 +143,23 @@ class ConnectTestCase(unittest.TestCase): pass psycopg2.connect(database='foo', host='baz', connection_factory=f) - assertDsnEqual(self, self.args[0], 'dbname=foo host=baz') + self.assertDsnEqual(self.args[0], 'dbname=foo host=baz') self.assertEqual(self.args[1], f) self.assertEqual(self.args[2], False) psycopg2.connect("dbname=foo host=baz", connection_factory=f) - assertDsnEqual(self, self.args[0], 'dbname=foo host=baz') + self.assertDsnEqual(self.args[0], 'dbname=foo host=baz') self.assertEqual(self.args[1], f) self.assertEqual(self.args[2], False) def test_async(self): psycopg2.connect(database='foo', host='baz', async=1) - assertDsnEqual(self, self.args[0], 'dbname=foo host=baz') + self.assertDsnEqual(self.args[0], 'dbname=foo host=baz') self.assertEqual(self.args[1], None) self.assert_(self.args[2]) psycopg2.connect("dbname=foo host=baz", async=True) - assertDsnEqual(self, self.args[0], 'dbname=foo host=baz') + self.assertDsnEqual(self.args[0], 'dbname=foo host=baz') self.assertEqual(self.args[1], None) self.assert_(self.args[2]) diff --git a/tests/test_connection.py b/tests/test_connection.py index ea8b8f52..4b72be14 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -33,7 +33,7 @@ import psycopg2.errorcodes from psycopg2 import extensions as ext from testutils import ( - unittest, assertDsnEqual, decorate_all_tests, skip_if_no_superuser, + unittest, decorate_all_tests, skip_if_no_superuser, skip_before_postgres, skip_after_postgres, skip_before_libpq, ConnectingTestCase, skip_if_tpc_disabled, skip_if_windows, slow) @@ -413,7 +413,7 @@ class MakeDsnTestCase(ConnectingTestCase): def test_empty_param(self): dsn = ext.make_dsn(dbname='sony', password='') - assertDsnEqual(self, dsn, "dbname=sony password=''") + self.assertDsnEqual(dsn, "dbname=sony password=''") def test_escape(self): dsn = ext.make_dsn(dbname='hello world') @@ -436,10 +436,10 @@ class MakeDsnTestCase(ConnectingTestCase): def test_params_merging(self): dsn = ext.make_dsn('dbname=foo host=bar', host='baz') - assertDsnEqual(self, dsn, 'dbname=foo host=baz') + self.assertDsnEqual(dsn, 'dbname=foo host=baz') dsn = ext.make_dsn('dbname=foo', user='postgres') - assertDsnEqual(self, dsn, 'dbname=foo user=postgres') + self.assertDsnEqual(dsn, 'dbname=foo user=postgres') def test_no_dsn_munging(self): dsnin = 'dbname=a host=b user=c password=d' @@ -453,7 +453,7 @@ class MakeDsnTestCase(ConnectingTestCase): self.assertEqual(dsn, url) dsn = ext.make_dsn(url, application_name='woot') - assertDsnEqual(self, dsn, + self.assertDsnEqual(dsn, 'dbname=test user=tester password=secret application_name=woot') self.assertRaises(psycopg2.ProgrammingError, diff --git a/tests/test_module.py b/tests/test_module.py index 8b31a09e..2af3c612 100755 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -27,7 +27,7 @@ import sys from subprocess import Popen from testutils import (unittest, skip_before_python, skip_before_postgres, - ConnectingTestCase, skip_copy_if_green, script_to_py3, assertDsnEqual, slow) + ConnectingTestCase, skip_copy_if_green, script_to_py3, slow) import psycopg2 @@ -93,23 +93,23 @@ class ConnectTestCase(unittest.TestCase): pass psycopg2.connect(database='foo', host='baz', connection_factory=f) - assertDsnEqual(self, self.args[0], 'dbname=foo host=baz') + self.assertDsnEqual(self.args[0], 'dbname=foo host=baz') self.assertEqual(self.args[1], f) self.assertEqual(self.args[2], False) psycopg2.connect("dbname=foo host=baz", connection_factory=f) - assertDsnEqual(self, self.args[0], 'dbname=foo host=baz') + self.assertDsnEqual(self.args[0], 'dbname=foo host=baz') self.assertEqual(self.args[1], f) self.assertEqual(self.args[2], False) def test_async(self): psycopg2.connect(database='foo', host='baz', async_=1) - assertDsnEqual(self, self.args[0], 'dbname=foo host=baz') + self.assertDsnEqual(self.args[0], 'dbname=foo host=baz') self.assertEqual(self.args[1], None) self.assert_(self.args[2]) psycopg2.connect("dbname=foo host=baz", async_=True) - assertDsnEqual(self, self.args[0], 'dbname=foo host=baz') + self.assertDsnEqual(self.args[0], 'dbname=foo host=baz') self.assertEqual(self.args[1], None) self.assert_(self.args[2]) @@ -121,7 +121,7 @@ class ConnectTestCase(unittest.TestCase): def test_empty_param(self): psycopg2.connect(database='sony', password='') - assertDsnEqual(self, self.args[0], "dbname=sony password=''") + self.assertDsnEqual(self.args[0], "dbname=sony password=''") def test_escape(self): psycopg2.connect(database='hello world') @@ -144,7 +144,7 @@ class ConnectTestCase(unittest.TestCase): self.assertEqual(self.args[0], 'dbname=bar') psycopg2.connect('dbname=foo', user='postgres') - assertDsnEqual(self, self.args[0], 'dbname=foo user=postgres') + self.assertDsnEqual(self.args[0], 'dbname=foo user=postgres') class ExceptionsTestCase(ConnectingTestCase): diff --git a/tests/testutils.py b/tests/testutils.py index f1c93de4..b32f6a83 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -82,6 +82,13 @@ if (not hasattr(unittest.TestCase, 'assert_') unittest.TestCase.failUnlessEqual = unittest.TestCase.assertEqual +def assertDsnEqual(self, dsn1, dsn2, msg=None): + """Check that two conninfo string have the same content""" + self.assertEqual(set(dsn1.split()), set(dsn2.split()), msg) + +unittest.TestCase.assertDsnEqual = assertDsnEqual + + class ConnectingTestCase(unittest.TestCase): """A test case providing connections for tests. @@ -473,7 +480,3 @@ def slow(f): return self.skipTest("slow test") return f(self) return slow_ - - -def assertDsnEqual(testsuite, dsn1, dsn2): - testsuite.assertEqual(set(dsn1.split()), set(dsn2.split()))