Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[devscripts]
run_tests
: Create Python script (#8720)
Authored by: Grub4K
- Loading branch information
Showing
7 changed files
with
95 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,4 @@ | ||
@setlocal | ||
@echo off | ||
cd /d %~dp0.. | ||
|
||
if ["%~1"]==[""] ( | ||
set "test_set="test"" | ||
) else if ["%~1"]==["core"] ( | ||
set "test_set="-m not download"" | ||
) else if ["%~1"]==["download"] ( | ||
set "test_set="-m "download"" | ||
) else ( | ||
echo.Invalid test type "%~1". Use "core" ^| "download" | ||
exit /b 1 | ||
) | ||
|
||
set PYTHONWARNINGS=error | ||
pytest %test_set% | ||
>&2 echo run_tests.bat is deprecated. Please use `devscripts/run_tests.py` instead | ||
python %~dp0run_tests.py %~1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import functools | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
|
||
fix_test_name = functools.partial(re.compile(r'IE(_all|_\d+)?$').sub, r'\1') | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser(description='Run selected yt-dlp tests') | ||
parser.add_argument( | ||
'test', help='a extractor tests, or one of "core" or "download"', nargs='*') | ||
parser.add_argument( | ||
'-k', help='run a test matching EXPRESSION. Same as "pytest -k"', metavar='EXPRESSION') | ||
return parser.parse_args() | ||
|
||
|
||
def run_tests(*tests, pattern=None): | ||
run_core = 'core' in tests or (not pattern and not tests) | ||
run_download = 'download' in tests | ||
tests = list(map(fix_test_name, tests)) | ||
|
||
arguments = ['pytest', '-Werror', '--tb', 'short'] | ||
if run_core: | ||
arguments.extend(['-m', 'not download']) | ||
elif run_download: | ||
arguments.extend(['-m', 'download']) | ||
elif pattern: | ||
arguments.extend(['-k', pattern]) | ||
else: | ||
arguments.extend( | ||
f'test/test_download.py::TestDownload::test_{test}' for test in tests) | ||
|
||
print(f'Running {arguments}') | ||
try: | ||
subprocess.run(arguments) | ||
return | ||
except FileNotFoundError: | ||
pass | ||
|
||
arguments = [sys.executable, '-Werror', '-m', 'unittest'] | ||
if run_core: | ||
print('"pytest" needs to be installed to run core tests', file=sys.stderr) | ||
return | ||
elif run_download: | ||
arguments.append('test.test_download') | ||
elif pattern: | ||
arguments.extend(['-k', pattern]) | ||
else: | ||
arguments.extend( | ||
f'test.test_download.TestDownload.test_{test}' for test in tests) | ||
|
||
print(f'Running {arguments}') | ||
subprocess.run(arguments) | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
args = parse_args() | ||
|
||
os.chdir(Path(__file__).parent.parent) | ||
run_tests(*args.test, pattern=args.k) | ||
except KeyboardInterrupt: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,4 @@ | ||
#!/usr/bin/env sh | ||
|
||
if [ -z "$1" ]; then | ||
test_set='test' | ||
elif [ "$1" = 'core' ]; then | ||
test_set="-m not download" | ||
elif [ "$1" = 'download' ]; then | ||
test_set="-m download" | ||
else | ||
echo 'Invalid test type "'"$1"'". Use "core" | "download"' | ||
exit 1 | ||
fi | ||
|
||
python3 -bb -Werror -m pytest "$test_set" | ||
>&2 echo 'run_tests.sh is deprecated. Please use `devscripts/run_tests.py` instead' | ||
python3 devscripts/run_tests.py "$1" |