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
|
"Test editor, coverage 35%."
from idlelib import editor
import unittest
from test.support import requires
from tkinter import Tk
Editor = editor.EditorWindow
class EditorWindowTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
requires('gui')
cls.root = Tk()
cls.root.withdraw()
@classmethod
def tearDownClass(cls):
cls.root.update_idletasks()
for id in cls.root.tk.call('after', 'info'):
cls.root.after_cancel(id)
cls.root.destroy()
del cls.root
def test_init(self):
e = Editor(root=self.root)
self.assertEqual(e.root, self.root)
e._close()
class TestGetLineIndent(unittest.TestCase):
def test_empty_lines(self):
for tabwidth in [1, 2, 4, 6, 8]:
for line in ['', '\n']:
with self.subTest(line=line, tabwidth=tabwidth):
self.assertEqual(
editor.get_line_indent(line, tabwidth=tabwidth),
(0, 0),
)
def test_tabwidth_4(self):
# (line, (raw, effective))
tests = (('no spaces', (0, 0)),
# Internal space isn't counted.
(' space test', (4, 4)),
('\ttab test', (1, 4)),
('\t\tdouble tabs test', (2, 8)),
# Different results when mixing tabs and spaces.
(' \tmixed test', (5, 8)),
(' \t mixed test', (5, 6)),
('\t mixed test', (5, 8)),
# Spaces not divisible by tabwidth.
(' \tmixed test', (3, 4)),
(' \t mixed test', (3, 5)),
('\t mixed test', (3, 6)),
# Only checks spaces and tabs.
('\nnewline test', (0, 0)))
for line, expected in tests:
with self.subTest(line=line):
self.assertEqual(
editor.get_line_indent(line, tabwidth=4),
expected,
)
def test_tabwidth_8(self):
# (line, (raw, effective))
tests = (('no spaces', (0, 0)),
# Internal space isn't counted.
(' space test', (8, 8)),
('\ttab test', (1, 8)),
('\t\tdouble tabs test', (2, 16)),
# Different results when mixing tabs and spaces.
(' \tmixed test', (9, 16)),
(' \t mixed test', (9, 10)),
('\t mixed test', (9, 16)),
# Spaces not divisible by tabwidth.
(' \tmixed test', (3, 8)),
(' \t mixed test', (3, 9)),
('\t mixed test', (3, 10)),
# Only checks spaces and tabs.
('\nnewline test', (0, 0)))
for line, expected in tests:
with self.subTest(line=line):
self.assertEqual(
editor.get_line_indent(line, tabwidth=8),
expected,
)
if __name__ == '__main__':
unittest.main(verbosity=2)
|