Skip to content

Commit

Permalink
Merge pull request #482 from henrykironde/getmd5_sorted_files
Browse files Browse the repository at this point in the history
add sorted to files in getmd5
  • Loading branch information
ethanwhite committed Apr 27, 2016
2 parents aa1701c + a7b7bee commit 861571c
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions test/test_regression_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import nose
from unittest import TestCase
from hashlib import md5

import nose


# First md5 is for csv, second md5 is for sqlite
known_md5s = {

Expand Down Expand Up @@ -40,24 +42,21 @@ def teardown_module():
os.chdir("..")


def getmd5(filename):
"""Get MD5 value for a file"""
lines = open(filename, 'rU')
sum = md5()
for line in lines:
sum.update(line)
return sum.hexdigest()


def getmd5dir(directoryname):
"""Get MD5 value for files in a directory"""
def getmd5(file_path):
"""Get MD5 of a file, files in a directory or for specific files"""
files = []
if os.path.isfile(file_path):
files.append(file_path)
elif os.path.isdir(file_path):
for root, directories, filenames in os.walk(file_path):
for filename in sorted(filenames):
files.append(os.path.normpath(os.path.join(root, filename)))
sum = md5()
for root, directories, filenames in os.walk(directoryname):
for filename in filenames:
lines = open(os.path.normpath(os.path.join(root, filename)), 'rU')
sum = md5()
for line in lines:
sum.update(line)
for file_path in files:
lines = open(file_path, 'rU')
sum = md5()
for line in lines:
sum.update(line)
return sum.hexdigest()


Expand Down Expand Up @@ -134,7 +133,7 @@ class DownloadRegression(TestCase):
def check_download_regression(self, dataset, known_md5):
"""Check for regression for a particular dataset downloaded only"""
os.system("retriever download {0} -p raw_data/{0}".format(dataset))
current_md5 = getmd5dir("raw_data/%s" % (dataset))
current_md5 = getmd5("raw_data/%s" % (dataset))
assert current_md5 == known_md5


Expand Down

0 comments on commit 861571c

Please sign in to comment.