-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_output.py
114 lines (86 loc) · 2.88 KB
/
test_output.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from __future__ import unicode_literals
import sys
import unittest
try:
from io import StringIO
except:
from StringIO import StringIO
from green.output import Colors, GreenStream, debug
import green.output
class TestDebug(unittest.TestCase):
def testDebug(self):
"""
debug() works as we expect
"""
orig_logging = green.output.logging.debug
s = StringIO()
green.output.logging.debug = s.write
green.output.debug_level = 0
debug("Nothing should happen", level=1)
self.assertEqual('', s.getvalue())
green.output.debug_level = 2
debug("Something should happen", level=1)
self.assertNotEqual('', s.getvalue())
green.output.logging.debug = orig_logging
class TestColors(unittest.TestCase):
def testTermcolorTrue(self):
"""
termcolor=True results in terminal output
"""
c = Colors(termcolor=True)
self.assertTrue(c.termcolor)
self.assertTrue(len(c.bold("")) > 0)
def testTermcolorFalse(self):
"""
termcolor=False results in no terminal output
"""
c = Colors(termcolor=False)
self.assertFalse(c.termcolor)
self.assertFalse(len(c.bold("")) > 0)
def testTermcolorAuto(self):
"""
termcolor=None causes termcolor autodetected and set to True or False
"""
c = Colors()
self.assertTrue(c.termcolor in [True, False])
def testUp(self):
"""
calling up gives us a non-blank string
"""
c = Colors()
up = c.up()
self.assertEqual(type(up), str)
self.assertNotEqual(up, '')
def testTermstyleColorsDoNotCrash(self):
"""
termstyle-based colors don't crash and output something
"""
c = Colors(termcolor=True)
for func in [c.bold, c.blue, c.green, c.red, c.yellow, c.passing,
c.failing, c.error, c.skipped, c.unexpectedSuccess,
c.expectedFailure, c.moduleName]:
self.assertTrue(len(func("")) > 0)
# c.className is a special case
c.className("")
class TestGreenStream(unittest.TestCase):
def testFormatText(self):
"""
formatText returns the input text by default
"""
s = StringIO()
gs = GreenStream(s)
msg = u"Unindented line.\n Indented.\n Double-indented.\n\n\n"
self.assertEqual(gs.formatText(msg), str(msg))
def testBadStringType(self):
"""
passing the wrong stream type to GreenStream gets auto-converted
"""
s = StringIO()
gs = GreenStream(s)
msg = "some string"
if sys.version_info[0] == 3: # pragma: no cover
bad_str = bytes(msg, 'utf-8')
else: # pragma: no cover
bad_str = str(msg)
gs.write(bad_str)
self.assertEqual(s.getvalue(), msg)