Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for Windows #320

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
51 changes: 33 additions & 18 deletions tests/test___main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
import shlex
import subprocess
import sys
import tempfile
Expand All @@ -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


Expand Down Expand Up @@ -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 = (
Expand All @@ -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():
Expand All @@ -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):
Expand Down
10 changes: 6 additions & 4 deletions tests/test_download.py
Original file line number Diff line number Diff line change
@@ -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)