From 1507bc65ae118b321ea745cdbe877236d7da3ded Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Mon, 29 Aug 2022 02:17:55 -0400 Subject: d/t/run-tests.py: Re-sync from upstream, upgrade from nose to unittests. Closes: #1018363 --- debian/tests/control | 2 +- debian/tests/run-tests.py | 54 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/debian/tests/control b/debian/tests/control index 6724131..531cfa0 100644 --- a/debian/tests/control +++ b/debian/tests/control @@ -1,3 +1,3 @@ Tests: run-tests.py -Depends: @, @builddeps@, python3-nose +Depends: @, @builddeps@ Restrictions: allow-stderr diff --git a/debian/tests/run-tests.py b/debian/tests/run-tests.py index 11feaed..c73db63 100644 --- a/debian/tests/run-tests.py +++ b/debian/tests/run-tests.py @@ -1,23 +1,45 @@ -#!/bin/bash -# This is a slightly modified version of upstream's scripts/run_tests.py +#!/usr/bin/python3 +# -*- coding: utf-8 -*- -TESTS_CORE=(cache config cookies downloader extractor oauth postprocessor text util) -TESTS_RESULTS=(results) +# 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 -# select tests -case "${1:-${GALLERYDL_TESTS:-core}}" in - core) TESTS=( ${TESTS_CORE[@]} );; - results) TESTS=( ${TESTS_RESULTS[@]} );; - *) TESTS=( );; -esac +TEST_DIRECTORY = "test" +sys.path.insert(0, TEST_DIRECTORY) -# transform each array element to test_###.py -TESTS=( ${TESTS[@]/#/test_} ) -TESTS=( ${TESTS[@]/%/.py} ) +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:] + ] -# run 'nosetests3' with selected tests -# (or all tests if ${TESTS} is empty) -nosetests3 --verbose -w "test" ${TESTS[@]} +suite = unittest.TestSuite() + +for test in TESTS: + try: + module = __import__(test) + except ImportError: + print("unable to import", test) + else: + tests = unittest.defaultTestLoader.loadTestsFromModule(module) + suite.addTests(tests) + +if __name__ == "__main__": + result = unittest.TextTestRunner(verbosity=2).run(suite) + if result.errors or result.failures: + sys.exit(1) -- cgit v1.2.3