~ubuntu-branches/ubuntu/wily/python-oslo.vmware/wily

« back to all changes in this revision

Viewing changes to tests/base.py

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2014-03-05 15:29:17 UTC
  • Revision ID: package-import@ubuntu.com-20140305152917-9n6zp4cktcwyr3ul
Tags: upstream-0.2
ImportĀ upstreamĀ versionĀ 0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Copyright 2010-2011 OpenStack Foundation
 
4
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
 
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 os
 
19
 
 
20
import fixtures
 
21
import testtools
 
22
 
 
23
_TRUE_VALUES = ('true', '1', 'yes')
 
24
 
 
25
# FIXME(dhellmann) Update this to use oslo.test library
 
26
 
 
27
 
 
28
class TestCase(testtools.TestCase):
 
29
 
 
30
    """Test case base class for all unit tests."""
 
31
 
 
32
    def setUp(self):
 
33
        """Run before each test method to initialize test environment."""
 
34
 
 
35
        super(TestCase, self).setUp()
 
36
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
 
37
        try:
 
38
            test_timeout = int(test_timeout)
 
39
        except ValueError:
 
40
            # If timeout value is invalid do not set a timeout.
 
41
            test_timeout = 0
 
42
        if test_timeout > 0:
 
43
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
 
44
 
 
45
        self.useFixture(fixtures.NestedTempfile())
 
46
        self.useFixture(fixtures.TempHomeDir())
 
47
 
 
48
        if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
 
49
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
 
50
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
 
51
        if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
 
52
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
 
53
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
 
54
 
 
55
        self.log_fixture = self.useFixture(fixtures.FakeLogger())