-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.py
169 lines (132 loc) · 8.18 KB
/
test.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import unittest
import sys
import collections
from pyprnt.util import get_terminal_size
from pyprnt.util import border
from pyprnt import prnt
class TestTerminalMethods(unittest.TestCase):
def test_get_terminal_size(self):
testee = get_terminal_size()
expect = 1
self.assertGreater(testee, expect)
class TestBorderMethods(unittest.TestCase):
def test_top_border(self):
testee = border("top", label=5, value=5, width=20)
expect = "┌─────┬─────┐"
self.assertEqual(testee, expect)
def test_bottom_border(self):
testee = border("bottom", label=5, value=5, width=20)
expect = "└─────┴─────┘"
self.assertEqual(testee, expect)
def test_exceed_border(self):
testee1 = border("top", label=5, value=20, width=20)
testee2 = len(testee1)
expect1 = "┌─────┬────────────┐"
expect2 = 20
self.assertEqual(testee1, expect1)
self.assertEqual(testee2, expect2)
class TestPrintEnable(unittest.TestCase):
def test_enable_false(self):
creation = ['Adam', 'Eve']
testee = prnt(creation, enable=False, output=True, width=50)
expect = "['Adam', 'Eve']"
self.assertEqual(testee, expect)
class TestPrintBoth(unittest.TestCase):
def test_both_true(self):
creation = ['Adam', 'Eve']
testee = prnt(creation, both=True, output=True, width=50)
expect = "['Adam', 'Eve']\n┌─┬────┐\n│0│Adam│\n│1│Eve │\n└─┴────┘"
self.assertEqual(testee, expect)
class TestPrintTruncate(unittest.TestCase):
def test_truncate_false(self):
testee = prnt(["abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", 12345678910], output=True, width=50)
expect = "┌─┬──────────────────────────────────────────────┐\n│0│abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst│\n│ │uvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmn│\n│ │opqrstuvwxyzabcdefghijklmnopqrstuvwxyz │\n│1│12345678910 │\n└─┴──────────────────────────────────────────────┘"
self.assertEqual(testee, expect)
def test_truncate_true(self):
testee = prnt(["abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", 12345678910], truncate=True, output=True, width=50)
expect = "┌─┬──────────────────────────────────────────────┐\n│0│abcdefghijklmnopqrstuvwxyzabcdefghijklmnopq...│\n│1│12345678910 │\n└─┴──────────────────────────────────────────────┘"
self.assertEqual(testee, expect)
class TestPrintDepth(unittest.TestCase):
def test_depth_infinity_basic(self):
testee = prnt([[[]], []], output=True, width=50)
print(repr(testee))
expect = "┌─┬──────┐\n│0│┌─┬──┐│\n│ ││0│[]││\n│ │└─┴──┘│\n│1│[] │\n└─┴──────┘"
self.assertEqual(testee, expect)
def test_depth_infinity_complex(self):
testee = prnt([[[{}]], []], output=True, width=50)
expect = "┌─┬──────────┐\n│0│┌─┬──────┐│\n│ ││0│┌─┬──┐││\n│ ││ ││0│{}│││\n│ ││ │└─┴──┘││\n│ │└─┴──────┘│\n│1│[] │\n└─┴──────────┘"
self.assertEqual(testee, expect)
def test_depth_1_basic(self):
testee = prnt([[[]], []], depth=1, output=True, width=50)
print(repr(testee))
expect = "┌─┬────┐\n│0│[[]]│\n│1│[] │\n└─┴────┘"
self.assertEqual(testee, expect)
def test_depth_1_complex(self):
testee = prnt([[[{}]], []], depth=1, output=True, width=50)
expect = "┌─┬──────┐\n│0│[[{}]]│\n│1│[] │\n└─┴──────┘"
self.assertEqual(testee, expect)
def test_depth_2_basic(self):
testee = prnt([[[]], []], depth=2, output=True, width=50)
print(repr(testee))
expect = "┌─┬──────┐\n│0│┌─┬──┐│\n│ ││0│[]││\n│ │└─┴──┘│\n│1│[] │\n└─┴──────┘"
self.assertEqual(testee, expect)
def test_depth_2_complex(self):
testee = prnt([[[{}]], []], depth=2, output=True, width=50)
expect = "┌─┬────────┐\n│0│┌─┬────┐│\n│ ││0│[{}]││\n│ │└─┴────┘│\n│1│[] │\n└─┴────────┘"
self.assertEqual(testee, expect)
class TestPrintWidth(unittest.TestCase):
def test_width_minimum_20(self):
testee = prnt(["Kevin Kim is a developer."], output=True, width=20)
expect = "┌─┬────────────────┐\n│0│Kevin Kim is a d│\n│ │eveloper. │\n└─┴────────────────┘"
self.assertEqual(testee, expect)
class TestPrintSep(unittest.TestCase):
def test_separator_empty(self):
testee = prnt("010", "8282", "8282", output=True, width=50)
expect = "010 8282 8282"
self.assertEqual(testee, expect)
def test_separator_dash(self):
testee = prnt("010", "8282", "8282", sep="-", output=True, width=50)
expect = "010-8282-8282"
self.assertEqual(testee, expect)
class TestPrintEnd(unittest.TestCase):
def test_end_empty(self):
testee = prnt("010", "8282", "8282", end="", output=True, width=50)
expect = "010 8282 8282"
self.assertEqual(testee, expect)
def test_end_newline(self):
testee = prnt("010", "8282", "8282", output=True, width=50)
expect = "010 8282 8282"
self.assertEqual(testee, expect)
def test_end_dash(self):
testee = prnt("010", "8282", "8282", end="--", output=True, width=50)
expect = "010 8282 8282--"
self.assertEqual(testee, expect)
class TestPrintBasic(unittest.TestCase):
def test_list_basic(self):
creation = ["Adam", "Eve"]
testee = prnt(creation, output=True, width=50)
expect = "┌─┬────┐\n│0│Adam│\n│1│Eve │\n└─┴────┘"
self.assertEqual(testee, expect)
def test_dict_basic(self):
# For python version 3.4 and below
menu = collections.OrderedDict()
menu["kimchi"] = 5000
menu["Ice Cream"] = 100
testee = prnt(menu, output=True, width=50)
expect = "┌─────────┬────┐\n│kimchi │5000│\n│Ice Cream│100 │\n└─────────┴────┘"
self.assertEqual(testee, expect)
def test_list_with_newline(self):
creation = ["Ad\nam", "Eve"]
testee = prnt(creation, output=True, width=50)
expect = "┌─┬──────┐\n│0│Ad\\nam│\n│1│Eve │\n└─┴──────┘"
self.assertEqual(testee, expect)
def test_dict_with_newline(self):
# For python version 3.4 and below
menu = collections.OrderedDict()
menu["kimchi"] = 5000
menu["Ice\nCream"] = "1 €\n1.08 $"
testee = prnt(menu, output=True, width=50)
expect = "┌──────────┬───────────┐\n│kimchi │5000 │\n│Ice\\nCream│1 €\\n1.08 $│\n└──────────┴───────────┘"
self.assertEqual(testee, expect)
if __name__ == "__main__":
unittest.main()