Author: cito
Date: Fri Nov 27 11:45:53 2015
New Revision: 648
Log:
Use unittest2 in test_classic
Also, depending on how the tests are started, relative imports may
fail, so use absolute imports if that happens.
Modified:
branches/4.x/module/tests/test_classic.py
trunk/module/tests/test_classic.py
trunk/module/tests/test_classic_connection.py
trunk/module/tests/test_classic_dbwrapper.py
trunk/module/tests/test_classic_functions.py
trunk/module/tests/test_classic_largeobj.py
trunk/module/tests/test_dbapi20.py
Modified: branches/4.x/module/tests/test_classic.py
==============================================================================
--- branches/4.x/module/tests/test_classic.py Fri Nov 27 11:03:01 2015
(r647)
+++ branches/4.x/module/tests/test_classic.py Fri Nov 27 11:45:53 2015
(r648)
@@ -2,11 +2,16 @@
from __future__ import with_statement
+try:
+ import unittest2 as unittest # for Python < 2.7
+except ImportError:
+ import unittest
+
import sys
from functools import partial
from time import sleep
from threading import Thread
-import unittest
+
from pg import *
# We need a database to test against. If LOCAL_PyGreSQL.py exists we will
@@ -345,22 +350,24 @@
if __name__ == '__main__':
- suite = unittest.TestSuite()
-
- if len(sys.argv) > 1: test_list = sys.argv[1:]
- else: test_list = unittest.getTestCaseNames(UtilityTest, 'test_')
-
if len(sys.argv) == 2 and sys.argv[1] == '-l':
print '\n'.join(unittest.getTestCaseNames(UtilityTest, 'test_'))
- sys.exit(1)
+ sys.exit(0)
+
+ test_list = [name for name in sys.argv[1:] if not name.startswith('-')]
+ if not test_list:
+ test_list = unittest.getTestCaseNames(UtilityTest, 'test_')
+ suite = unittest.TestSuite()
for test_name in test_list:
try:
suite.addTest(UtilityTest(test_name))
- except:
+ except Exception:
print "\n ERROR: %s.\n" % sys.exc_value
sys.exit(1)
- rc = unittest.TextTestRunner(verbosity=1).run(suite)
- sys.exit(len(rc.errors+rc.failures) != 0)
-
+ verbosity = '-v' in sys.argv[1:] and 2 or 1
+ failfast = '-l' in sys.argv[1:]
+ runner = unittest.TextTestRunner(verbosity=verbosity, failfast=failfast)
+ rc = runner.run(suite)
+ sys.exit(1 if rc.errors or rc.failures else 0)
Modified: trunk/module/tests/test_classic.py
==============================================================================
--- trunk/module/tests/test_classic.py Fri Nov 27 11:03:01 2015 (r647)
+++ trunk/module/tests/test_classic.py Fri Nov 27 11:45:53 2015 (r648)
@@ -3,11 +3,16 @@
from __future__ import print_function
+try:
+ import unittest2 as unittest # for Python < 2.7
+except ImportError:
+ import unittest
+
import sys
from functools import partial
from time import sleep
from threading import Thread
-import unittest
+
from pg import *
# We need a database to test against. If LOCAL_PyGreSQL.py exists we will
@@ -18,8 +23,11 @@
try:
from .LOCAL_PyGreSQL import *
-except ImportError:
- pass
+except (ImportError, ValueError):
+ try:
+ from LOCAL_PyGreSQL import *
+ except ImportError:
+ pass
def opendb():
@@ -361,17 +369,15 @@
if __name__ == '__main__':
- suite = unittest.TestSuite()
-
- if len(sys.argv) > 1:
- test_list = sys.argv[1:]
- else:
- test_list = unittest.getTestCaseNames(UtilityTest, 'test_')
-
if len(sys.argv) == 2 and sys.argv[1] == '-l':
print('\n'.join(unittest.getTestCaseNames(UtilityTest, 'test_')))
- sys.exit(1)
+ sys.exit(0)
+ test_list = [name for name in sys.argv[1:] if not name.startswith('-')]
+ if not test_list:
+ test_list = unittest.getTestCaseNames(UtilityTest, 'test_')
+
+ suite = unittest.TestSuite()
for test_name in test_list:
try:
suite.addTest(UtilityTest(test_name))
@@ -379,5 +385,8 @@
print("\n ERROR: %s.\n" % sys.exc_value)
sys.exit(1)
- rc = unittest.TextTestRunner(verbosity=1).run(suite)
- sys.exit(1 if rc.errors or rc.failures else 0)
+ verbosity = '-v' in sys.argv[1:] and 2 or 1
+ failfast = '-l' in sys.argv[1:]
+ runner = unittest.TextTestRunner(verbosity=verbosity, failfast=failfast)
+ rc = runner.run(suite)
+ sys.exit(1 if rc.errors or rc.failures else 0)
\ No newline at end of file
Modified: trunk/module/tests/test_classic_connection.py
==============================================================================
--- trunk/module/tests/test_classic_connection.py Fri Nov 27 11:03:01
2015 (r647)
+++ trunk/module/tests/test_classic_connection.py Fri Nov 27 11:45:53
2015 (r648)
@@ -34,8 +34,11 @@
try:
from .LOCAL_PyGreSQL import *
-except ImportError:
- pass
+except (ImportError, ValueError):
+ try:
+ from LOCAL_PyGreSQL import *
+ except ImportError:
+ pass
try:
long
Modified: trunk/module/tests/test_classic_dbwrapper.py
==============================================================================
--- trunk/module/tests/test_classic_dbwrapper.py Fri Nov 27 11:03:01
2015 (r647)
+++ trunk/module/tests/test_classic_dbwrapper.py Fri Nov 27 11:45:53
2015 (r648)
@@ -32,8 +32,11 @@
try:
from .LOCAL_PyGreSQL import *
-except ImportError:
- pass
+except (ImportError, ValueError):
+ try:
+ from LOCAL_PyGreSQL import *
+ except ImportError:
+ pass
try:
long
Modified: trunk/module/tests/test_classic_functions.py
==============================================================================
--- trunk/module/tests/test_classic_functions.py Fri Nov 27 11:03:01
2015 (r647)
+++ trunk/module/tests/test_classic_functions.py Fri Nov 27 11:45:53
2015 (r648)
@@ -378,6 +378,7 @@
def testGetNamedresult(self):
r = pg.get_namedresult()
+ self.assertTrue(callable(r))
self.assertIs(r, pg._namedresult)
def testSetNamedresult(self):
Modified: trunk/module/tests/test_classic_largeobj.py
==============================================================================
--- trunk/module/tests/test_classic_largeobj.py Fri Nov 27 11:03:01 2015
(r647)
+++ trunk/module/tests/test_classic_largeobj.py Fri Nov 27 11:45:53 2015
(r648)
@@ -28,8 +28,11 @@
try:
from .LOCAL_PyGreSQL import *
-except ImportError:
- pass
+except (ImportError, ValueError):
+ try:
+ from LOCAL_PyGreSQL import *
+ except ImportError:
+ pass
windows = os.name == 'nt'
Modified: trunk/module/tests/test_dbapi20.py
==============================================================================
--- trunk/module/tests/test_dbapi20.py Fri Nov 27 11:03:01 2015 (r647)
+++ trunk/module/tests/test_dbapi20.py Fri Nov 27 11:45:53 2015 (r648)
@@ -6,7 +6,10 @@
import pgdb
-from . import dbapi20
+try:
+ from . import dbapi20
+except (ImportError, ValueError, SystemError):
+ import dbapi20
# We need a database to test against.
# If LOCAL_PyGreSQL.py exists we will get our information from that.
@@ -16,8 +19,11 @@
dbport = 5432
try:
from .LOCAL_PyGreSQL import *
-except ImportError:
- pass
+except (ImportError, ValueError):
+ try:
+ from LOCAL_PyGreSQL import *
+ except ImportError:
+ pass
try:
long
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql