Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed first validatio #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions first_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

from hashlib import sha1


babakslt marked this conversation as resolved.
Show resolved Hide resolved
#from pandas import read_csv

data_pth = Path() / 'data'
example_pth = data_pth / '24719.f3_beh_CHYM.csv'

Expand All @@ -31,7 +34,9 @@ def hash_for_fname(fname):
# Convert a string filename to a Path object.
fpath = Path(fname)
# Your code here.
return 'not-really-the-hash'
contents = fpath.read_bytes()
hash_value = sha1(contents).hexdigest()
return hash_value
babakslt marked this conversation as resolved.
Show resolved Hide resolved


# Fill in the function above to make the test below pass.
Expand All @@ -54,7 +59,19 @@ def check_hashes(hash_fname):
# Calculate actual hash for given filename.
# Check actual hash against expected hash
# Return False if any of the hashes do not match.
return False
def get_file_hash(path_fname):
babakslt marked this conversation as resolved.
Show resolved Hide resolved
contents = path_fname.read_bytes()
hash_value = sha1(contents).hexdigest()
return hash_value

hash_text = hash_fname.read_text().splitlines()
for line in hash_text:
hash,_,file = line.split(" ")
babakslt marked this conversation as resolved.
Show resolved Hide resolved
_hash = get_file_hash(data_dir/Path(file))
babakslt marked this conversation as resolved.
Show resolved Hide resolved
if hash == _hash:
continue
else: return False
babakslt marked this conversation as resolved.
Show resolved Hide resolved
return True


assert check_hashes(hashes_pth), 'Check hash list does not return True'