mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-13 12:36:33 +03:00
Merge remote-tracking branch 'jdufresne/script-to-py3'
This commit is contained in:
commit
ccc3820f8e
|
@ -35,7 +35,7 @@ import psycopg2.errorcodes
|
||||||
from psycopg2 import extensions as ext
|
from psycopg2 import extensions as ext
|
||||||
|
|
||||||
from testutils import (
|
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,
|
skip_before_postgres, skip_after_postgres, skip_before_libpq,
|
||||||
ConnectingTestCase, skip_if_tpc_disabled, skip_if_windows, slow)
|
ConnectingTestCase, skip_if_tpc_disabled, skip_if_windows, slow)
|
||||||
|
|
||||||
|
@ -1566,7 +1566,7 @@ while True:
|
||||||
cur.execute(%(query)r, ("Hello, world!",))
|
cur.execute(%(query)r, ("Hello, world!",))
|
||||||
""" % {'dsn': dsn, 'query': query})
|
""" % {'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)
|
stdout=sp.PIPE, stderr=sp.PIPE)
|
||||||
(out, err) = proc.communicate()
|
(out, err) = proc.communicate()
|
||||||
self.assertNotEqual(proc.returncode, 0)
|
self.assertNotEqual(proc.returncode, 0)
|
||||||
|
|
|
@ -32,7 +32,7 @@ from subprocess import Popen, PIPE
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import psycopg2.extensions
|
import psycopg2.extensions
|
||||||
from testutils import skip_copy_if_green, script_to_py3
|
from testutils import skip_copy_if_green
|
||||||
from testconfig import dsn
|
from testconfig import dsn
|
||||||
|
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ except psycopg2.ProgrammingError:
|
||||||
conn.close()
|
conn.close()
|
||||||
""" % {'dsn': dsn})
|
""" % {'dsn': dsn})
|
||||||
|
|
||||||
proc = Popen([sys.executable, '-c', script_to_py3(script)])
|
proc = Popen([sys.executable, '-c', script])
|
||||||
proc.communicate()
|
proc.communicate()
|
||||||
self.assertEqual(0, proc.returncode)
|
self.assertEqual(0, proc.returncode)
|
||||||
|
|
||||||
|
@ -343,7 +343,7 @@ except psycopg2.ProgrammingError:
|
||||||
conn.close()
|
conn.close()
|
||||||
""" % {'dsn': dsn})
|
""" % {'dsn': dsn})
|
||||||
|
|
||||||
proc = Popen([sys.executable, '-c', script_to_py3(script)], stdout=PIPE)
|
proc = Popen([sys.executable, '-c', script], stdout=PIPE)
|
||||||
proc.communicate()
|
proc.communicate()
|
||||||
self.assertEqual(0, proc.returncode)
|
self.assertEqual(0, proc.returncode)
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ import sys
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
|
||||||
from testutils import (unittest, skip_before_postgres,
|
from testutils import (unittest, skip_before_postgres,
|
||||||
ConnectingTestCase, skip_copy_if_green, script_to_py3, slow)
|
ConnectingTestCase, skip_copy_if_green, slow)
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ sys.path.insert(0, %r)
|
||||||
import _psycopg
|
import _psycopg
|
||||||
""" % (pardir, pkgdir))
|
""" % (pardir, pkgdir))
|
||||||
|
|
||||||
proc = Popen([sys.executable, '-c', script_to_py3(script)])
|
proc = Popen([sys.executable, '-c', script])
|
||||||
proc.communicate()
|
proc.communicate()
|
||||||
self.assertEqual(0, proc.returncode)
|
self.assertEqual(0, proc.returncode)
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ from testutils import unittest
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2 import extensions
|
from psycopg2 import extensions
|
||||||
from testutils import ConnectingTestCase, script_to_py3, slow
|
from testutils import ConnectingTestCase, slow
|
||||||
from testconfig import dsn
|
from testconfig import dsn
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
@ -61,7 +61,7 @@ import %(module)s as psycopg2
|
||||||
import %(module)s.extensions as ext
|
import %(module)s.extensions as ext
|
||||||
conn = psycopg2.connect(%(dsn)r)
|
conn = psycopg2.connect(%(dsn)r)
|
||||||
conn.set_isolation_level(ext.ISOLATION_LEVEL_AUTOCOMMIT)
|
conn.set_isolation_level(ext.ISOLATION_LEVEL_AUTOCOMMIT)
|
||||||
print conn.get_backend_pid()
|
print(conn.get_backend_pid())
|
||||||
curs = conn.cursor()
|
curs = conn.cursor()
|
||||||
curs.execute("NOTIFY " %(name)r %(payload)r)
|
curs.execute("NOTIFY " %(name)r %(payload)r)
|
||||||
curs.close()
|
curs.close()
|
||||||
|
@ -70,7 +70,7 @@ conn.close()
|
||||||
'module': psycopg2.__name__,
|
'module': psycopg2.__name__,
|
||||||
'dsn': dsn, 'sec': sec, 'name': name, 'payload': payload})
|
'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
|
@slow
|
||||||
def test_notifies_received_on_poll(self):
|
def test_notifies_received_on_poll(self):
|
||||||
|
|
|
@ -371,34 +371,6 @@ def skip_if_windows(f):
|
||||||
return skip_if_windows_
|
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):
|
class py3_raises_typeerror(object):
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user