-
-
Notifications
You must be signed in to change notification settings - Fork 120
/
misc_tests.py
78 lines (62 loc) · 2.39 KB
/
misc_tests.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Tests for cement.utils.misc."""
from cement.utils import test, misc
APP = misc.rando()[:12]
class BackendTestCase(test.CementCoreTestCase):
def test_defaults(self):
defaults = misc.init_defaults('APPp', 'section2', 'section3')
defaults['APPp']['debug'] = True
defaults['section2']['foo'] = 'bar'
self.app = self.make_app('APPp', config_defaults=defaults)
self.app.setup()
self.eq(self.app.config.get('APPp', 'debug'), True)
self.ok(self.app.config.get_section_dict('section2'))
def test_minimal_logger(self):
log = misc.minimal_logger(__name__)
log = misc.minimal_logger(__name__, debug=True)
log.info('info test')
log.warn('warn test')
log.error('error test')
log.fatal('fatal test')
log.debug('debug test')
log.info('info test with namespce', 'test_namespace')
log.info('info test with extra kwargs', extra=dict(foo='bar'))
log.info('info test with extra kwargs', extra=dict(namespace='foo'))
# set logging back to non-debug
misc.minimal_logger(__name__, debug=False)
pass
def test_wrap_str(self):
text = "aaaaa bbbbb ccccc"
new_text = misc.wrap(text, width=5)
parts = new_text.split('\n')
self.eq(len(parts), 3)
self.eq(parts[1], 'bbbbb')
new_text = misc.wrap(text, width=5, indent='***')
parts = new_text.split('\n')
self.eq(parts[2], '***ccccc')
def test_wrap_unicode(self):
text = u"aaaaa bbbbb ccccc"
new_text = misc.wrap(text, width=5)
parts = new_text.split('\n')
self.eq(len(parts), 3)
self.eq(parts[1], u'bbbbb')
new_text = misc.wrap(text, width=5, indent='***')
parts = new_text.split('\n')
self.eq(parts[2], u'***ccccc')
@test.raises(TypeError)
def test_wrap_int(self):
text = int('1' * 80)
try:
new_text = misc.wrap(text, width=5)
except TypeError as e:
self.eq(e.args[0],
"Argument `text` must be one of [str, unicode].")
raise
@test.raises(TypeError)
def test_wrap_none(self):
text = None
try:
new_text = misc.wrap(text, width=5)
except TypeError as e:
self.eq(e.args[0],
"Argument `text` must be one of [str, unicode].")
raise