Author: cito Date: Sat Jan 2 18:25:14 2016 New Revision: 690 Log: Amend tests so that they can run with PostgreSQL < 9.0
Note that we do not need to make these amendments in the trunk, because we assume PostgreSQL >= 9.0 for PyGreSQL version 5.0. Modified: branches/4.x/module/pg.py branches/4.x/module/setup.py branches/4.x/module/tests/test_classic.py branches/4.x/module/tests/test_classic_connection.py branches/4.x/module/tests/test_classic_dbwrapper.py branches/4.x/module/tests/test_dbapi20.py trunk/module/setup.py trunk/module/tests/test_classic_connection.py trunk/module/tests/test_classic_dbwrapper.py trunk/module/tests/test_dbapi20.py Modified: branches/4.x/module/pg.py ============================================================================== --- branches/4.x/module/pg.py Sat Jan 2 11:41:04 2016 (r689) +++ branches/4.x/module/pg.py Sat Jan 2 18:25:14 2016 (r690) @@ -197,6 +197,8 @@ Note: If the main loop is running in another thread, you must pass a different database connection to avoid a collision. + The payload parameter is only supported in PostgreSQL >= 9.0. + """ if not db: db = self.db Modified: branches/4.x/module/setup.py ============================================================================== --- branches/4.x/module/setup.py Sat Jan 2 11:41:04 2016 (r689) +++ branches/4.x/module/setup.py Sat Jan 2 18:25:14 2016 (r690) @@ -128,11 +128,11 @@ define_macros.append(('LARGE_OBJECTS', None)) if self.default_vars: define_macros.append(('DEFAULT_VARS', None)) - if self.escaping_funcs: + if self.escaping_funcs and pg_version[0] >= 9: define_macros.append(('ESCAPING_FUNCS', None)) if sys.platform == 'win32': bits = platform.architecture()[0] - if bits == '64bit': # we need to find libpq64 + if bits == '64bit': # we need to find libpq64 for path in os.environ['PATH'].split(os.pathsep) + [ r'C:\Program Files\PostgreSQL\libpq64']: library_dir = os.path.join(path, 'lib') @@ -149,13 +149,13 @@ library_dirs.insert(1, library_dir) if include_dir not in include_dirs: include_dirs.insert(1, include_dir) - libraries[0] += 'dll' # libpqdll instead of libpq + libraries[0] += 'dll' # libpqdll instead of libpq break compiler = self.get_compiler() - if compiler == 'mingw32': # MinGW - if bits == '64bit': # needs MinGW-w64 + if compiler == 'mingw32': # MinGW + if bits == '64bit': # needs MinGW-w64 define_macros.append(('MS_WIN64', None)) - elif compiler == 'msvc': # Microsoft Visual C++ + elif compiler == 'msvc': # Microsoft Visual C++ libraries[0] = 'lib' + libraries[0] @@ -163,7 +163,7 @@ name="PyGreSQL", version=version, description="Python PostgreSQL Interfaces", - long_description=__doc__.split('\n\n', 2)[1], # first passage + long_description=__doc__.split('\n\n', 2)[1], # first passage keywords="pygresql postgresql database api dbapi", author="D'Arcy J. M. Cain", author_email="da...@pygresql.org", Modified: branches/4.x/module/tests/test_classic.py ============================================================================== --- branches/4.x/module/tests/test_classic.py Sat Jan 2 11:41:04 2016 (r689) +++ branches/4.x/module/tests/test_classic.py Sat Jan 2 18:25:14 2016 (r690) @@ -249,6 +249,8 @@ call_notify = options.get('call_notify') two_payloads = options.get('two_payloads') db = opendb() + if db.server_version < 90000: # PostgreSQL < 9.0 + self.skipTest('Notify with payload not supported') # Get function under test, can be standalone or DB method. if run_as_method: fut = db.notification_handler @@ -336,6 +338,8 @@ def test_notify_timeout(self): for run_as_method in False, True: db = opendb() + if db.server_version < 90000: # PostgreSQL < 9.0 + self.skipTest('Notify with payload not supported') # Get function under test, can be standalone or DB method. if run_as_method: fut = db.notification_handler Modified: branches/4.x/module/tests/test_classic_connection.py ============================================================================== --- branches/4.x/module/tests/test_classic_connection.py Sat Jan 2 11:41:04 2016 (r689) +++ branches/4.x/module/tests/test_classic_connection.py Sat Jan 2 18:25:14 2016 (r690) @@ -86,6 +86,9 @@ fileno get_notice_receiver getline getlo getnotify inserttable locreate loimport parameter putline query reset set_notice_receiver source transaction'''.split() + if self.connection.server_version < 90000: # PostgreSQL < 9.0 + methods.remove('escape_identifier') + methods.remove('escape_literal') connection_methods = [a for a in dir(self.connection) if callable(eval("self.connection." + a))] self.assertEqual(methods, connection_methods) @@ -558,7 +561,7 @@ [(Decimal('2'),)]) self.assertEqual(query("select 1, $1::integer", (2,) ).getresult(), [(1, 2)]) - self.assertEqual(query("select 1 union select $1", (2,) + self.assertEqual(query("select 1 union select $1::integer", (2,) ).getresult(), [(1,), (2,)]) self.assertEqual(query("select $1::integer+$2", (1, 2) ).getresult(), [(3,)]) @@ -816,7 +819,7 @@ v = getline() if i < n: self.assertEqual(v, '%d\t%s' % data[i]) - elif i == n: + elif i == n or self.c.server_version < 90000: self.assertEqual(v, '\\.') else: self.assertIsNone(v) @@ -842,6 +845,8 @@ self.c.close() def testGetNotify(self): + if self.c.server_version < 90000: # PostgreSQL < 9.0 + self.skipTest('Notify with payload not supported') getnotify = self.c.getnotify query = self.c.query self.assertIsNone(getnotify()) @@ -858,20 +863,16 @@ self.assertEqual(r[0], 'test_notify') self.assertEqual(r[2], '') self.assertIsNone(self.c.getnotify()) - try: - query("notify test_notify, 'test_payload'") - except pg.ProgrammingError: # PostgreSQL < 9.0 - pass - else: - r = getnotify() - self.assertTrue(isinstance(r, tuple)) - self.assertEqual(len(r), 3) - self.assertIsInstance(r[0], str) - self.assertIsInstance(r[1], int) - self.assertIsInstance(r[2], str) - self.assertEqual(r[0], 'test_notify') - self.assertEqual(r[2], 'test_payload') - self.assertIsNone(getnotify()) + query("notify test_notify, 'test_payload'") + r = getnotify() + self.assertTrue(isinstance(r, tuple)) + self.assertEqual(len(r), 3) + self.assertIsInstance(r[0], str) + self.assertIsInstance(r[1], int) + self.assertIsInstance(r[2], str) + self.assertEqual(r[0], 'test_notify') + self.assertEqual(r[2], 'test_payload') + self.assertIsNone(getnotify()) finally: query('unlisten test_notify') @@ -983,7 +984,7 @@ en_money = '$34.25', '$ 34.25', '34.25$', '34.25 $', '34.25 Dollar' de_locales = 'de', 'de_DE', 'de_DE.utf8', 'de_DE.UTF-8' de_money = ('34,25€', '34,25 €', '€34,25' '€ 34,25', - '34,25 EUR', '34,25 Euro', '34,25 DM') + 'EUR34,25', 'EUR 34,25', '34,25 EUR', '34,25 Euro', '34,25 DM') # first try with English localization (using the point) for lc in en_locales: try: Modified: branches/4.x/module/tests/test_classic_dbwrapper.py ============================================================================== --- branches/4.x/module/tests/test_classic_dbwrapper.py Sat Jan 2 11:41:04 2016 (r689) +++ branches/4.x/module/tests/test_classic_dbwrapper.py Sat Jan 2 18:25:14 2016 (r690) @@ -120,6 +120,9 @@ 'use_regtypes', 'user', ] + if self.db.server_version < 90000: # PostgreSQL < 9.0 + attributes.remove('escape_identifier') + attributes.remove('escape_literal') db_attributes = [a for a in dir(self.db) if not a.startswith('_')] self.assertEqual(attributes, db_attributes) @@ -190,9 +193,13 @@ self.assertEqual(user, self.db.db.user) def testMethodEscapeLiteral(self): + if self.db.server_version < 90000: # PostgreSQL < 9.0 + self.skipTest('Escaping functions not supported') self.assertEqual(self.db.escape_literal(''), "''") def testMethodEscapeIdentifier(self): + if self.db.server_version < 90000: # PostgreSQL < 9.0 + self.skipTest('Escaping functions not supported') self.assertEqual(self.db.escape_identifier(''), '""') def testMethodEscapeString(self): @@ -289,13 +296,19 @@ query = self.db.query query('set client_encoding=utf8') query('set standard_conforming_strings=on') - query('set bytea_output=hex') query("set lc_monetary='C'") + query("set datestyle='ISO,YMD'") + try: + query('set bytea_output=hex') + except pg.ProgrammingError: # PostgreSQL < 9.0 + pass def tearDown(self): self.db.close() def testEscapeLiteral(self): + if self.db.server_version < 90000: # PostgreSQL < 9.0 + self.skipTest('Escaping functions not supported') f = self.db.escape_literal self.assertEqual(f("plain"), "'plain'") self.assertEqual(f("that's k\xe4se"), "'that''s k\xe4se'") @@ -305,6 +318,8 @@ "'No \"quotes\" must be escaped.'") def testEscapeIdentifier(self): + if self.db.server_version < 90000: # PostgreSQL < 9.0 + self.skipTest('Escaping functions not supported') f = self.db.escape_identifier self.assertEqual(f("plain"), '"plain"') self.assertEqual(f("that's k\xe4se"), '"that\'s k\xe4se"') @@ -322,11 +337,16 @@ def testEscapeBytea(self): f = self.db.escape_bytea - # note that escape_byte always returns hex output since Pg 9.0, + # note that escape_byte always returns hex output since PostgreSQL 9.0, # regardless of the bytea_output setting - self.assertEqual(f("plain"), r"\x706c61696e") - self.assertEqual(f("that's k\xe4se"), r"\x746861742773206be47365") - self.assertEqual(f('O\x00ps\xff!'), r"\x4f007073ff21") + if self.db.server_version < 90000: + self.assertEqual(f("plain"), r"plain") + self.assertEqual(f("that's k\xe4se"), r"that''s k\344se") + self.assertEqual(f('O\x00ps\xff!'), r"O\000ps\377!") + else: + self.assertEqual(f("plain"), r"\x706c61696e") + self.assertEqual(f("that's k\xe4se"), r"\x746861742773206be47365") + self.assertEqual(f('O\x00ps\xff!'), r"\x4f007073ff21") def testUnescapeBytea(self): f = self.db.unescape_bytea @@ -689,6 +709,7 @@ def testInsert(self): insert = self.db.insert query = self.db.query + server_version = self.db.server_version for table in ('insert_test_table', 'test table for insert'): query('drop table if exists "%s"' % table) query('create table "%s" (' @@ -716,7 +737,7 @@ dict(d=Decimal('123456789.9876543212345678987654321')), dict(m=None), (dict(m=''), dict(m=None)), dict(m=Decimal('-1234.56')), - (dict(m=('-1234.56')), dict(m=Decimal('-1234.56'))), + (dict(m='-1234.56'), dict(m=Decimal('-1234.56'))), dict(m=Decimal('1234.56')), dict(m=Decimal('123456')), (dict(m='1234.56'), dict(m=Decimal('1234.56'))), (dict(m=1234.5), dict(m=Decimal('1234.5'))), @@ -751,6 +772,9 @@ data, change = test expect = data.copy() expect.update(change) + if data.get('m') and server_version < 910000: + # PostgreSQL < 9.1 cannot directly convert numbers to money + data['m'] = "'%s'::money" % data['m'] self.assertEqual(insert(table, data), data) self.assertIn(oid_table, data) oid = data[oid_table] Modified: branches/4.x/module/tests/test_dbapi20.py ============================================================================== --- branches/4.x/module/tests/test_dbapi20.py Sat Jan 2 11:41:04 2016 (r689) +++ branches/4.x/module/tests/test_dbapi20.py Sat Jan 2 18:25:14 2016 (r690) @@ -85,6 +85,7 @@ con = self._connect() try: cur = con.cursor() + cur.execute("set datestyle to 'iso'") cur.execute("create table %s (" "stringtest varchar," "binarytest bytea," Modified: trunk/module/setup.py ============================================================================== --- trunk/module/setup.py Sat Jan 2 11:41:04 2016 (r689) +++ trunk/module/setup.py Sat Jan 2 18:25:14 2016 (r690) @@ -76,7 +76,7 @@ if part.isdigit(): part = int(part) parts.append(part) - return tuple(parts or [8]) + return tuple(parts or [9]) pg_version = pg_version() @@ -129,11 +129,11 @@ define_macros.append(('LARGE_OBJECTS', None)) if self.default_vars: define_macros.append(('DEFAULT_VARS', None)) - if self.escaping_funcs: + if self.escaping_funcs and pg_version[0] >= 9: define_macros.append(('ESCAPING_FUNCS', None)) if sys.platform == 'win32': bits = platform.architecture()[0] - if bits == '64bit': # we need to find libpq64 + if bits == '64bit': # we need to find libpq64 for path in os.environ['PATH'].split(os.pathsep) + [ r'C:\Program Files\PostgreSQL\libpq64']: library_dir = os.path.join(path, 'lib') @@ -150,13 +150,13 @@ library_dirs.insert(1, library_dir) if include_dir not in include_dirs: include_dirs.insert(1, include_dir) - libraries[0] += 'dll' # libpqdll instead of libpq + libraries[0] += 'dll' # libpqdll instead of libpq break compiler = self.get_compiler() - if compiler == 'mingw32': # MinGW - if bits == '64bit': # needs MinGW-w64 + if compiler == 'mingw32': # MinGW + if bits == '64bit': # needs MinGW-w64 define_macros.append(('MS_WIN64', None)) - elif compiler == 'msvc': # Microsoft Visual C++ + elif compiler == 'msvc': # Microsoft Visual C++ libraries[0] = 'lib' + libraries[0] @@ -164,7 +164,7 @@ name="PyGreSQL", version=version, description="Python PostgreSQL Interfaces", - long_description=__doc__.split('\n\n', 2)[1], # first passage + long_description=__doc__.split('\n\n', 2)[1], # first passage keywords="pygresql postgresql database api dbapi", author="D'Arcy J. M. Cain", author_email="da...@pygresql.org", Modified: trunk/module/tests/test_classic_connection.py ============================================================================== --- trunk/module/tests/test_classic_connection.py Sat Jan 2 11:41:04 2016 (r689) +++ trunk/module/tests/test_classic_connection.py Sat Jan 2 18:25:14 2016 (r690) @@ -760,7 +760,7 @@ [(Decimal('2'),)]) self.assertEqual(query("select 1, $1::integer", (2,) ).getresult(), [(1, 2)]) - self.assertEqual(query("select 1 union select $1", (2,) + self.assertEqual(query("select 1 union select $1::integer", (2,) ).getresult(), [(1,), (2,)]) self.assertEqual(query("select $1::integer+$2", (1, 2) ).getresult(), [(3,)]) @@ -1223,20 +1223,16 @@ self.assertEqual(r[0], 'test_notify') self.assertEqual(r[2], '') self.assertIsNone(self.c.getnotify()) - try: - query("notify test_notify, 'test_payload'") - except pg.ProgrammingError: # PostgreSQL < 9.0 - pass - else: - r = getnotify() - self.assertTrue(isinstance(r, tuple)) - self.assertEqual(len(r), 3) - self.assertIsInstance(r[0], str) - self.assertIsInstance(r[1], int) - self.assertIsInstance(r[2], str) - self.assertEqual(r[0], 'test_notify') - self.assertEqual(r[2], 'test_payload') - self.assertIsNone(getnotify()) + query("notify test_notify, 'test_payload'") + r = getnotify() + self.assertTrue(isinstance(r, tuple)) + self.assertEqual(len(r), 3) + self.assertIsInstance(r[0], str) + self.assertIsInstance(r[1], int) + self.assertIsInstance(r[2], str) + self.assertEqual(r[0], 'test_notify') + self.assertEqual(r[2], 'test_payload') + self.assertIsNone(getnotify()) finally: query('unlisten test_notify') @@ -1352,7 +1348,7 @@ en_money = '$34.25', '$ 34.25', '34.25$', '34.25 $', '34.25 Dollar' de_locales = 'de', 'de_DE', 'de_DE.utf8', 'de_DE.UTF-8' de_money = ('34,25€', '34,25 €', '€34,25' '€ 34,25', - '34,25 EUR', '34,25 Euro', '34,25 DM') + 'EUR34,25', 'EUR 34,25', '34,25 EUR', '34,25 Euro', '34,25 DM') # first try with English localization (using the point) for lc in en_locales: try: Modified: trunk/module/tests/test_classic_dbwrapper.py ============================================================================== --- trunk/module/tests/test_classic_dbwrapper.py Sat Jan 2 11:41:04 2016 (r689) +++ trunk/module/tests/test_classic_dbwrapper.py Sat Jan 2 18:25:14 2016 (r690) @@ -298,8 +298,9 @@ query = self.db.query query('set client_encoding=utf8') query('set standard_conforming_strings=on') - query('set bytea_output=hex') query("set lc_monetary='C'") + query("set datestyle='ISO,YMD'") + query('set bytea_output=hex') def tearDown(self): self.db.close() @@ -755,6 +756,7 @@ def testInsert(self): insert = self.db.insert query = self.db.query + server_version = self.db.server_version for table in ('insert_test_table', 'test table for insert'): query('drop table if exists "%s"' % table) query('create table "%s" (' @@ -817,6 +819,9 @@ data, change = test expect = data.copy() expect.update(change) + if data.get('m') and server_version < 910000: + # PostgreSQL < 9.1 cannot directly convert numbers to money + data['m'] = "'%s'::money" % data['m'] self.assertEqual(insert(table, data), data) self.assertIn(oid_table, data) oid = data[oid_table] Modified: trunk/module/tests/test_dbapi20.py ============================================================================== --- trunk/module/tests/test_dbapi20.py Sat Jan 2 11:41:04 2016 (r689) +++ trunk/module/tests/test_dbapi20.py Sat Jan 2 18:25:14 2016 (r690) @@ -247,6 +247,7 @@ con = self._connect() try: cur = con.cursor() + cur.execute("set datestyle to 'iso'") cur.execute("create table %s (" "stringtest varchar," "binarytest bytea," _______________________________________________ PyGreSQL mailing list PyGreSQL@vex.net https://mail.vex.net/mailman/listinfo.cgi/pygresql