~larry-e-works/uci-engine/amqp-to-kombu

« back to all changes in this revision

Viewing changes to cupstream2distro/tests/unit/__init__.py

  • Committer: Francis Ginther
  • Date: 2014-06-10 20:42:46 UTC
  • mto: This revision was merged to the branch mainline in revision 571.
  • Revision ID: francis.ginther@canonical.com-20140610204246-b1bsrik7nlcolqy7
Import lp:cupstream2distro rev 605.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright: (C) 2013 Canonical
 
3
#
 
4
# Authors:
 
5
#  Didier Roche
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify it under
 
8
# the terms of the GNU General Public License as published by the Free Software
 
9
# Foundation; version 3.
 
10
#
 
11
# This program is distributed in the hope that it will be useful, but WITHOUT
 
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
14
# details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License along with
 
17
# this program; if not, write to the Free Software Foundation, Inc.,
 
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
19
 
 
20
 
 
21
import os
 
22
 
 
23
from ..tools import basetestcase
 
24
 
 
25
 
 
26
class BaseUnitTestCase(basetestcase.BaseTestCase):
 
27
    '''Base unit test case module, add all mocks to PATH'''
 
28
 
 
29
    @classmethod
 
30
    def setUpClass(cls):
 
31
        super(BaseUnitTestCase, cls).setUpClass()
 
32
        cls.addToPath(os.path.join("mocks", "offline"))
 
33
        cls.addToPath(os.path.join("mocks", "online"))
 
34
 
 
35
    def setUp(self):
 
36
        super(BaseUnitTestCase, self).setUp()
 
37
        self.create_temp_workdir()
 
38
        os.environ['MOCK_MODE'] = "0"
 
39
        os.environ['MOCK_ERROR_MODE'] = "0"
 
40
 
 
41
 
 
42
class BaseUnitTestCaseWithErrors(BaseUnitTestCase):
 
43
    '''Base unit test case module, simulating errors in mock objects'''
 
44
 
 
45
    def setUp(self):
 
46
        '''Reset the error mode to 1'''
 
47
        super(BaseUnitTestCaseWithErrors, self).setUp()
 
48
        os.environ['MOCK_ERROR_MODE'] = "1"
 
49
 
 
50
    @classmethod
 
51
    def tearDownClass(cls):
 
52
        super(BaseUnitTestCase, cls).setUpClass()
 
53
        try:
 
54
            os.environ.pop('MOCK_ERROR_MODE')
 
55
        except:
 
56
            pass