-
Notifications
You must be signed in to change notification settings - Fork 42
Fixes to the validation script #3
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -31,7 +31,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 | ||||||
|
||||||
|
||||||
# Fill in the function above to make the test below pass. | ||||||
|
@@ -48,13 +50,24 @@ def check_hashes(hash_fname): | |||||
# Directory containing hash filenames file. | ||||||
data_dir = hash_pth.parent | ||||||
# Read in text for hash filename | ||||||
hash_file_contents = hash_pth.read_text() | ||||||
|
||||||
# Split into lines. | ||||||
lst_of_splitted_lines = hash_file_contents.splitlines() | ||||||
# For each line: | ||||||
for line in lst_of_splitted_lines: | ||||||
# Split each line into expected_hash and filename | ||||||
[exp_hash, gap, filename] = line.split(sep=' ') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes - but you don't even need the brackets around the list on the left hand side. And you can use the default separator (of any number of spaces) to make it a bit simpler, as in:
Suggested change
|
||||||
|
||||||
# Calculate actual hash for given filename. | ||||||
act_hash = hash_for_fname(data_dir / filename) | ||||||
|
||||||
# Check actual hash against expected hash | ||||||
# Return False if any of the hashes do not match. | ||||||
return False | ||||||
result = (act_hash == exp_hash) | ||||||
Comment on lines
-57
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that you end up returning the result of the last test here, so if any of the previous tests failed, the function still returns True. I think you want something like:
to combine the results of the tests. |
||||||
|
||||||
# Return False if any of the hashes do not match. | ||||||
return result | ||||||
|
||||||
#check_hashes(hashes_pth) | ||||||
assert check_hashes(hashes_pth), 'Check hash list does not return True' | ||||||
print("Finished!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or: