Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mikf
GitHub Repository: mikf/gallery-dl
Path: blob/master/scripts/run_tests.py
5457 views
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
else:
26
TESTS = [
27
name if name.startswith("test_") else "test_" + name
28
for name in sys.argv[1:]
29
]
30
31
32
suite = unittest.TestSuite()
33
34
for test in TESTS:
35
try:
36
module = __import__(test)
37
except Exception as exc:
38
sys.stderr.write(f"Failed to import {test}: {exc}\n")
39
else:
40
tests = unittest.defaultTestLoader.loadTestsFromModule(module)
41
suite.addTests(tests)
42
43
if __name__ == "__main__":
44
result = unittest.TextTestRunner(verbosity=2).run(suite)
45
if not result.wasSuccessful():
46
sys.exit(1)
47
48