1 # -*- coding: utf-8 -*-
3 # Copyright 2010-2011 OpenStack Foundation
4 # Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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
24 from toscaparser.tosca_template import ToscaTemplate
26 _TRUE_VALUES = ('True', 'true', '1', 'yes')
29 class TestCase(testscenarios.TestWithScenarios, testtools.TestCase):
31 """Test case base class for all unit tests."""
34 """Run before each test method to initialize test environment."""
36 super(TestCase, self).setUp()
37 test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
39 test_timeout = int(test_timeout)
41 # If timeout value is invalid do not set a timeout.
44 self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
46 self.useFixture(fixtures.NestedTempfile())
47 self.useFixture(fixtures.TempHomeDir())
49 if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
50 stdout = self.useFixture(fixtures.StringStream('stdout')).stream
51 self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
52 if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
53 stderr = self.useFixture(fixtures.StringStream('stderr')).stream
54 self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
56 self.log_fixture = self.useFixture(fixtures.FakeLogger())
58 def _load_template(self, filename):
59 """Load a Tosca template from tests data folder.
61 :param filename: Tosca template file name to load.
62 :return: ToscaTemplate
64 return ToscaTemplate(os.path.join(
65 os.path.dirname(os.path.abspath(__file__)),