Debian Codegraph @

oslo_db/sqlalchemy/test_base.py

raw symbols SCIP
1 # Copyright (c) 2013 OpenStack Foundation
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 import functools
17
18 from oslo_utils import reflection
19
20
21 ALLOWED_DIALECTS = ['sqlite', 'mysql', 'postgresql']
22
23
24 def backend_specific(*dialects):
25 """Decorator to skip backend specific tests on inappropriate engines.
26
27 ::dialects: list of dialects names under which the test will be launched.
28 """
29 def wrap(f):
30 @functools.wraps(f)
31 def ins_wrap(self):
32 if not set(dialects).issubset(ALLOWED_DIALECTS):
33 raise ValueError(
34 "Please use allowed dialects: %s" % ALLOWED_DIALECTS)
35 if self.engine.name not in dialects:
36 msg = ('The test "%s" can be run '
37 'only on %s. Current engine is %s.')
38 args = (reflection.get_callable_name(f), ', '.join(dialects),
39 self.engine.name)
40 self.skipTest(msg % args)
41 else:
42 return f(self)
43 return ins_wrap
44 return wrap