10 # provide missing unittest decorators and API for python 2.6; these decorators
11 # do not actually work, just avoid the syntax failure
12 if sys.version_info[:2] == (2, 6):
13 def skipUnless(condition, reason):
15 sys.stderr.write('[expected failure] ')
16 return lambda obj: obj
18 unittest.skipUnless = skipUnless
19 unittest.expectedFailure = lambda obj: obj
21 def skipIf(condition, reason):
23 sys.stderr.write('[expected failure] ')
24 return lambda obj: obj
26 unittest.skipIf = skipUnless
28 def assertGreater(self, a, b, msg=None):
30 self.fail('%s not greater than %s' % (repr(a), repr(b)))
32 def assertGreaterEqual(self, a, b, msg=None):
34 self.fail('%s not greater than or equal to %s' % (repr(a), repr(b)))
36 def assertLess(self, a, b, msg=None):
38 self.fail('%s not less than %s' % (repr(a), repr(b)))
40 def assertLessEqual(self, a, b, msg=None):
42 self.fail('%s not less than or equal to %s' % (repr(a), repr(b)))
44 def assertIsInstance(self, obj, cls, msg=None):
45 if not isinstance(obj, cls):
46 self.fail('%s is not an instance of %r' % (repr(obj), cls))
48 unittest.TestCase.assertGreaterEqual = assertGreaterEqual
49 unittest.TestCase.assertGreater = assertGreater
50 unittest.TestCase.assertLessEqual = assertLessEqual
51 unittest.TestCase.assertLess = assertLess
52 unittest.TestCase.assertIsInstance = assertIsInstance
54 if sys.version_info[:2] == (2, 7):
55 unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
57 if '--help' in sys.argv:
58 print("Usage: ./runtests.py <testfiles>")
61 mydir = os.path.dirname(os.path.abspath(__file__))
62 tests_builddir = os.path.abspath(os.environ.get('TESTS_BUILDDIR', os.path.dirname(__file__)))
63 builddir = os.path.dirname(tests_builddir)
65 # we have to do this here instead of Makefile.am so that the implicitly added
66 # directory for the source file comes after the builddir
67 sys.path.insert(0, tests_builddir)
68 sys.path.insert(0, builddir)
70 # force untranslated messages, as we check for them in some tests
71 os.environ['LC_MESSAGES'] = 'C'
72 os.environ['G_DEBUG'] = 'fatal-warnings fatal-criticals'
74 # make Gio able to find our gschemas.compiled in tests/. This needs to be set
75 # before importing Gio. Support a separate build tree, so look in build dir
77 os.environ['GSETTINGS_BACKEND'] = 'memory'
78 os.environ['GSETTINGS_SCHEMA_DIR'] = tests_builddir
79 os.environ['G_FILENAME_ENCODING'] = 'UTF-8'
82 if 'TEST_NAMES' in os.environ:
83 names = os.environ['TEST_NAMES'].split()
84 elif 'TEST_FILES' in os.environ:
86 for filename in os.environ['TEST_FILES'].split():
87 names.append(filename[:-3])
88 elif len(sys.argv) > 1:
90 for filename in sys.argv[1:]:
91 names.append(filename.replace('.py', ''))
94 for filename in glob.iglob(os.path.join(mydir, 'test_*.py')):
95 names.append(os.path.basename(filename)[:-3])
97 loader = unittest.TestLoader()
98 suite = loader.loadTestsFromNames(names)
102 runner = unittest.TextTestRunner(verbosity=2)
103 result = runner.run(suite)
104 if not result.wasSuccessful():
105 sys.exit(1) # exit code so "make check" reports error