-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_util.py
56 lines (40 loc) · 1.58 KB
/
test_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, division
import unittest
import sys
import logging
import six
from pullover import util
class TestPrintError(unittest.TestCase):
_MESSAGE = 'test message'
def test_stream(self):
try:
sys.stderr = six.StringIO()
util.print_error(self._MESSAGE)
self.assertEquals(sys.stderr.getvalue(), self._MESSAGE + '\n')
finally:
sys.stderr = sys.__stderr__
class TestDecodeCliArg(unittest.TestCase):
_ARG_VALUE = 'test_arg_value'
def test_empty(self):
with self.assertRaises(ValueError):
util.decode_cli_arg(None)
@unittest.skipUnless(sys.version_info.major == 2,
'Only applies to Python 2')
def test_valid_2(self):
self.assertEqual(
util.decode_cli_arg(
self._ARG_VALUE.encode(sys.getfilesystemencoding())),
self._ARG_VALUE)
@unittest.skipUnless(sys.version_info.major == 3,
'Only applies to Python 3')
def test_valid_3(self):
self.assertEqual(util.decode_cli_arg(self._ARG_VALUE), self._ARG_VALUE)
class TestLogLevelFromVerbosity(unittest.TestCase):
def test_warning(self):
self.assertEqual(util.log_level_from_vebosity(0), logging.WARNING)
def test_info(self):
self.assertEqual(util.log_level_from_vebosity(1), logging.INFO)
def test_debug(self):
self.assertEqual(util.log_level_from_vebosity(2), logging.DEBUG)
self.assertEqual(util.log_level_from_vebosity(None), logging.DEBUG)