Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kmark/e1d479cb36581f8af1bb3ffae0c7f83d to your computer and use it in GitHub Desktop.
Save kmark/e1d479cb36581f8af1bb3ffae0c7f83d to your computer and use it in GitHub Desktop.
From 6a13d2435af223a6164734b3e9255d686578e5c2 Mon Sep 17 00:00:00 2001
From: Kevin Mark <[email protected]>
Date: Sat, 8 Jul 2017 19:45:21 -0400
Subject: [PATCH] Allow entire file to match or first 10241 bytes
---
test/test_download.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/test/test_download.py b/test/test_download.py
index 209f5f6d6..f918af799 100644
--- a/test/test_download.py
+++ b/test/test_download.py
@@ -56,9 +56,9 @@ class YoutubeDL(youtube_dl.YoutubeDL):
return super(YoutubeDL, self).process_info(info_dict)
-def _file_md5(fn):
+def _file_md5(fn, size=None):
with open(fn, 'rb') as f:
- return hashlib.md5(f.read()).hexdigest()
+ return hashlib.md5(f.read(size)).hexdigest()
defs = gettestcases()
@@ -224,8 +224,8 @@ def generator(test_case, tname):
(tc_filename, format_bytes(expected_minsize),
format_bytes(got_fsize)))
if 'md5' in tc:
- md5_for_file = _file_md5(tc_filename)
- self.assertEqual(tc['md5'], md5_for_file)
+ if tc['md5'] != _file_md5(tc_filename):
+ self.assertEqual(tc['md5'], _file_md5(tc_filename, 10241))
# Finally, check test cases' data again but this time against
# extracted data from info JSON file written during processing
info_json_fn = os.path.splitext(tc_filename)[0] + '.info.json'
--
2.13.2
From 6a094f02693a5854c280948e445f55267ce0a92f Mon Sep 17 00:00:00 2001
From: Kevin Mark <[email protected]>
Date: Sat, 8 Jul 2017 19:33:18 -0400
Subject: [PATCH] Only MD5 the first 10241 bytes
---
test/test_download.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/test_download.py b/test/test_download.py
index 209f5f6d6..4f720eff3 100644
--- a/test/test_download.py
+++ b/test/test_download.py
@@ -58,7 +58,7 @@ class YoutubeDL(youtube_dl.YoutubeDL):
def _file_md5(fn):
with open(fn, 'rb') as f:
- return hashlib.md5(f.read()).hexdigest()
+ return hashlib.md5(f.read(10241)).hexdigest()
defs = gettestcases()
--
2.13.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment