diff --git a/src/python/Utils/FileTools.py b/src/python/Utils/FileTools.py index eea77bfbbf..7f10bee731 100644 --- a/src/python/Utils/FileTools.py +++ b/src/python/Utils/FileTools.py @@ -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): @@ -117,4 +117,4 @@ def getFullPath(name, envPath="PATH"): fullPath = os.path.join(path, name) if os.path.exists(fullPath): return fullPath - return None \ No newline at end of file + return None diff --git a/test/python/Utils_t/FileTools_t.py b/test/python/Utils_t/FileTools_t.py index 05445f99d8..46987f1d89 100644 --- a/test/python/Utils_t/FileTools_t.py +++ b/test/python/Utils_t/FileTools_t.py @@ -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) @@ -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()