diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2017-11-28 20:58:41 -0800 |
---|---|---|
committer | Jon Dufresne <jon.dufresne@gmail.com> | 2017-12-01 22:50:16 -0800 |
commit | 699be52e8b8a08e04e3486b73f748a7e489b35f2 (patch) | |
tree | c23e08b4583b529fe96baaae728a64c47fda6db4 /tests | |
parent | a51160317c680662c52e4a1a6b4d11beae37f205 (diff) | |
download | psycopg2-699be52e8b8a08e04e3486b73f748a7e489b35f2.tar.gz |
Remove unnecessary script_to_py3; make scripts compatible instead
Part of the work towards moving tests out of the installed package.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_connection.py | 4 | ||||
-rwxr-xr-x | tests/test_copy.py | 6 | ||||
-rwxr-xr-x | tests/test_module.py | 4 | ||||
-rwxr-xr-x | tests/test_notify.py | 6 | ||||
-rw-r--r-- | tests/testutils.py | 28 |
5 files changed, 10 insertions, 38 deletions
diff --git a/tests/test_connection.py b/tests/test_connection.py index f13df18..369c204 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -35,7 +35,7 @@ import psycopg2.errorcodes from psycopg2 import extensions as ext from testutils import ( - script_to_py3, unittest, 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) @@ -1566,7 +1566,7 @@ while True: cur.execute(%(query)r, ("Hello, world!",)) """ % {'dsn': dsn, 'query': query}) - proc = sp.Popen([sys.executable, '-c', script_to_py3(script)], + proc = sp.Popen([sys.executable, '-c', script], stdout=sp.PIPE, stderr=sp.PIPE) (out, err) = proc.communicate() self.assertNotEqual(proc.returncode, 0) diff --git a/tests/test_copy.py b/tests/test_copy.py index c5e7913..a70e58e 100755 --- a/tests/test_copy.py +++ b/tests/test_copy.py @@ -32,7 +32,7 @@ from subprocess import Popen, PIPE import psycopg2 import psycopg2.extensions -from testutils import skip_copy_if_green, script_to_py3 +from testutils import skip_copy_if_green from testconfig import dsn @@ -324,7 +324,7 @@ except psycopg2.ProgrammingError: conn.close() """ % {'dsn': dsn}) - proc = Popen([sys.executable, '-c', script_to_py3(script)]) + proc = Popen([sys.executable, '-c', script]) proc.communicate() self.assertEqual(0, proc.returncode) @@ -343,7 +343,7 @@ except psycopg2.ProgrammingError: conn.close() """ % {'dsn': dsn}) - proc = Popen([sys.executable, '-c', script_to_py3(script)], stdout=PIPE) + proc = Popen([sys.executable, '-c', script], stdout=PIPE) proc.communicate() self.assertEqual(0, proc.returncode) diff --git a/tests/test_module.py b/tests/test_module.py index 4a4941c..01565d4 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_postgres, - ConnectingTestCase, skip_copy_if_green, script_to_py3, slow) + ConnectingTestCase, skip_copy_if_green, slow) import psycopg2 @@ -322,7 +322,7 @@ sys.path.insert(0, %r) import _psycopg """ % (pardir, pkgdir)) - proc = Popen([sys.executable, '-c', script_to_py3(script)]) + proc = Popen([sys.executable, '-c', script]) proc.communicate() self.assertEqual(0, proc.returncode) diff --git a/tests/test_notify.py b/tests/test_notify.py index 0e74e1d..97fa6d8 100755 --- a/tests/test_notify.py +++ b/tests/test_notify.py @@ -26,7 +26,7 @@ from testutils import unittest import psycopg2 from psycopg2 import extensions -from testutils import ConnectingTestCase, script_to_py3, slow +from testutils import ConnectingTestCase, slow from testconfig import dsn import sys @@ -61,7 +61,7 @@ import %(module)s as psycopg2 import %(module)s.extensions as ext conn = psycopg2.connect(%(dsn)r) conn.set_isolation_level(ext.ISOLATION_LEVEL_AUTOCOMMIT) -print conn.get_backend_pid() +print(conn.get_backend_pid()) curs = conn.cursor() curs.execute("NOTIFY " %(name)r %(payload)r) curs.close() @@ -70,7 +70,7 @@ conn.close() 'module': psycopg2.__name__, 'dsn': dsn, 'sec': sec, 'name': name, 'payload': payload}) - return Popen([sys.executable, '-c', script_to_py3(script)], stdout=PIPE) + return Popen([sys.executable, '-c', script], stdout=PIPE) @slow def test_notifies_received_on_poll(self): diff --git a/tests/testutils.py b/tests/testutils.py index bd08d6c..2ee07af 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -371,34 +371,6 @@ def skip_if_windows(f): return skip_if_windows_ -def script_to_py3(script): - """Convert a script to Python3 syntax if required.""" - if sys.version_info[0] < 3: - return script - - import tempfile - f = tempfile.NamedTemporaryFile(suffix=".py", delete=False) - f.write(script.encode()) - f.flush() - filename = f.name - f.close() - - # 2to3 is way too chatty - import logging - logging.basicConfig(filename=os.devnull) - - from lib2to3.main import main - if main("lib2to3.fixes", ['--no-diffs', '-w', '-n', filename]): - raise Exception('py3 conversion failed') - - f2 = open(filename) - try: - return f2.read() - finally: - f2.close() - os.remove(filename) - - class py3_raises_typeerror(object): def __enter__(self): pass |