blob: 858e77cd0649c33bddfd458b2989d331c487465f [file] [log] [blame]
Matthew Treinish9b4d5882013-10-24 20:00:11 +00001# Copyright 2010 United States Government as represented by the
2# Administrator of the National Aeronautics and Space Administration.
3# Copyright 2013 Hewlett-Packard Development Company, L.P.
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import fixtures
19import mock
20
21
22class PatchObject(fixtures.Fixture):
23 """Deal with code around mock."""
24
25 def __init__(self, obj, attr, **kwargs):
26 self.obj = obj
27 self.attr = attr
28 self.kwargs = kwargs
29
30 def setUp(self):
31 super(PatchObject, self).setUp()
32 _p = mock.patch.object(self.obj, self.attr, **self.kwargs)
33 self.mock = _p.start()
34 self.addCleanup(_p.stop)
35
36
37class Patch(fixtures.Fixture):
38
39 """Deal with code around mock.patch."""
40
41 def __init__(self, obj, **kwargs):
42 self.obj = obj
43 self.kwargs = kwargs
44
45 def setUp(self):
46 super(Patch, self).setUp()
47 _p = mock.patch(self.obj, **self.kwargs)
48 self.mock = _p.start()
49 self.addCleanup(_p.stop)