1 # Copyright 2017 Intel Corporation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
20 from yardstick.common import task_template
23 class PluginParserFixture(fixtures.Fixture):
24 """PluginParser fixture.
26 This class is intended to be used as a fixture within unit tests and
27 therefore consumers must register it using useFixture() within their
31 def __init__(self, rendered_plugin):
32 super(PluginParserFixture, self).__init__()
33 self._rendered_plugin = rendered_plugin
36 self.addCleanup(self._restore)
37 self._mock_tasktemplate_render = mock.patch.object(
38 task_template.TaskTemplate, 'render')
39 self.mock_tasktemplate_render = self._mock_tasktemplate_render.start()
40 self.mock_tasktemplate_render.return_value = self._rendered_plugin
41 self._mock_open = mock.patch.object(six.moves.builtins, 'open', create=True)
42 self.mock_open = self._mock_open.start()
43 self.mock_open.side_effect = mock.mock_open()
46 self._mock_tasktemplate_render.stop()
47 self._mock_open.stop()