Changeset 648


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.

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/4.x/module/tests/test_classic.py

    r647 r648  
    22
    33from __future__ import with_statement
     4
     5try:
     6    import unittest2 as unittest  # for Python < 2.7
     7except ImportError:
     8    import unittest
    49
    510import sys
     
    712from time import sleep
    813from threading import Thread
    9 import unittest
     14
    1015from pg import *
    1116
     
    346351
    347352if __name__ == '__main__':
    348     suite = unittest.TestSuite()
    349 
    350     if len(sys.argv) > 1: test_list = sys.argv[1:]
    351     else: test_list = unittest.getTestCaseNames(UtilityTest, 'test_')
    352 
    353353    if len(sys.argv) == 2 and sys.argv[1] == '-l':
    354354        print '\n'.join(unittest.getTestCaseNames(UtilityTest, 'test_'))
    355         sys.exit(1)
    356 
     355        sys.exit(0)
     356
     357    test_list = [name for name in sys.argv[1:] if not name.startswith('-')]
     358    if not test_list:
     359        test_list = unittest.getTestCaseNames(UtilityTest, 'test_')
     360
     361    suite = unittest.TestSuite()
    357362    for test_name in test_list:
    358363        try:
    359364            suite.addTest(UtilityTest(test_name))
    360         except:
     365        except Exception:
    361366            print "\n ERROR: %s.\n" % sys.exc_value
    362367            sys.exit(1)
    363368
    364     rc = unittest.TextTestRunner(verbosity=1).run(suite)
    365     sys.exit(len(rc.errors+rc.failures) != 0)
    366 
     369    verbosity = '-v' in sys.argv[1:] and 2 or 1
     370    failfast = '-l' in sys.argv[1:]
     371    runner = unittest.TextTestRunner(verbosity=verbosity, failfast=failfast)
     372    rc = runner.run(suite)
     373    sys.exit(1 if rc.errors or rc.failures else 0)
  • 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.