38
44
# This list also determines the order in which tests will executed
40
46
'package', 'translations',
41
'utils', 'errors', 'signals',
42
'fs', 'config', 'applications', 'async',
43
'parsing', 'formats', 'templates',
47
'datetimetz', 'utils', 'errors', 'signals',
49
'config', 'applications',
50
'parsing', 'formats', 'templates', 'objectmanager',
44
51
'stores', 'index', 'notebook', 'history',
46
52
'export', 'www', 'search',
47
53
'widgets', 'gui', 'pageview', 'clipboard',
48
55
'calendar', 'printtobrowser', 'versioncontrol', 'inlinecalculator',
49
56
'tasklist', 'tags', 'imagegenerators', 'tableofcontents',
50
57
'quicknote', 'attachmentbrowser', 'insertsymbol',
62
mydir = os.path.dirname(__file__)
54
65
# when a test is missing from the list that should be detected
55
66
for file in glob.glob(os.path.dirname(__file__) + '/*.py'):
56
67
name = os.path.basename(file)[:-3]
57
68
if name != '__init__' and not name in __all__:
58
69
raise AssertionError, 'Test missing in __all__: %s' % name
71
# get our own data dir
72
DATADIR = os.path.abspath(os.path.join(mydir, 'data'))
61
74
# get our own tmpdir
62
TMPDIR = os.path.abspath('./tests/tmp')
75
TMPDIR = os.path.abspath(os.path.join(mydir, 'tmp'))
63
76
# Wanted to use tempfile.get_tempdir here to put everything in
64
77
# e.g. /tmp/zim but since /tmp is often mounted as special file
65
78
# system this conflicts with thrash support. For writing in source
72
85
TMPDIR = TMPDIR.encode(sys.getfilesystemencoding())
87
# also get the default tmpdir and put a copy in the env
88
REAL_TMPDIR = tempfile.gettempdir()
75
91
def load_tests(loader, tests, pattern):
76
92
'''Load all test cases and return a unittest.TestSuite object.
92
108
'ZIM_TEST_RUNNING': 'True',
93
109
'ZIM_TEST_ROOT': os.getcwd(),
111
'REAL_TMP': REAL_TMPDIR,
95
112
'XDG_DATA_HOME': os.path.join(TMPDIR, 'data_home'),
96
113
'XDG_DATA_DIRS': os.path.join(TMPDIR, 'data_dir'),
97
114
'XDG_CONFIG_HOME': os.path.join(TMPDIR, 'config_home'),
184
def tearDownClass(cls):
186
gtk_process_events() # flush any pending events / warnings
166
188
def assertEqual(self, first, second, msg=None):
167
## HACK to work around bug in unittest - it does not consider
189
## HACK to work around "feature" in unittest - it does not consider
168
190
## string and unicode to be of the same type and thus does not
170
## TODO file bug report for this
191
## show diffs if the textual content differs
171
192
if type(first) in (str, unicode) \
172
193
and type(second) in (str, unicode):
173
self.assertMultiLineEqual(second, first, msg)
174
## HACK switch arguments here, otherwise order of
175
## diff is wrong (assuming first is what we got and second
194
self.assertMultiLineEqual(first, second, msg)
178
196
unittest.TestCase.assertEqual(self, first, second, msg)
199
215
assert not os.path.exists(path), 'This path should not exist: %s' % path
218
def clear_tmp_dir(self, name=None):
219
'''Clears the tmp dir for this test'''
220
path = self._get_tmp_name(name)
221
if os.path.exists(path):
223
assert not os.path.exists(path) # make real sure
202
225
def _get_tmp_name(self, name):
204
227
assert not os.path.sep in name, 'Don\'t use this method to get sub folders or files'
219
242
using the "with" keyword. To subclass it you only need to set the
220
243
logger to be used and (the begin of) the message to filter.
245
The message can be a string, or a list or tuple of strings. Any
246
messages that start with this string or any of these strings are
222
249
Alternatively you can call L{wrap_test()} from test C{setUp}.
223
This will start the filter and make sure it is cleanep up again.
250
This will start the filter and make sure it is cleaned up again.
229
256
def __init__(self, logger=None, message=None):
230
if logger: self.logger = logger
231
if message: self.message = message
261
self.message = message
233
263
self.loggerobj = logging.getLogger(self.logger)
515
547
def __getattr__(self, name):
516
548
'''Automatically mock methods'''
517
return self.mock_method(name, None)
549
if name == '__zim_extension_objects__':
552
return self.mock_method(name, None)
520
555
def gtk_process_events(*a):
521
556
'''Method to simulate a few iterations of the gtk main loop'''
557
assert gtk is not None
523
558
while gtk.events_pending():
524
559
gtk.main_iteration(block=False)
525
560
return True # continue