CLITestCase.tearDown()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
1
'''
2
Created on Feb 22, 2014
3
4
@author: sean
5
'''
6
import logging
7
import io
8
import unittest
9
import mock
10
11
from binstar_client import tests
12
13
14
class AnyIO(io.StringIO):
15
    def write(self, msg):
16
        if hasattr('msg', 'decode'):
17
            msg = msg.decode()
18
        return io.StringIO.write(self, msg)
19
20
21
class CLITestCase(unittest.TestCase):
22
    def setUp(self):
23
        self.get_config_patch = mock.patch('binstar_client.utils.get_config')
24
        self.get_config = self.get_config_patch.start()
25
        self.get_config.return_value = {}
26
27
        self.load_token_patch = mock.patch('binstar_client.utils.config.load_token')
28
        self.load_token = self.load_token_patch.start()
29
        self.load_token.return_value = '123'
30
31
        self.store_token_patch = mock.patch('binstar_client.utils.config.store_token')
32
        self.store_token = self.store_token_patch.start()
33
34
        self.setup_logging_patch = mock.patch('binstar_client.scripts.cli._setup_logging')
35
        self.setup_logging_patch.start()
36
37
        self.logger = logger = logging.getLogger('binstar')
38
        logger.setLevel(logging.INFO)
39
        self.stream = AnyIO()
40
        self.hndlr = hndlr = logging.StreamHandler(stream=self.stream)
41
        hndlr.setLevel(logging.INFO)
42
        logger.addHandler(hndlr)
43
44
    def tearDown(self):
45
        self.setup_logging_patch.stop()
46
        self.get_config_patch.stop()
47
        self.load_token_patch.stop()
48
        self.store_token_patch.stop()
49
50
        self.logger.removeHandler(self.hndlr)
51