diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77105a19..fe4cfeb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,3 +37,24 @@ jobs: make build pip install dist/gdown-*.tar.gz pip install dist/gdown-*.whl + + test-windows: + + runs-on: windows-latest + strategy: + matrix: + python-version: ["3.8", "3.12"] + + steps: + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - uses: actions/checkout@v3 + + - name: Install main + run: | + pip install .[test] + + - name: Test + run: | + pytest -n auto -v tests diff --git a/tests/test___main__.py b/tests/test___main__.py index 10488aff..be2b758f 100644 --- a/tests/test___main__.py +++ b/tests/test___main__.py @@ -1,5 +1,6 @@ +from __future__ import annotations + import os -import shlex import subprocess import sys import tempfile @@ -9,19 +10,19 @@ here = os.path.dirname(os.path.abspath(__file__)) -def _test_cli_with_md5(url_or_id, md5, options=None): - with tempfile.NamedTemporaryFile() as f: - cmd = f"gdown --no-cookies {url_or_id} -O {f.name}" - if options is not None: - cmd = f"{cmd} {options}" - subprocess.call(shlex.split(cmd)) - _assert_filehash(path=f.name, hash=f"md5:{md5}") +def _test_cli_with_md5(url_or_id: str, md5: str, options: list[str] = []): + with tempfile.TemporaryDirectory() as d: + file = os.path.join(d, "temp") + cmd = ["gdown", "--no-cookies", url_or_id, "-O", file, *options] + subprocess.call(cmd) + _assert_filehash(path=file, hash=f"md5:{md5}") def _test_cli_with_content(url_or_id, content): - with tempfile.NamedTemporaryFile() as f: - subprocess.call(shlex.split(f"gdown --no-cookies {url_or_id} -O {f.name}")) - with open(f.name) as f: + with tempfile.TemporaryDirectory() as d: + file = os.path.join(d, "temp") + subprocess.call(["gdown", "--no-cookies", url_or_id, "-O", file]) + with open(file) as f: assert f.read() == content @@ -77,8 +78,7 @@ def test_download_folder_from_gdrive(): for folder_id, md5 in folder_id_and_md5s: with tempfile.TemporaryDirectory() as d: - cmd = f"gdown --no-cookies {folder_id} -O {d} --folder" - subprocess.call(shlex.split(cmd)) + subprocess.call(["gdown", "--no-cookies", folder_id, "-O", d, "--folder"]) cmd = "find . -type f -exec md5sum {} \\; | awk '{print $1}' | sort | md5sum | awk '{print $1}'" # noqa: E501 md5_actual = ( @@ -96,8 +96,15 @@ def test_download_folder_from_gdrive(): def test_download_a_folder_with_remining_ok_false(): with tempfile.TemporaryDirectory() as d: - cmd = f"gdown --no-cookies https://drive.google.com/drive/folders/1gd3xLkmjT8IckN6WtMbyFZvLR4exRIkn -O {d} --folder" # noqa: E501 - assert subprocess.call(shlex.split(cmd)) == 1 + cmd = [ + "gdown", + "--no-cookies", + "https://drive.google.com/drive/folders/1gd3xLkmjT8IckN6WtMbyFZvLR4exRIkn", + "-O", + d, + "--folder", + ] + assert subprocess.call(cmd) == 1 # def test_download_docs_from_gdrive(): @@ -115,15 +122,23 @@ def test_download_a_folder_with_remining_ok_false(): def test_download_slides_from_gdrive(): file_id = "13AhW1Z1GYGaiTpJ0Pr2TTXoQivb6jx-a" md5 = "96704c6c40e308a68d3842e83a0136b9" - _test_cli_with_md5(url_or_id=file_id, md5=md5, options="--format pdf") + _test_cli_with_md5(url_or_id=file_id, md5=md5, options=["--format", "pdf"]) def test_download_a_folder_with_file_content_more_than_the_limit(): url = "https://drive.google.com/drive/folders/1gd3xLkmjT8IckN6WtMbyFZvLR4exRIkn" with tempfile.TemporaryDirectory() as d: - cmd = f"gdown --no-cookies {url} -O {d} --folder --remaining-ok" - subprocess.check_call(shlex.split(cmd)) + cmd = [ + "gdown", + "--no-cookies", + url, + "-O", + d, + "--folder", + "--remaining-ok", + ] + subprocess.check_call(cmd) filenames = sorted(os.listdir(d)) for i in range(50): diff --git a/tests/test_download.py b/tests/test_download.py index 34d08e86..5e685e2e 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -1,12 +1,14 @@ import os +import tempfile from gdown.download import download def test_download(): url = "https://raw.githubusercontent.com/wkentaro/gdown/3.1.0/gdown/__init__.py" # NOQA - output = "/tmp/gdown_r" - # Usage before https://github.com/wkentaro/gdown/pull/32 - assert download(url, output, quiet=False) == output - os.remove(output) + with tempfile.TemporaryDirectory() as d: + output = os.path.join(d, "gdown_r") + # Usage before https://github.com/wkentaro/gdown/pull/32 + assert download(url, output, quiet=False) == output + os.remove(output)