root / test / py / cmdlib / testsupport / util.py @ 08cef8fc
History | View | Annotate | Download (1.4 kB)
1 | 08cef8fc | Thomas Thrainer | #
|
---|---|---|---|
2 | 08cef8fc | Thomas Thrainer | #
|
3 | 08cef8fc | Thomas Thrainer | |
4 | 08cef8fc | Thomas Thrainer | # Copyright (C) 2013 Google Inc.
|
5 | 08cef8fc | Thomas Thrainer | #
|
6 | 08cef8fc | Thomas Thrainer | # This program is free software; you can redistribute it and/or modify
|
7 | 08cef8fc | Thomas Thrainer | # it under the terms of the GNU General Public License as published by
|
8 | 08cef8fc | Thomas Thrainer | # the Free Software Foundation; either version 2 of the License, or
|
9 | 08cef8fc | Thomas Thrainer | # (at your option) any later version.
|
10 | 08cef8fc | Thomas Thrainer | #
|
11 | 08cef8fc | Thomas Thrainer | # This program is distributed in the hope that it will be useful, but
|
12 | 08cef8fc | Thomas Thrainer | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 08cef8fc | Thomas Thrainer | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 08cef8fc | Thomas Thrainer | # General Public License for more details.
|
15 | 08cef8fc | Thomas Thrainer | #
|
16 | 08cef8fc | Thomas Thrainer | # You should have received a copy of the GNU General Public License
|
17 | 08cef8fc | Thomas Thrainer | # along with this program; if not, write to the Free Software
|
18 | 08cef8fc | Thomas Thrainer | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 08cef8fc | Thomas Thrainer | # 02110-1301, USA.
|
20 | 08cef8fc | Thomas Thrainer | |
21 | 08cef8fc | Thomas Thrainer | |
22 | 08cef8fc | Thomas Thrainer | """Utility functions or the cmdlib test framework"""
|
23 | 08cef8fc | Thomas Thrainer | |
24 | 08cef8fc | Thomas Thrainer | |
25 | 08cef8fc | Thomas Thrainer | import mock |
26 | 08cef8fc | Thomas Thrainer | |
27 | 08cef8fc | Thomas Thrainer | |
28 | 08cef8fc | Thomas Thrainer | # pylint: disable=C0103
|
29 | 08cef8fc | Thomas Thrainer | def patchModule(module_under_test, mock_module): |
30 | 08cef8fc | Thomas Thrainer | """Computes the module prefix required to mock parts of the Ganeti code.
|
31 | 08cef8fc | Thomas Thrainer |
|
32 | 08cef8fc | Thomas Thrainer | @type module_under_test: string
|
33 | 08cef8fc | Thomas Thrainer | @param module_under_test: the module within cmdlib which is tested. The
|
34 | 08cef8fc | Thomas Thrainer | "ganeti.cmdlib" prefix is optional.
|
35 | 08cef8fc | Thomas Thrainer | @type mock_module
|
36 | 08cef8fc | Thomas Thrainer | @param mock_module: the module which should be mocked.
|
37 | 08cef8fc | Thomas Thrainer |
|
38 | 08cef8fc | Thomas Thrainer | """
|
39 | 08cef8fc | Thomas Thrainer | if not module_under_test.startswith("ganeti.cmdlib"): |
40 | 08cef8fc | Thomas Thrainer | module_under_test = "ganeti.cmdlib." + module_under_test
|
41 | 08cef8fc | Thomas Thrainer | return mock.patch("%s.%s" % (module_under_test, mock_module)) |