From 5a54458735ac964776535da0b3a465939900c664 Mon Sep 17 00:00:00 2001 From: MayWei1113 <83398360+MayWei1113@users.noreply.github.com> Date: Wed, 24 Aug 2022 22:54:41 +0800 Subject: [PATCH 1/2] Fixes to the validation script --- first_validation.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/first_validation.py b/first_validation.py index cfbd543..95ce270 100644 --- a/first_validation.py +++ b/first_validation.py @@ -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,23 @@ def check_hashes(hash_fname): # Directory containing hash filenames file. data_dir = hash_pth.parent # Read in text for hash filename + hashes_text = hash_pth.read_text() # Split into lines. + hash_text = hashes_text.split("\n")[:-1] # For each line: # Split each line into expected_hash and filename # Calculate actual hash for given filename. # Check actual hash against expected hash # Return False if any of the hashes do not match. - return False + for lines in hash_text: + line = lines.split(' ') + expected_hash = line[0] + fname = data_dir / line[1] + calc_hash = hash_for_fname(fname) + if not calc_hash == expected_hash: + return False + + return True assert check_hashes(hashes_pth), 'Check hash list does not return True' From 1d7deac78e79b7ef501da1ec7fd06f4b78abc509 Mon Sep 17 00:00:00 2001 From: MayWei1113 <83398360+MayWei1113@users.noreply.github.com> Date: Mon, 29 Aug 2022 10:35:50 +0800 Subject: [PATCH 2/2] add first-validation.py --- first-validation | 1 + 1 file changed, 1 insertion(+) create mode 160000 first-validation diff --git a/first-validation b/first-validation new file mode 160000 index 0000000..ee92c10 --- /dev/null +++ b/first-validation @@ -0,0 +1 @@ +Subproject commit ee92c10e58f73c32987d04c492cb005bd6f71001