15 # this was renamed in Python 3, provide backwards compatible name
16 if sys
.version_info
[:2] == (2, 7):
17 unittest
.TestCase
.assertRaisesRegex
= unittest
.TestCase
.assertRaisesRegexp
19 if sys
.version_info
[0] == 3:
20 unittest
.TestCase
.assertRegexpMatches
= unittest
.TestCase
.assertRegex
21 unittest
.TestCase
.assertRaisesRegexp
= unittest
.TestCase
.assertRaisesRegex
23 if '--help' in sys
.argv
:
24 print("Usage: ./runtests.py <testfiles>")
28 def dbus_launch_session():
29 if os
.name
== "nt" or sys
.platform
== "darwin":
33 out
= subprocess
.check_output([
34 "dbus-daemon", "--session", "--fork", "--print-address=1",
36 except (subprocess
.CalledProcessError
, OSError):
39 if sys
.version_info
[0] == 3:
40 out
= out
.decode("utf-8")
41 addr
, pid
= out
.splitlines()
45 pid
, addr
= dbus_launch_session()
47 os
.environ
["DBUS_SESSION_BUS_ADDRESS"] = addr
48 atexit
.register(os
.kill
, pid
, signal
.SIGKILL
)
50 os
.environ
["DBUS_SESSION_BUS_ADDRESS"] = "."
52 mydir
= os
.path
.dirname(os
.path
.abspath(__file__
))
53 tests_builddir
= os
.path
.abspath(os
.environ
.get('TESTS_BUILDDIR', os
.path
.dirname(__file__
)))
54 builddir
= os
.path
.dirname(tests_builddir
)
55 tests_srcdir
= os
.path
.abspath(os
.path
.dirname(__file__
))
56 srcdir
= os
.path
.dirname(tests_srcdir
)
58 sys
.path
.insert(0, tests_srcdir
)
59 sys
.path
.insert(0, srcdir
)
60 sys
.path
.insert(0, tests_builddir
)
61 sys
.path
.insert(0, builddir
)
63 # force untranslated messages, as we check for them in some tests
64 os
.environ
['LC_MESSAGES'] = 'C'
65 os
.environ
['G_DEBUG'] = 'fatal-warnings fatal-criticals'
66 if sys
.platform
== "darwin":
67 # gtk 3.22 has warnings and ciriticals on OS X, ignore for now
68 os
.environ
['G_DEBUG'] = ''
70 # make Gio able to find our gschemas.compiled in tests/. This needs to be set
71 # before importing Gio. Support a separate build tree, so look in build dir
73 os
.environ
['GSETTINGS_BACKEND'] = 'memory'
74 os
.environ
['GSETTINGS_SCHEMA_DIR'] = tests_builddir
75 os
.environ
['G_FILENAME_ENCODING'] = 'UTF-8'
78 gi
.require_version("GIRepository", "2.0")
79 from gi
.repository
import GIRepository
80 repo
= GIRepository
.Repository
.get_default()
81 repo
.prepend_library_path(os
.path
.join(tests_builddir
))
82 repo
.prepend_library_path(os
.path
.join(tests_builddir
, ".libs"))
83 repo
.prepend_search_path(tests_builddir
)
86 def try_require_version(namespace
, version
):
88 gi
.require_version(namespace
, version
)
90 # prevent tests from running with the wrong version
91 sys
.modules
["gi.repository." + namespace
] = None
95 try_require_version("Gtk", os
.environ
.get("TEST_GTK_VERSION", "3.0"))
96 try_require_version("Gdk", os
.environ
.get("TEST_GTK_VERSION", "3.0"))
97 try_require_version("GdkPixbuf", "2.0")
98 try_require_version("Pango", "1.0")
99 try_require_version("PangoCairo", "1.0")
100 try_require_version("Atk", "1.0")
103 gi
.require_versions({
104 "GIMarshallingTests": "1.0",
112 if 'TEST_NAMES' in os
.environ
:
113 names
= os
.environ
['TEST_NAMES'].split()
114 elif 'TEST_FILES' in os
.environ
:
116 for filename
in os
.environ
['TEST_FILES'].split():
117 names
.append(filename
[:-3])
118 elif len(sys
.argv
) > 1:
120 for filename
in sys
.argv
[1:]:
121 names
.append(filename
.replace('.py', ''))
124 for filename
in glob
.iglob(os
.path
.join(mydir
, 'test_*.py')):
125 names
.append(os
.path
.basename(filename
)[:-3])
128 def unittest_to_pytest_name(name
):
129 parts
= name
.split(".")
130 parts
[0] = os
.path
.join(mydir
, parts
[0] + ".py")
131 return "::".join(parts
)
134 sys
.exit(pytest
.main([unittest_to_pytest_name(n
) for n
in names
]))