-
Notifications
You must be signed in to change notification settings - Fork 48
/
test_termcolor.py
81 lines (69 loc) · 2.55 KB
/
test_termcolor.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
"""
TODO: Modify unittest doc.
"""
import os
import sys
import unittest
from monty.termcolor import (
cprint,
cprint_map,
enable,
get_terminal_size,
stream_has_colours,
)
class FuncTest(unittest.TestCase):
def test_remove_non_ascii(self):
enable(True)
print("Current terminal type: %s" % os.getenv("TERM"))
print("Test basic colors:")
cprint("Grey color", "grey")
cprint("Red color", "red")
cprint("Green color", "green")
cprint("Yellow color", "yellow")
cprint("Blue color", "blue")
cprint("Magenta color", "magenta")
cprint("Cyan color", "cyan")
cprint("White color", "white")
print("-" * 78)
print("Test highlights:")
cprint("On grey color", on_color="on_grey")
cprint("On red color", on_color="on_red")
cprint("On green color", on_color="on_green")
cprint("On yellow color", on_color="on_yellow")
cprint("On blue color", on_color="on_blue")
cprint("On magenta color", on_color="on_magenta")
cprint("On cyan color", on_color="on_cyan")
cprint("On white color", color="grey", on_color="on_white")
print("-" * 78)
print("Test attributes:")
cprint("Bold grey color", "grey", attrs=["bold"])
cprint("Dark red color", "red", attrs=["dark"])
cprint("Underline green color", "green", attrs=["underline"])
cprint("Blink yellow color", "yellow", attrs=["blink"])
cprint("Reversed blue color", "blue", attrs=["reverse"])
cprint("Concealed Magenta color", "magenta", attrs=["concealed"])
cprint(
"Bold underline reverse cyan color",
"cyan",
attrs=["bold", "underline", "reverse"],
)
cprint(
"Dark blink concealed white color",
"white",
attrs=["dark", "blink", "concealed"],
)
print("-" * 78)
print("Test mixing:")
cprint("Underline red on grey color", "red", "on_grey", ["underline"])
cprint("Reversed green on red color", "green", "on_red", ["reverse"])
# Test cprint_keys
cprint_map("Hello world", {"Hello": "red"})
cprint_map("Hello world", {"Hello": {"color": "blue", "on_color": "on_red"}})
# Test terminal size.
print("terminal size: %s", get_terminal_size())
enable(False)
def test_stream_has_colors(self):
# TODO: not a real test. Need to do a proper test.
stream_has_colours(sys.stdout)
if __name__ == "__main__":
unittest.main()