mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-26 05:30:33 +03:00
Fixed notification tests to run on Py3.
Call 2to3 on the dynamically generated scripts.
This commit is contained in:
parent
b78ff4a273
commit
0a4eeb4e13
|
@ -4,6 +4,7 @@ from testutils import unittest
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2 import extensions
|
from psycopg2 import extensions
|
||||||
from testconfig import dsn
|
from testconfig import dsn
|
||||||
|
from testutils import script_to_py3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
@ -52,7 +53,7 @@ conn.close()
|
||||||
"""
|
"""
|
||||||
% { 'dsn': dsn, 'sec': sec, 'name': name, 'payload': payload})
|
% { 'dsn': dsn, 'sec': sec, 'name': name, 'payload': payload})
|
||||||
|
|
||||||
return Popen([sys.executable, '-c', script], stdout=PIPE)
|
return Popen([sys.executable, '-c', script_to_py3(script)], stdout=PIPE)
|
||||||
|
|
||||||
def test_notifies_received_on_poll(self):
|
def test_notifies_received_on_poll(self):
|
||||||
self.autocommit(self.conn)
|
self.autocommit(self.conn)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
# Use unittest2 if available. Otherwise mock a skip facility with warnings.
|
# Use unittest2 if available. Otherwise mock a skip facility with warnings.
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -92,3 +93,23 @@ def skip_on_python3(f):
|
||||||
|
|
||||||
return skip_on_python3_
|
return skip_on_python3_
|
||||||
|
|
||||||
|
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")
|
||||||
|
f.write(script.encode())
|
||||||
|
f.flush()
|
||||||
|
|
||||||
|
# 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', f.name]):
|
||||||
|
raise Exception('py3 conversion failed')
|
||||||
|
|
||||||
|
return open(f.name).read()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user