1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

run tests without using 'nose'

run_tests.sh -> run_tests.py
This commit is contained in:
Mike Fährmann 2021-10-13 03:10:55 +02:00
parent 918fc9974d
commit f2d6b3e6b4
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
6 changed files with 61 additions and 34 deletions

View File

@ -36,7 +36,6 @@ jobs:
- name: Run tests - name: Run tests
run: | run: |
pip install nose
make test make test
- name: Test autogeneration of man pages, bash/zsh completion, etc - name: Test autogeneration of man pages, bash/zsh completion, etc

View File

@ -19,7 +19,7 @@ release: man completion supportedsites
scripts/release.sh scripts/release.sh
test: test:
scripts/run_tests.sh scripts/run_tests.py
executable: executable:
scripts/pyinstaller.py scripts/pyinstaller.py

View File

@ -211,6 +211,7 @@ def _path():
return os.path.join(cachedir, "cache.sqlite3") return os.path.join(cachedir, "cache.sqlite3")
def _init():
try: try:
dbfile = _path() dbfile = _path()
@ -220,4 +221,8 @@ try:
DatabaseCacheDecorator.db = sqlite3.connect( DatabaseCacheDecorator.db = sqlite3.connect(
dbfile, timeout=60, check_same_thread=False) dbfile, timeout=60, check_same_thread=False)
except (OSError, TypeError, sqlite3.OperationalError): except (OSError, TypeError, sqlite3.OperationalError):
cache = memcache # noqa: F811 global cache
cache = memcache
_init()

46
scripts/run_tests.py Executable file
View File

@ -0,0 +1,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 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)

View File

@ -1,24 +0,0 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
TESTS_CORE=(cache config cookies downloader extractor formatter job oauth output postprocessor text util)
TESTS_RESULTS=(results)
# select tests
case "${1:-${GALLERYDL_TESTS:-core}}" in
core) TESTS=( ${TESTS_CORE[@]} );;
results) TESTS=( ${TESTS_RESULTS[@]} );;
*) TESTS=( );;
esac
# transform each array element to test_###.py
TESTS=( ${TESTS[@]/#/test_} )
TESTS=( ${TESTS[@]/%/.py} )
# run 'nosetests' with selected tests
# (or all tests if ${TESTS} is empty)
nosetests --verbose -w "${DIR}/../test" ${TESTS[@]}

View File

@ -20,6 +20,7 @@ from gallery_dl import config, util # noqa E402
dbpath = tempfile.mkstemp()[1] dbpath = tempfile.mkstemp()[1]
config.set(("cache",), "file", dbpath) config.set(("cache",), "file", dbpath)
from gallery_dl import cache # noqa E402 from gallery_dl import cache # noqa E402
cache._init()
# def tearDownModule(): # def tearDownModule():