Debian Codegraph @

scripts/run_tests.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 # Copyright 2021 Mike Fährmann
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as
8 # published by the Free Software Foundation.
9
10 import os
11 import sys
12 import unittest
13
14 TEST_DIRECTORY = os.path.join(
15 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "test")
16
17 sys.path.insert(0, TEST_DIRECTORY)
18
19 if len(sys.argv) <= 1:
20 TESTS = [
21 file.rpartition(".")[0]
22 for file in os.listdir(TEST_DIRECTORY)
23 if file.startswith("test_") and file != "test_results.py"
24 ]
25
26 import random
27 random.shuffle(TESTS)
28 else:
29 TESTS = [
30 name if name.startswith("test_") else "test_" + name
31 for name in sys.argv[1:]
32 ]
33
34
35 suite = unittest.TestSuite()
36
37 for test in TESTS:
38 try:
39 module = __import__(test)
40 except Exception as exc:
41 sys.stderr.write(f"Failed to import {test}: {exc}\n")
42 else:
43 tests = unittest.defaultTestLoader.loadTestsFromModule(module)
44 suite.addTests(tests)
45
46 if __name__ == "__main__":
47 result = unittest.TextTestRunner(verbosity=2).run(suite)
48 if not result.wasSuccessful():
49 sys.exit(1)