From d5b99a501ccc32ec441fdd5ab3f98182ea4881c2 Mon Sep 17 00:00:00 2001 From: jbannon Date: Thu, 28 Apr 2022 04:43:47 +0000 Subject: [PATCH] e2e tests wip --- tests/e2e/__init__.py | 0 tests/e2e/expected_download.py | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/e2e/__init__.py create mode 100644 tests/e2e/expected_download.py diff --git a/tests/e2e/__init__.py b/tests/e2e/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/e2e/expected_download.py b/tests/e2e/expected_download.py new file mode 100644 index 00000000..5099493b --- /dev/null +++ b/tests/e2e/expected_download.py @@ -0,0 +1,26 @@ +import hashlib +import os.path +from pathlib import Path +from typing import Dict + + +class ExpectedDownload: + """ + To test ytdl-sub downloads work, we compare each downloaded file's md5 hash to an + expected md5 hash defined in this class + """ + + def __init__(self, expected_md5_file_hashes: Dict[Path, str]): + self.expected_md5_file_hashes = expected_md5_file_hashes + + def assert_files_exist(self): + """ + Assert each expected file exists and that its respective md5 hash matches. + """ + for path, expected_md5_hash in self.expected_md5_file_hashes.items(): + assert os.path.isfile(path), f"Expected {str(path)} to be a file but it is not" + + with open(path, "rb") as file: + md5_hash = hashlib.md5(file.read()).hexdigest() + + assert md5_hash == expected_md5_hash, f"MD5 hash for {str(path)} does not match"