Skip to content
Merged
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repos:
- id: trailing-whitespace
- id: check-yaml
- id: check-added-large-files
exclude: '^tests/cassettes'
- id: debug-statements
- id: end-of-file-fixer
exclude: '^.+?\.json$'
Expand Down
5 changes: 0 additions & 5 deletions requirements_test.txt

This file was deleted.

10 changes: 10 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
"filetype>=1.1.0",
"urllib3==2.3.0",
],
extras_require={
"test": [
"requests-cache==1.2.1",
"pytest==8.3.4",
"pycountry==24.6.1",
"pytest-env==1.1.5",
"vcrpy==7.0.0; python_version >='3.10'",
"mock==5.1.0",
],
},
python_requires=">=3.9, <3.13",
license="MIT license",
zip_safe=False,
Expand Down
19,648 changes: 19,648 additions & 0 deletions tests/cassettes/test_youtubevideo_process_file.yaml

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
from le_utils.constants import licenses
from le_utils.constants import roles

try:
from vcr.stubs import VCRHTTPResponse
except ImportError:
VCRHTTPResponse = None

from ricecooker.__init__ import __version__
from ricecooker.classes.files import _ExerciseBase64ImageFile
from ricecooker.classes.files import _ExerciseGraphieFile
Expand Down Expand Up @@ -77,6 +82,18 @@ def global_fixture():
pass


# Monkey patch VCRHTTPResponse to handle kwargs that are not compatible with BufferIO
# This can be removed when this issue has been resolved: https://github.com/kevin1024/vcrpy/issues/902
def _new_read(self, *args, **kwargs):
# urllib3 allows the kwarg 'decode_content' but BytesIO does not support it
kwargs.pop("decode_content", None)
return self._content.read(*args, **kwargs)


if VCRHTTPResponse is not None:
VCRHTTPResponse.read = _new_read


# CHANNEL FIXTURES
################################################################################

Expand Down Expand Up @@ -428,9 +445,9 @@ def invalid_video_file():
@pytest.fixture
def youtube_video_dict():
"""
A short 17 sec video that won't slow down tests too much.
A short 1 sec video that won't store too much data locally.
"""
return {"youtube_id": "C0DPdy98e4c"}
return {"youtube_id": "tPEE9ZwTmy0"}


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from PIL import Image
from requests import HTTPError
from test_pdfutils import _save_file_url_to_path
from vcr_config import my_vcr

from ricecooker import config
from ricecooker.classes.files import _ExerciseGraphieFile
Expand Down Expand Up @@ -744,7 +745,7 @@ def test_create_many_predictable_zip_files(ndirs=8193):
""" *********** YOUTUBEVIDEOFILE TESTS *********** """


@pytest.mark.skipif(True, reason="Requires connecting to youtube.")
@my_vcr.use_cassette
def test_youtubevideo_process_file(youtube_video_dict):
video_file = YouTubeVideoFile(youtube_id=youtube_video_dict["youtube_id"])
filename = video_file.process_file()
Expand Down
17 changes: 17 additions & 0 deletions tests/vcr_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

try:
import vcr

my_vcr = vcr.VCR(
cassette_library_dir="tests/cassettes",
record_mode="new_episodes",
path_transformer=vcr.VCR.ensure_suffix(".yaml"),
)
except ImportError:

class VCR:
def use_cassette(self, *args, **kwargs):
return pytest.mark.skip("vcrpy is not available on this Python version")

my_vcr = VCR()
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ basepython =
py3.10: python3.10
py3.11: python3.11
py3.12: python3.12
deps =
-r{toxinidir}/requirements_test.txt
extras = test
setenv =
PYTHONPATH = {toxinidir}
commands =
Expand Down