1 | """Global database feature support policy. |
---|
2 | |
---|
3 | Provides decorators to mark tests requiring specific feature support from the |
---|
4 | target database. |
---|
5 | |
---|
6 | """ |
---|
7 | |
---|
8 | from testing import \ |
---|
9 | _block_unconditionally as no_support, \ |
---|
10 | _chain_decorators_on, \ |
---|
11 | exclude, \ |
---|
12 | emits_warning_on |
---|
13 | |
---|
14 | |
---|
15 | def deferrable_constraints(fn): |
---|
16 | """Target database must support derferable constraints.""" |
---|
17 | return _chain_decorators_on( |
---|
18 | fn, |
---|
19 | no_support('firebird', 'not supported by database'), |
---|
20 | no_support('mysql', 'not supported by database'), |
---|
21 | no_support('mssql', 'not supported by database'), |
---|
22 | ) |
---|
23 | |
---|
24 | def foreign_keys(fn): |
---|
25 | """Target database must support foreign keys.""" |
---|
26 | return _chain_decorators_on( |
---|
27 | fn, |
---|
28 | no_support('sqlite', 'not supported by database'), |
---|
29 | ) |
---|
30 | |
---|
31 | def identity(fn): |
---|
32 | """Target database must support GENERATED AS IDENTITY or a facsimile. |
---|
33 | |
---|
34 | Includes GENERATED AS IDENTITY, AUTOINCREMENT, AUTO_INCREMENT, or other |
---|
35 | column DDL feature that fills in a DB-generated identifier at INSERT-time |
---|
36 | without requiring pre-execution of a SEQUENCE or other artifact. |
---|
37 | |
---|
38 | """ |
---|
39 | return _chain_decorators_on( |
---|
40 | fn, |
---|
41 | no_support('firebird', 'not supported by database'), |
---|
42 | no_support('oracle', 'not supported by database'), |
---|
43 | no_support('postgres', 'not supported by database'), |
---|
44 | no_support('sybase', 'not supported by database'), |
---|
45 | ) |
---|
46 | |
---|
47 | def independent_connections(fn): |
---|
48 | """Target must support simultaneous, independent database connections.""" |
---|
49 | |
---|
50 | # This is also true of some configurations of UnixODBC and probably win32 |
---|
51 | # ODBC as well. |
---|
52 | return _chain_decorators_on( |
---|
53 | fn, |
---|
54 | no_support('sqlite', 'no driver support') |
---|
55 | ) |
---|
56 | |
---|
57 | def row_triggers(fn): |
---|
58 | """Target must support standard statement-running EACH ROW triggers.""" |
---|
59 | return _chain_decorators_on( |
---|
60 | fn, |
---|
61 | # no access to same table |
---|
62 | no_support('mysql', 'requires SUPER priv'), |
---|
63 | exclude('mysql', '<', (5, 0, 10), 'not supported by database'), |
---|
64 | no_support('postgres', 'not supported by database: no statements'), |
---|
65 | ) |
---|
66 | |
---|
67 | def savepoints(fn): |
---|
68 | """Target database must support savepoints.""" |
---|
69 | return _chain_decorators_on( |
---|
70 | fn, |
---|
71 | emits_warning_on('mssql', 'Savepoint support in mssql is experimental and may lead to data loss.'), |
---|
72 | no_support('access', 'not supported by database'), |
---|
73 | no_support('sqlite', 'not supported by database'), |
---|
74 | no_support('sybase', 'FIXME: guessing, needs confirmation'), |
---|
75 | exclude('mysql', '<', (5, 0, 3), 'not supported by database'), |
---|
76 | ) |
---|
77 | |
---|
78 | def sequences(fn): |
---|
79 | """Target database must support SEQUENCEs.""" |
---|
80 | return _chain_decorators_on( |
---|
81 | fn, |
---|
82 | no_support('access', 'no SEQUENCE support'), |
---|
83 | no_support('mssql', 'no SEQUENCE support'), |
---|
84 | no_support('mysql', 'no SEQUENCE support'), |
---|
85 | no_support('sqlite', 'no SEQUENCE support'), |
---|
86 | no_support('sybase', 'no SEQUENCE support'), |
---|
87 | ) |
---|
88 | |
---|
89 | def subqueries(fn): |
---|
90 | """Target database must support subqueries.""" |
---|
91 | return _chain_decorators_on( |
---|
92 | fn, |
---|
93 | exclude('mysql', '<', (4, 1, 1), 'no subquery support'), |
---|
94 | ) |
---|
95 | |
---|
96 | def two_phase_transactions(fn): |
---|
97 | """Target database must support two-phase transactions.""" |
---|
98 | return _chain_decorators_on( |
---|
99 | fn, |
---|
100 | no_support('access', 'not supported by database'), |
---|
101 | no_support('firebird', 'no SA implementation'), |
---|
102 | no_support('maxdb', 'not supported by database'), |
---|
103 | no_support('mssql', 'FIXME: guessing, needs confirmation'), |
---|
104 | no_support('oracle', 'no SA implementation'), |
---|
105 | no_support('sqlite', 'not supported by database'), |
---|
106 | no_support('sybase', 'FIXME: guessing, needs confirmation'), |
---|
107 | exclude('mysql', '<', (5, 0, 3), 'not supported by database'), |
---|
108 | ) |
---|
109 | |
---|
110 | def unicode_connections(fn): |
---|
111 | """Target driver must support some encoding of Unicode across the wire.""" |
---|
112 | # TODO: expand to exclude MySQLdb versions w/ broken unicode |
---|
113 | return _chain_decorators_on( |
---|
114 | fn, |
---|
115 | exclude('mysql', '<', (4, 1, 1), 'no unicode connection support'), |
---|
116 | ) |
---|
117 | |
---|
118 | def unicode_ddl(fn): |
---|
119 | """Target driver must support some encoding of Unicode across the wire.""" |
---|
120 | # TODO: expand to exclude MySQLdb versions w/ broken unicode |
---|
121 | return _chain_decorators_on( |
---|
122 | fn, |
---|
123 | no_support('maxdb', 'database support flakey'), |
---|
124 | no_support('oracle', 'FIXME: no support in database?'), |
---|
125 | no_support('sybase', 'FIXME: guessing, needs confirmation'), |
---|
126 | exclude('mysql', '<', (4, 1, 1), 'no unicode connection support'), |
---|
127 | ) |
---|