forked from google/ci_edit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_tests.py
executable file
·166 lines (152 loc) · 4.93 KB
/
unit_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
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
#!/usr/bin/python
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import sys
if not os.getenv('CI_EDIT_USE_REAL_CURSES'):
# Replace curses with a fake version for testing.
sys.path = [os.path.join(os.path.dirname(__file__), 'test_fake')] + sys.path
import app.log
app.log.enabledChannels = {
'error': True,
'info': True,
'meta': True,
'mouse': True,
'startup': True
}
app.log.shouldWritePrintLog = True
# Set up strict_debug before loading other app.* modules.
import app.config
app.config.strict_debug = True
import app.unit_test_actions
import app.unit_test_application
import app.unit_test_automatic_column_adjustment
import app.unit_test_bookmarks
import app.unit_test_brace_matching
import app.unit_test_curses_util
import app.unit_test_file_manager
import app.unit_test_find_window
import app.unit_test_execute_prompt
import app.unit_test_intention
import app.unit_test_parser
import app.unit_test_performance
import app.unit_test_prediction_window
import app.unit_test_prefs
import app.unit_test_regex
import app.unit_test_selectable
import app.unit_test_text_buffer
import app.unit_test_ui
import app.unit_test_undo_redo
import unittest
# Add new test cases here.
TESTS = {
'actions_mouse':
app.unit_test_actions.MouseTestCases,
'actions_text_delete':
app.unit_test_actions.TextDeleteTestCases,
'actions_text_indent':
app.unit_test_actions.TextIndentTestCases,
'actions_text_insert':
app.unit_test_actions.TextInsertTestCases,
'application':
app.unit_test_application.ApplicationTestCases,
'automatic_column_adjustment':
app.unit_test_automatic_column_adjustment.AutomaticColumnAdjustmentCases,
'bookmarks':
app.unit_test_bookmarks.BookmarkTestCases,
'brace_matching':
app.unit_test_brace_matching.BraceMatchingTestCases,
'curses_util':
app.unit_test_curses_util.CursesUtilTestCases,
'file_manager':
app.unit_test_file_manager.FileManagerTestCases,
'find':
app.unit_test_find_window.FindWindowTestCases,
'execute':
app.unit_test_execute_prompt.ExecutePromptTestCases,
'intention':
app.unit_test_intention.IntentionTestCases,
'parser':
app.unit_test_parser.ParserTestCases,
'performance':
app.unit_test_performance.PerformanceTestCases,
'prediction':
app.unit_test_prediction_window.PredictionWindowTestCases,
'prefs':
app.unit_test_prefs.PrefsTestCases,
'regex':
app.unit_test_regex.RegexTestCases,
'selectable':
app.unit_test_selectable.SelectableTestCases,
'draw':
app.unit_test_text_buffer.DrawTestCases,
'ui':
app.unit_test_ui.UiBasicsTestCases,
'undo':
app.unit_test_undo_redo.UndoRedoTestCases,
}
def runTests(tests, stopOnFailure=False):
"""Run through the list of tests."""
for test in tests:
suite = unittest.TestLoader().loadTestsFromTestCase(test)
result = unittest.TextTestRunner(verbosity=2).run(suite)
if stopOnFailure and (result.failures or result.errors):
return 1
return 0
def usage():
print('Help:')
print('./unit_tests.py [--log] [[no] <name>]\n')
print(' --help This help')
print(' --log Print output from app.log.* calls')
print(' no Run all tests except named tests')
print(' <name> Run the named set of tests (only)')
print('The <name> argument is any of:')
testNames = list(TESTS.keys())
testNames.sort()
for i in testNames:
print(' ', i)
def parseArgList(argList):
testList = list(TESTS.values())
try:
argList.remove('--help')
usage()
sys.exit(0)
except ValueError:
pass
try:
useAppLog = False
argList.remove('--log')
useAppLog = True
except ValueError:
pass
if len(argList) > 1:
if not (argList[1] == u"no" or argList[1] in TESTS):
usage()
sys.exit(-1)
if argList[1] == u"no":
for i in argList[2:]:
del testList[testList.index(TESTS[i])]
else:
testList = []
for i in argList[1:]:
testList.append(TESTS[i])
if useAppLog:
app.log.wrapper(lambda: runTests(testList, True))
else:
sys.exit(runTests(testList, True))
if __name__ == '__main__':
parseArgList(sys.argv)