Commit 1b570c89 authored by André Anjos's avatar André Anjos 💬

[data] Raise an IOError (instead of AssertionError) if data files do not check sum

parent f16e8b9a
Pipeline #1744 passed with stage
......@@ -217,18 +217,21 @@ class CachedDataSource(DataSource):
# files
checksum_filenames_noext = [os.path.splitext(f)[0] for f in checksum_filenames]
assert data_filenames == checksum_filenames_noext, "number of data " \
"files and checksum files for `%s' does not match (%d != %d)" % \
(filename, len(data_filenames), len(checksum_filenames_noext))
if data_filenames != checksum_filenames_noext:
raise IOError("number of data files and checksum files for `%s' " \
"does not match (%d != %d)" % (filename, len(data_filenames),
len(checksum_filenames_noext)))
# list of start/end indices to check that there are contiguous
indices = []
for f_data, f_chck in zip(data_filenames, checksum_filenames):
expected_chksum = open(f_chck, 'rt').read().strip()
current_chksum = hashFileContents(f_data)
assert expected_chksum == current_chksum, "data file `%s' has a " \
"checksum (%s) that differs from expected one (%s)" % \
(f_data, current_chksum, expected_chksum)
if expected_chksum != current_chksum:
raise IOError("data file `%s' has a checksum (%s) that differs " \
"from expected one (%s)" % (f_data, current_chksum,
expected_chksum))
r = index_re.match(f_data)
if r: indices.append((int(r.group(1)), int(r.group(2))))
......@@ -243,7 +246,8 @@ class CachedDataSource(DataSource):
ok_indices = sum([indices[i + 1][0] - indices[i][1] == 1
for i in range(len(indices) - 1)])
assert ok_indices, "data file `%s' have missing indices." % f_data
if not ok_indices:
raise IOError("data file `%s' have missing indices." % f_data)
self.prefix = prefix
basename, data_ext = os.path.splitext(filename)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment