Changeset 648 for trunk


Ignore:
Timestamp:
Nov 27, 2015, 11:45:53 AM (4 years ago)
Author:
cito
Message:

Use unittest2 in test_classic

Also, depending on how the tests are started, relative imports may
fail, so use absolute imports if that happens.

Location:
trunk/module/tests
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/tests/test_classic.py

    r640 r648  
    33
    44from __future__ import print_function
     5
     6try:
     7    import unittest2 as unittest  # for Python < 2.7
     8except ImportError:
     9    import unittest
    510
    611import sys
     
    813from time import sleep
    914from threading import Thread
    10 import unittest
     15
    1116from pg import *
    1217
     
    1924try:
    2025    from .LOCAL_PyGreSQL import *
    21 except ImportError:
    22     pass
     26except (ImportError, ValueError):
     27    try:
     28        from LOCAL_PyGreSQL import *
     29    except ImportError:
     30        pass
    2331
    2432
     
    362370
    363371if __name__ == '__main__':
    364     suite = unittest.TestSuite()
    365 
    366     if len(sys.argv) > 1:
    367         test_list = sys.argv[1:]
    368     else:
    369         test_list = unittest.getTestCaseNames(UtilityTest, 'test_')
    370 
    371372    if len(sys.argv) == 2 and sys.argv[1] == '-l':
    372373        print('\n'.join(unittest.getTestCaseNames(UtilityTest, 'test_')))
    373         sys.exit(1)
    374 
     374        sys.exit(0)
     375
     376    test_list = [name for name in sys.argv[1:] if not name.startswith('-')]
     377    if not test_list:
     378        test_list = unittest.getTestCaseNames(UtilityTest, 'test_')
     379
     380    suite = unittest.TestSuite()
    375381    for test_name in test_list:
    376382        try:
     
    380386            sys.exit(1)
    381387
    382     rc = unittest.TextTestRunner(verbosity=1).run(suite)
     388    verbosity = '-v' in sys.argv[1:] and 2 or 1
     389    failfast = '-l' in sys.argv[1:]
     390    runner = unittest.TextTestRunner(verbosity=verbosity, failfast=failfast)
     391    rc = runner.run(suite)
    383392    sys.exit(1 if rc.errors or rc.failures else 0)
  • trunk/module/tests/test_classic_connection.py

    r644 r648  
    3535try:
    3636    from .LOCAL_PyGreSQL import *
    37 except ImportError:
    38     pass
     37except (ImportError, ValueError):
     38    try:
     39        from LOCAL_PyGreSQL import *
     40    except ImportError:
     41        pass
    3942
    4043try:
  • trunk/module/tests/test_classic_dbwrapper.py

    r644 r648  
    3333try:
    3434    from .LOCAL_PyGreSQL import *
    35 except ImportError:
    36     pass
     35except (ImportError, ValueError):
     36    try:
     37        from LOCAL_PyGreSQL import *
     38    except ImportError:
     39        pass
    3740
    3841try:
  • trunk/module/tests/test_classic_functions.py

    r646 r648  
    379379    def testGetNamedresult(self):
    380380        r = pg.get_namedresult()
     381        self.assertTrue(callable(r))
    381382        self.assertIs(r, pg._namedresult)
    382383
  • trunk/module/tests/test_classic_largeobj.py

    r645 r648  
    2929try:
    3030    from .LOCAL_PyGreSQL import *
    31 except ImportError:
    32     pass
     31except (ImportError, ValueError):
     32    try:
     33        from LOCAL_PyGreSQL import *
     34    except ImportError:
     35        pass
    3336
    3437windows = os.name == 'nt'
  • trunk/module/tests/test_dbapi20.py

    r640 r648  
    77import pgdb
    88
    9 from . import dbapi20
     9try:
     10    from . import dbapi20
     11except (ImportError, ValueError, SystemError):
     12    import dbapi20
    1013
    1114# We need a database to test against.
     
    1720try:
    1821    from .LOCAL_PyGreSQL import *
    19 except ImportError:
    20     pass
     22except (ImportError, ValueError):
     23    try:
     24        from LOCAL_PyGreSQL import *
     25    except ImportError:
     26        pass
    2127
    2228try:
Note: See TracChangeset for help on using the changeset viewer.