[libgxps] regtest: Read test results in chunks to get the md5 digest
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgxps] regtest: Read test results in chunks to get the md5 digest
- Date: Tue, 23 Jun 2015 17:25:06 +0000 (UTC)
commit 151e161f6823069f1efc027e2acf69d0062d2ece
Author: Carlos Garcia Campos <carlosgc gnome org>
Date: Tue Jun 23 18:28:32 2015 +0200
regtest: Read test results in chunks to get the md5 digest
Instead of creating the md5 object with the entire file, we feed it with
chunks of data using the update method. This improves a lot the memory
consumption and performance as well.
regtest/Test.py | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/regtest/Test.py b/regtest/Test.py
index 3e22e74..6f5374e 100644
--- a/regtest/Test.py
+++ b/regtest/Test.py
@@ -16,7 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from hashlib import md5
+import hashlib
import os
import subprocess
import shutil
@@ -30,6 +30,14 @@ class Test:
self._xpstopng = os.path.join(Config().tools_dir, 'xpstopng')
self.printer = get_printer()
+ def __md5sum(self, ref_path):
+ md5 = hashlib.md5()
+ with open(ref_path,'rb') as f:
+ for chunk in iter(lambda: f.read(128 * md5.block_size), b''):
+ md5.update(chunk)
+
+ return md5.hexdigest()
+
def __should_have_checksum(self, entry):
return entry not in ('md5', 'crashed', 'failed', 'stderr');
@@ -42,9 +50,7 @@ class Test:
continue
ref_path = os.path.join(refs_path, entry)
- f = open(ref_path, 'rb')
- md5_file.write("%s %s\n" % (md5(f.read()).hexdigest(), ref_path))
- f.close()
+ md5_file.write("%s %s\n" % (self.__md5sum(ref_path), ref_path))
if delete_refs:
os.remove(ref_path)
@@ -70,10 +76,8 @@ class Test:
continue
result_path = os.path.join(out_path, basename)
- f = open(result_path, 'rb')
- result_md5sum = md5(f.read()).hexdigest()
+ result_md5sum = self.__md5sum(result_path);
matched = md5sum == result_md5sum
- f.close()
if update_refs:
result_md5.append("%s %s\n" % (result_md5sum, ref_path))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]