forked from unknown-horizons/unknown-horizons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
executable file
·90 lines (69 loc) · 2.23 KB
/
run_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
#!/usr/bin/env python2
# ###################################################
# Copyright (C) 2008-2013 The Unknown Horizons Team
# This file is part of Unknown Horizons.
#
# Unknown Horizons is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# ###################################################
import gettext
import sys
try:
import nose
except ImportError:
print 'The nose package is needed to run the UH tests.'
sys.exit(1)
try:
import mock
except ImportError:
print 'The mock package is needed to run the UH tests.'
sys.exit(1)
from horizons.ext.dummy import Dummy
def mock_fife():
"""
Using a custom import hook, we catch all imports of fife and provide a
dummy module.
"""
class Importer(object):
def find_module(self, fullname, path=None):
if fullname.startswith('fife'):
return self
return None
def load_module(self, name):
mod = sys.modules.setdefault(name, Dummy())
return mod
sys.meta_path = [Importer()]
def setup_horizons():
"""
Get ready for testing.
"""
# This needs to run at first to avoid that other code gets a reference to
# the real fife module
mock_fife()
# set global reference to fife
import horizons.globals
import fife
horizons.globals.fife = fife.fife
from run_uh import create_user_dirs
create_user_dirs()
import horizons.i18n
horizons.i18n.change_language()
if __name__ == '__main__':
gettext.install('', unicode=True) # no translations here
setup_horizons()
from tests.gui import GuiTestPlugin
from tests.utils import ReRunInfoPlugin
nose.run(defaultTest='tests', addplugins=[GuiTestPlugin(), ReRunInfoPlugin()])