| Matthew Treinish | 9b4d588 | 2013-10-24 20:00:11 +0000 | [diff] [blame] | 1 | # 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 |  | 
|  | 18 | import fixtures | 
|  | 19 | import mock | 
|  | 20 |  | 
|  | 21 |  | 
|  | 22 | class 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 |  | 
|  | 37 | class 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) |