Skip to content

Commit

Permalink
refactor tests to use a single test function
Browse files Browse the repository at this point in the history
this will be modified in a second
  • Loading branch information
kytpbs committed Aug 27, 2024
1 parent d8dc435 commit 876e960
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Tests/video_system/download_tester.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from src.downloader import VIDEO_RETURN_TYPE
import os
import requests
from src.downloader import VIDEO_RETURN_TYPE, VideoFile


class DownloadTester:
def download_single_video_test(self, videos: VIDEO_RETURN_TYPE, should_be_path: str):
assert len(videos) == 1
video = videos[0]

with open(video.path, "rb") as downloaded, open(
should_be_path, "rb"
) as should_be:
assert downloaded.read() == should_be.read(), "Downloaded file does not match the expected file"
self._test_download(video, should_be_path)

def download_multiple_video_test(self, videos: VIDEO_RETURN_TYPE, should_be_paths: list[str]):
assert len(videos) == len(should_be_paths), f"len(videos)={len(videos)} len(should_be_paths)={len(should_be_paths)}"

for video, should_be_path in zip(videos, should_be_paths):
with open(video.path, "rb") as downloaded, open(
should_be_path, "rb"
self._test_download(video, should_be_path)


def _test_download(self, video: VideoFile, should_be_path: str):
with open(video.path, "rb") as downloaded, open(
should_be_path, "rb" # change to "wb" to run fix tests
) as should_be:
assert downloaded.read() == should_be.read(), "Downloaded file does not match the expected file"
# should_be.write(downloaded.read()) # uncomment to fix tests
assert downloaded.read() == should_be.read(), "Downloaded file does not match the expected file"

0 comments on commit 876e960

Please sign in to comment.