File: run_tests.py

package info (click to toggle)
gallery-dl 1.31.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,756 kB
  • sloc: python: 58,716; makefile: 9
file content (46 lines) | stat: -rwxr-xr-x 1,194 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2021 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

import os
import sys
import unittest

TEST_DIRECTORY = os.path.join(
    os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "test")

sys.path.insert(0, TEST_DIRECTORY)

if len(sys.argv) <= 1:
    TESTS = [
        file.rpartition(".")[0]
        for file in os.listdir(TEST_DIRECTORY)
        if file.startswith("test_") and file != "test_results.py"
    ]
else:
    TESTS = [
        name if name.startswith("test_") else "test_" + name
        for name in sys.argv[1:]
    ]


suite = unittest.TestSuite()

for test in TESTS:
    try:
        module = __import__(test)
    except Exception as exc:
        sys.stderr.write(f"Failed to import {test}: {exc}\n")
    else:
        tests = unittest.defaultTestLoader.loadTestsFromModule(module)
        suite.addTests(tests)

if __name__ == "__main__":
    result = unittest.TextTestRunner(verbosity=2).run(suite)
    if not result.wasSuccessful():
        sys.exit(1)