From 52a4f9d19af68b231b88a8e52bb8e26ce503e433 Mon Sep 17 00:00:00 2001 From: bashonly <88596187+bashonly@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:59:59 -0500 Subject: [PATCH] Add Python module test (#17) --- .github/workflows/ci.yml | 52 +++++++++++++++++++++++++++++++++++++++- .gitignore | 1 + hatch_build.py | 9 +++---- pyproject.toml | 3 +++ test/__init__.py | 0 test/test_modules.py | 18 ++++++++++++++ 6 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 test/__init__.py create mode 100644 test/test_modules.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f15b01..9bd9343 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,8 +31,40 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: + python_tests: + name: Python tests + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', pypy-3.11] + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + - name: Install Deno v2.x (latest) + uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python-version }} + - name: Build project + run: | + # `pip install -e` omits the force-included JS, so use `build` instead + python -m pip install -U build + python -m build + unzip -u dist/yt_dlp_ejs-*.whl "yt_dlp_ejs/*" + - name: Run Python tests + timeout-minutes: 5 + run: | + python -m unittest + # python -Werror -m unittest + prepare: - name: Prepare + name: Prepare JS runtime tests + needs: [python_tests] runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -95,6 +127,12 @@ jobs: - name: Test Deno build run: | python -m build + - name: Verify artifact contents + run: | + tar -tvzf dist/yt_dlp_ejs-*.tar.gz + unzip -l dist/yt_dlp_ejs-*.whl | tee .wheel_contents + grep -q 'yt_dlp_ejs/yt/solver/core\.min\.js' .wheel_contents + grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents - name: Install Deno requirements run: | deno install @@ -156,6 +194,12 @@ jobs: - name: Test Bun build run: | python -m build + - name: Verify artifact contents + run: | + tar -tvzf dist/yt_dlp_ejs-*.tar.gz + unzip -l dist/yt_dlp_ejs-*.whl | tee .wheel_contents + grep -q 'yt_dlp_ejs/yt/solver/core\.min\.js' .wheel_contents + grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents - name: Install Bun requirements run: | bun install @@ -215,6 +259,12 @@ jobs: - name: Test Node build run: | python -m build + - name: Verify artifact contents + run: | + tar -tvzf dist/yt_dlp_ejs-*.tar.gz + unzip -l dist/yt_dlp_ejs-*.whl | tee .wheel_contents + grep -q 'yt_dlp_ejs/yt/solver/core\.min\.js' .wheel_contents + grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents - name: Install Node requirements run: | npm install diff --git a/.gitignore b/.gitignore index 2270aa1..4a297d0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /deno.lock /package-lock.json /.idea +/.venv diff --git a/hatch_build.py b/hatch_build.py index 77d9f25..65a5285 100644 --- a/hatch_build.py +++ b/hatch_build.py @@ -2,7 +2,6 @@ import os import shutil import subprocess - from hatchling.builders.hooks.plugin.interface import BuildHookInterface @@ -31,8 +30,10 @@ class CustomBuildHook(BuildHookInterface): "One of 'deno', 'bun', or 'npm' could not be found. " "Please install one of them to proceed with the build.") - build_data["force_include"]["dist/yt.solver.core.min.js"] = "yt_dlp_ejs/yt/solver/core.min.js" - build_data["force_include"]["dist/yt.solver.lib.min.js"] = "yt_dlp_ejs/yt/solver/lib.min.js" + build_data["force_include"].update({ + "dist/yt.solver.core.min.js": "yt_dlp_ejs/yt/solver/core.min.js", + "dist/yt.solver.lib.min.js": "yt_dlp_ejs/yt/solver/lib.min.js", + }) def clean(self, versions): - shutil.rmtree('node_modules', ignore_errors=True) + shutil.rmtree("node_modules", ignore_errors=True) diff --git a/pyproject.toml b/pyproject.toml index f9669d0..3e8e720 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,6 +44,9 @@ exclude = [ "/src/yt/solver/test/players/*", ] +[tool.hatch.build.targets.wheel] +packages = ["yt_dlp_ejs"] + [tool.hatch.build.hooks.vcs] version-file = "yt_dlp_ejs/_version.py" diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_modules.py b/test/test_modules.py new file mode 100644 index 0000000..7549237 --- /dev/null +++ b/test/test_modules.py @@ -0,0 +1,18 @@ +import unittest +from pathlib import Path + +import yt_dlp_ejs.yt.solver + +BASE_PATH = Path(__file__).parent.parent +CORE_PATH = BASE_PATH / 'yt_dlp_ejs/yt/solver/core.min.js' +LIB_PATH = BASE_PATH / 'yt_dlp_ejs/yt/solver/lib.min.js' + + +class TestModules(unittest.TestCase): + def test_yt_solver(self): + self.assertEqual(yt_dlp_ejs.yt.solver.core(), CORE_PATH.read_text(encoding='utf-8')) + self.assertEqual(yt_dlp_ejs.yt.solver.lib(), LIB_PATH.read_text(encoding='utf-8')) + + +if __name__ == '__main__': + unittest.main()