Skip to main content

scripts: switch to standard test runner; ty for type checking; add coverage

ID
15955a8
date
2026-04-20 05:24:12+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
3f30c9d
message
scripts: switch to standard test runner; ty for type checking; add coverage
changed files
7 files, 38 additions, 22 deletions

Changed files

.github/workflows/test.yml (952) → .github/workflows/test.yml (947)

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index f7216c0..8cd99fd 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -37,7 +37,7 @@ jobs:
         ruff format --check .
 
     - name: Check types
-      run: mypy *.py --strict
+      run: ty check *.py
 
     # I don't run tests in GitHub Actions because YouTube blocks yt-dlp
     # without authentication, and I don't want to sort out passing cookies

dev_requirements.in (80) → dev_requirements.in (65)

diff --git a/dev_requirements.in b/dev_requirements.in
index 30b9bfa..472d96f 100644
--- a/dev_requirements.in
+++ b/dev_requirements.in
@@ -1,8 +1,7 @@
 -r requirements.txt
 
-mypy
 pymediainfo
 pytest-cov
 pytest-xdist
 ruff
-types-yt-dlp
+ty

dev_requirements.txt (1983) → dev_requirements.txt (1749)

diff --git a/dev_requirements.txt b/dev_requirements.txt
index 66e7106..7b25bca 100644
--- a/dev_requirements.txt
+++ b/dev_requirements.txt
@@ -31,18 +31,10 @@ idna==3.11
     #   requests
 iniconfig==2.3.0
     # via pytest
-librt==0.8.1
-    # via mypy
 mutagen==1.47.0
     # via -r requirements.txt
-mypy==1.20.0
-    # via -r dev_requirements.in
-mypy-extensions==1.1.0
-    # via mypy
 packaging==26.0
     # via pytest
-pathspec==1.0.4
-    # via mypy
 pillow==12.2.0
     # via -r requirements.txt
 pluggy==1.6.0
@@ -59,7 +51,7 @@ pygments==2.20.0
     # via pytest
 pymediainfo==7.0.1
     # via -r dev_requirements.in
-pytest==9.0.2
+pytest==9.0.3
     # via
     #   pytest-cov
     #   pytest-xdist
@@ -71,20 +63,16 @@ requests==2.33.1
     # via
     #   -r requirements.txt
     #   gallery-dl
-ruff==0.15.9
+ruff==0.15.10
     # via -r dev_requirements.in
-types-yt-dlp==2026.3.17.20260402
+ty==0.0.29
     # via -r dev_requirements.in
-typing-extensions==4.15.0
-    # via mypy
 urllib3==2.6.3
     # via
     #   -r requirements.txt
     #   requests
 websockets==16.0
-    # via
-    #   -r requirements.txt
-    #   types-yt-dlp
+    # via -r requirements.txt
 yt-dlp==2026.3.17
     # via -r requirements.txt
 yt-dlp-ejs==0.8.0

pyproject.toml (0) → pyproject.toml (225)

diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..bb03129
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,12 @@
+[project]
+name = "yt-dlp_alexwlchan"
+version = "1.0"
+
+[tool.coverage.run]
+branch = true
+source = ["yt-dlp_alexwlchan", "test_yt-dlp_alexwlchan"]
+
+[tool.coverage.report]
+show_missing = true
+skip_covered = true
+fail_under = 68

scripts/run_yt_dlp_alexwlchan_tests.sh (0) → scripts/run_yt_dlp_alexwlchan_tests.sh (333)

diff --git a/scripts/run_yt_dlp_alexwlchan_tests.sh b/scripts/run_yt_dlp_alexwlchan_tests.sh
new file mode 100755
index 0000000..c9a84f6
--- /dev/null
+++ b/scripts/run_yt_dlp_alexwlchan_tests.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+
+# Print a command in blue, then run the command
+run_command() {
+    echo ""
+    echo -e "\033[34m-> $@\033[0m"
+    bash -c "$@"
+}
+
+run_command 'ruff format'
+run_command 'ruff check *.py'
+run_command 'ty check *.py'
+run_command 'python3 -m pytest --cov=. test_yt-dlp_alexwlchan.py'

test_yt-dlp_alexwlchan.py (4224) → test_yt-dlp_alexwlchan.py (4234)

diff --git a/test_yt-dlp_alexwlchan.py b/test_yt-dlp_alexwlchan.py
index 8818dc8..46ced98 100644
--- a/test_yt-dlp_alexwlchan.py
+++ b/test_yt-dlp_alexwlchan.py
@@ -32,7 +32,7 @@ def test_youtube_video() -> None:
     assert video_info["id"] == "TUQaGhPdlxs"
     assert video_info["date_uploaded"] == "2022-03-25T01:10:38Z"
 
-    assert video_info["video_path"].endswith(" [TUQaGhPdlxs].mp4")
+    assert video_info["video_path"].name.endswith(" [TUQaGhPdlxs].mp4")
 
 
 def test_youtube_path_is_cleaned_up() -> None:
@@ -100,7 +100,7 @@ def test_instagram_video() -> None:
     assert video_info["id"] == "DMWY8KkOS0n"
     assert video_info["date_uploaded"] == "2025-07-21T00:34:41Z"
 
-    assert video_info["video_path"].endswith(" [DMWY8KkOS0n].mp4")
+    assert video_info["video_path"].name.endswith(" [DMWY8KkOS0n].mp4")
 
 
 @pytest.mark.parametrize(

yt-dlp_alexwlchan.py (9017) → yt-dlp_alexwlchan.py (9064)

diff --git a/yt-dlp_alexwlchan.py b/yt-dlp_alexwlchan.py
index 27d718f..d352239 100755
--- a/yt-dlp_alexwlchan.py
+++ b/yt-dlp_alexwlchan.py
@@ -214,7 +214,8 @@ def download_video(url: str) -> VideoInfo:
                 ydl.extract_info(url)
             except DownloadError as e:
                 if (
-                    isinstance(e.exc_info[1], YouTubeDLHTTPError)
+                    e.exc_info is not None
+                    and isinstance(e.exc_info[1], YouTubeDLHTTPError)
                     and e.exc_info[1].status == 429
                 ):
                     pass