From 3ab33936563d9a3deb65a3804664e2ee29fa0d96 Mon Sep 17 00:00:00 2001 From: Joanna Bitton Date: Tue, 7 Nov 2023 16:58:38 -0800 Subject: [PATCH] Video Tests Optimization Summary: This diff particularly optimizes the check for video equivalency to use `filecmp` instead of md5 hashes, which are more brittle and also more inefficient. Reviewed By: hazirbas Differential Revision: D51090754 fbshipit-source-id: 8e6043c99946ce02bf8c66a561e61a264295e545 --- augly/tests/video_tests/base_unit_test.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/augly/tests/video_tests/base_unit_test.py b/augly/tests/video_tests/base_unit_test.py index a1624440..b883d8df 100644 --- a/augly/tests/video_tests/base_unit_test.py +++ b/augly/tests/video_tests/base_unit_test.py @@ -5,7 +5,7 @@ # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. -import hashlib +import filecmp import os import tempfile import unittest @@ -16,19 +16,7 @@ def are_equal_videos(a_path: str, b_path: str) -> bool: - hasher = hashlib.md5() - with open(a_path, "rb") as a_file: - buf = a_file.read() - hasher.update(buf) - a_md5_hash = hasher.hexdigest() - - hasher = hashlib.md5() - with open(b_path, "rb") as b_file: - buf = b_file.read() - hasher.update(buf) - b_md5_hash = hasher.hexdigest() - - return a_md5_hash == b_md5_hash + return filecmp.cmp(a_path, b_path, shallow=False) class BaseVideoUnitTest(unittest.TestCase):