Contact: fumanchu@aminus.org

Log in as guest/geniusql to create tickets

root/trunk/geniusql/test/test.py

Revision 2 (checked in by fumanchu, 6 years ago)

New Database methods: make_table, save, insert. Added initial test suite (mostly copied from dejavu).

  • Property svn:eol-style set to native
Line 
1 import getopt
2 import sys
3 import unittest
4
5 from geniusql.test import tools
6
7
8 class TestHarness(object):
9     """A test harness for Geniusql."""
10    
11     def __init__(self, available_tests):
12         """Constructor to populate the TestHarness instance.
13         
14         available_tests should be a list of module names (strings).
15         """
16         self.available_tests = available_tests
17         self.tests = []
18    
19     def load(self, args=sys.argv[1:]):
20         """Populate a TestHarness from sys.argv.
21         
22         args defaults to sys.argv[1:], but you can provide a different
23             set of args if you like.
24         """
25        
26         longopts = ['help']
27         longopts.extend(self.available_tests)
28         try:
29             opts, args = getopt.getopt(args, "", longopts)
30         except getopt.GetoptError:
31             # print help information and exit
32             self.help()
33             sys.exit(2)
34        
35         self.tests = []
36        
37         for o, a in opts:
38             if o == '--help':
39                 self.help()
40                 sys.exit()
41             else:
42                 o = o[2:]
43                 if o in self.available_tests and o not in self.tests:
44                     self.tests.append(o)
45        
46         if not self.tests:
47             self.tests = self.available_tests[:]
48    
49     def help(self):
50         """Print help for test.py command-line options."""
51        
52         print """
53 Geniusql Test Program
54     Usage:
55         test.py --<testname>
56         
57         tests:"""
58         for name in self.available_tests:
59             print '        --' + name
60    
61     def run(self, conf=None):
62         """Run the test harness."""
63         self.load()
64        
65         import geniusql
66         print "Python version:", sys.version.split()[0]
67         print "Geniusql version:", geniusql.__version__
68        
69         for testmod in self.tests:
70             if testmod.startswith("test_store"):
71                 print
72                 print "Testing %s storage..." % testmod[10:]
73                 mod = __import__(testmod, globals(), locals(), [''])
74                 if hasattr(mod, 'proxied_opts'):
75                     mod.proxied_opts['Prefix'] = 'test'
76                 elif hasattr(mod, 'opts'):
77                     mod.opts['Prefix'] = 'test'
78                 mod.run()
79             else:
80                 suite = unittest.TestLoader().loadTestsFromName(testmod)
81                 tools.TestRunner.run(suite)
82
83
84 def run():
85    
86     tools.prefer_parent_path()
87    
88     testList = [
89         'test_firebird',
90         'test_msaccess',
91         'test_mysql',
92         'test_psycopg',
93         'test_pypgsql',
94         'test_sqlite',
95         'test_sqlserver',
96     ]
97     TestHarness(testList).run()
98
99
100 if __name__ == '__main__':
101     run()
Note: See TracBrowser for help on using the browser.