Debian Codegraph @

lib/tests/__init__.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 # Copyright (C) 2008 Lukáš Lalinský <[email protected]om>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 # The QBrz makefile
21 #
22
23 import os
24 import sys
25 from breezy import (
26 tests,
27 trace,
28 )
29
30 try:
31 from PyQt5 import QtGui, QtTest, QtWidgets
32 except ImportError:
33 pass
34
35
36 def load_tests(loader, basic_tests, pattern):
37 testmod_names = [
38 'mock',
39 'test_annotate',
40 'test_autocomplete',
41 'test_bugs',
42 'test_cat',
43 'test_commit',
44 'test_commit_data',
45 # 'test_diffview', # - broken by API changes
46 'test_extra_isignored',
47 'test_extra_isversioned',
48 'test_i18n',
49 'test_log',
50 'test_loggraphviz',
51 'test_logmodel',
52 'test_revisionmessagebrowser',
53 # RJLRJL ignore spellcheck for now
54 'test_spellcheck',
55 'test_subprocess',
56 'test_tree_branch',
57 'test_treewidget',
58 'test_util',
59 'test_decorator',
60 'test_guidebar',
61 'test_extdiff',
62 ]
63 for name in testmod_names:
64 m = "%s.%s" % (__name__, name)
65 try:
66 basic_tests.addTests(loader.loadTestsFromModuleName(m))
67 except ImportError as e:
68 if str(e).endswith('PyQt5'):
69 trace.note('QBrz: skip module %s because PyQt5 is not installed' % m)
70 else:
71 raise
72 return basic_tests
73
74 # The application should be initialized only once pre process, but this should
75 # be delayed until the first tests is run in a given process, doing it when the
76 # tests are loaded is too early and failed for selftest --parallel=fork
77 _qt_app = None
78
79 class QTestCase(tests.TestCaseWithTransport):
80
81 def setUp(self):
82 super(QTestCase, self).setUp()
83 global _qt_app
84 if _qt_app is None:
85 _qt_app = QtWidgets.QApplication(sys.argv)
86 def excepthook_tests(eclass, evalue, tb):
87 def _reraise_on_cleanup():
88 raise eclass(evalue).with_traceback(tb)
89 self.addCleanup(_reraise_on_cleanup)
90 self.overrideAttr(sys, "excepthook", excepthook_tests)
91
92 def waitUntil(self, break_condition, timeout, timeout_msg=None):
93 erapsed = 0
94 while (True):
95 if break_condition():
96 # RJL: Give ourselves a little bit more time. Tests
97 # are less flaky (but still flaky)
98 QtTest.QTest.qWait(200)
99 return
100 if timeout < erapsed:
101 self.fail(timeout_msg or 'Timeout!')
102 QtTest.QTest.qWait(200)
103 erapsed += 200