From bb19a6745c1a5278de578a8be12caad39ed5d03e Mon Sep 17 00:00:00 2001 From: Kaya <95276965+kytpbs@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:56:56 +0300 Subject: [PATCH] look at lenght of the videos to compare them this is the temporary workaround I found, I wish i could find a better option but this will do for now. Videos will be stored instead of lenghts so if I find a better way to compare, I can do that instead --- Tests/video_system/download_tester.py | 23 ++++++++++++++++------- tox.ini | 1 + 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Tests/video_system/download_tester.py b/Tests/video_system/download_tester.py index 3b4c1b6..5c62cfa 100644 --- a/Tests/video_system/download_tester.py +++ b/Tests/video_system/download_tester.py @@ -1,7 +1,18 @@ -import os -import requests +import static_ffmpeg +import subprocess from src.downloader import VIDEO_RETURN_TYPE, VideoFile +static_ffmpeg.add_paths(weak=True) # add the ffmpeg if not already added + +def _get_video_duration(video_path: str) -> float: + result = subprocess.run(["ffprobe", "-v", "error", "-show_entries", + "format=duration", "-of", + "default=noprint_wrappers=1:nokey=1", video_path], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + check=False) + return float(result.stdout) + class DownloadTester: def download_single_video_test(self, videos: VIDEO_RETURN_TYPE, should_be_path: str): @@ -18,8 +29,6 @@ def download_multiple_video_test(self, videos: VIDEO_RETURN_TYPE, 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: - # should_be.write(downloaded.read()) # uncomment to fix tests - assert downloaded.read() == should_be.read(), "Downloaded file does not match the expected file" + video_duration = _get_video_duration(video.path) + should_be_duration = _get_video_duration(should_be_path) + assert video_duration == should_be_duration, f"video_duration was '{video_duration}' should have been: '{should_be_duration}'" diff --git a/tox.ini b/tox.ini index 795ccba..24411b6 100644 --- a/tox.ini +++ b/tox.ini @@ -14,6 +14,7 @@ description = run the tests with pytest deps = pytest>=8 pytest-asyncio + static-ffmpeg -r requirements.txt passenv = * commands =