Skip to content

Commit 1afbe2b

Browse files
committed
Update validate data for new data organization
1 parent 0ae366e commit 1afbe2b

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

scripts/validate_data.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
python3 scripts/validata_data.py data
66
"""
77

8-
import os.path as op
8+
import op as op
99
import sys
1010
import hashlib
1111

12-
1312
def file_hash(filename):
1413
""" Get byte contents of file `filename`, return SHA1 hash
1514
@@ -25,11 +24,13 @@ def file_hash(filename):
2524
"""
2625
# Open the file, read contents as bytes.
2726
# Calculate, return SHA1 has on the bytes from the file.
28-
raise NotImplementedError('This is just a template -- you are expected to code this.')
27+
# This is a placeholder, replace it to write your solution.
28+
raise NotImplementedError(
29+
'This is just a template -- you are expected to code this.')
2930

3031

3132
def validate_data(data_directory):
32-
""" Read ``data_hashes.txt`` file in ``data_directory``, check hashes
33+
""" Read ``data_hashes.txt`` file in `data_directory`, check hashes
3334
3435
Parameters
3536
----------
@@ -51,6 +52,7 @@ def validate_data(data_directory):
5152
# Calculate actual hash for given filename.
5253
# If hash for filename is not the same as the one in the file, raise
5354
# ValueError
55+
# This is a placeholder, replace it to write your solution.
5456
raise NotImplementedError('This is just a template -- you are expected to code this.')
5557

5658

solutions/.solutions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Where the exercises etc go, given the solutions
2+
3+
[solution.validate_data]
4+
out_path = '{one_down}/scripts/validate_data.py'

solutions/validate_data.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
import hashlib
1111

12+
1213
def file_hash(filename):
1314
""" Get byte contents of file `filename`, return SHA1 hash
1415
@@ -24,9 +25,15 @@ def file_hash(filename):
2425
"""
2526
# Open the file, read contents as bytes.
2627
# Calculate, return SHA1 has on the bytes from the file.
28+
# LAB(begin solution)
2729
with open(filename, 'rb') as fobj:
2830
contents = fobj.read()
2931
return hashlib.sha1(contents).hexdigest()
32+
# LAB(replace solution)
33+
# This is a placeholder, replace it to write your solution.
34+
raise NotImplementedError(
35+
'This is just a template -- you are expected to code this.')
36+
# LAB(end solution)
3037

3138

3239
def validate_data(data_directory):
@@ -48,6 +55,11 @@ def validate_data(data_directory):
4855
``data_hashes.txt`` file.
4956
"""
5057
# Read lines from ``data_hashes.txt`` file.
58+
# Split into SHA1 hash and filename
59+
# Calculate actual hash for given filename.
60+
# If hash for filename is not the same as the one in the file, raise
61+
# ValueError
62+
# LAB(begin solution)
5163
for line in open(op.join(data_directory, 'data_hashes.txt'), 'rt'):
5264
# Split into SHA1 hash and filename
5365
hash, filename = line.strip().split()
@@ -57,6 +69,10 @@ def validate_data(data_directory):
5769
# ValueError
5870
if hash != actual_hash:
5971
raise ValueError("Hash for {} does not match".format(filename))
72+
# LAB(replace solution)
73+
# This is a placeholder, replace it to write your solution.
74+
raise NotImplementedError('This is just a template -- you are expected to code this.')
75+
# LAB(end solution)
6076

6177

6278
def main():

0 commit comments

Comments
 (0)