-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor tests to use a single test function
this will be modified in a second
- Loading branch information
Showing
1 changed file
with
12 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |