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

Add leading zeros to adler32 checksum to ensure 8 chars length #9809

Merged
merged 2 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/python/Utils/FileTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def calculateChecksums(filename):
if len(cksumStdout) != 2 or int(cksumStdout[1]) != filesize:
raise RuntimeError("Something went wrong with the cksum calculation !")

return ("%x" % (adler32Checksum & 0xffffffff), "%s" % cksumStdout[0])
return (format(adler32Checksum & 0xffffffff, '08x'), "%s" % cksumStdout[0])


def tail(filename, nLines=20):
Expand Down Expand Up @@ -117,4 +117,4 @@ def getFullPath(name, envPath="PATH"):
fullPath = os.path.join(path, name)
if os.path.exists(fullPath):
return fullPath
return None
return None
26 changes: 23 additions & 3 deletions test/python/Utils_t/FileTools_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ def test_fileInfo(self):
silly = "This is a rather ridiculous string"
filename = os.path.join(self.testDir, 'fileInfo.test')

f = open(filename, 'w')
f.write(silly)
f.close()
with open(filename, 'w') as fObj:
fObj.write(silly)

info = FileTools.getFileInfo(filename=filename)
self.assertEqual(info['Name'], filename)
Expand All @@ -84,5 +83,26 @@ def test_getFullPath(self):
fullPath = FileTools.getFullPath("this_shouldnt_be")
self.assertEqual(fullPath, None)

def testChecksum(self):
"""
Test file checksums calculation
"""
filename = os.path.join(self.testDir, 'fileInfo.test')
with open(filename, 'w') as fObj:
fObj.write("")

(adler32, cksum) = FileTools.calculateChecksums(filename=filename)
self.assertEqual(adler32, "00000001")
self.assertEqual(cksum, "4294967295")

silly = "This is a rather ridiculous string"
with open(filename, 'w') as fObj:
fObj.write(silly * 100001)
(adler32, cksum) = FileTools.calculateChecksums(filename=filename)
self.assertEqual(adler32, "827db5b1")
self.assertEqual(cksum, "3774692924")
return


if __name__ == "__main__":
unittest.main()