Example #1
0
def compareAndRenameFileIfNotEqual(orig, new):
    if os.path.exists(orig):
        oldHash = hashFile(orig)
        newHash = hashFile(new)
        if (oldHash == newHash):
            os.remove(new)
            return
    os.rename(new, orig)
Example #2
0
    def testBigFile(self):
        with NamedTemporaryFile() as f:
            for i in range(1000):
                f.write(b'0123456789' * 1024)
            f.flush()

            hashFile(f.name) == binascii.unhexlify(
                "c94d8ee379dcbef70b3da8fb57df8020b76b0c70")
Example #3
0
    def testBigFile(self):
        with NamedTemporaryFile() as f:
            for i in range(1000):
                f.write(b'0123456789' * 1024)
            f.flush()

            hashFile(f.name) == binascii.unhexlify(
                "c94d8ee379dcbef70b3da8fb57df8020b76b0c70")
Example #4
0
def compareAndRenameFileIfNotEqual(orig, new):
    if os.path.exists(orig):
        oldHash = hashFile(orig)
        newHash = hashFile(new)
        if (oldHash == newHash):
            os.remove(new)
            return
    os.rename(new, orig)
Example #5
0
 def testMissingFile(self):
     """Missing files should be treated as empty"""
     # assertLogs was introduced in python 3.4
     if sys.version_info < (3, 4):
         assert hashFile("does-not-exist") == binascii.unhexlify(
             "da39a3ee5e6b4b0d3255bfef95601890afd80709")
     else:
         with self.assertLogs(level='WARNING') as cm:
             assert hashFile("does-not-exist") == binascii.unhexlify(
                 "da39a3ee5e6b4b0d3255bfef95601890afd80709")
             self.assertEqual(cm.records[0].msg, "Cannot hash file: %s")
Example #6
0
 def testMissingFile(self):
     """Missing files should be treated as empty"""
     # assertLogs was introduced in python 3.4
     if sys.version_info < (3, 4):
         assert hashFile("does-not-exist") == binascii.unhexlify(
             "da39a3ee5e6b4b0d3255bfef95601890afd80709")
     else:
         with self.assertLogs(level='WARNING') as cm:
             assert hashFile("does-not-exist") == binascii.unhexlify(
                 "da39a3ee5e6b4b0d3255bfef95601890afd80709")
             self.assertEqual(cm.records[0].msg, "Cannot hash file: %s")
Example #7
0
 def testMissingFile(self):
     """Missing files should be treated as empty"""
     assert hashFile("does-not-exist") == binascii.unhexlify(
         "da39a3ee5e6b4b0d3255bfef95601890afd80709")
Example #8
0
 def testMissingFile(self):
     """Missing files should be treated as empty"""
     assert hashFile("does-not-exist") == binascii.unhexlify(
         "da39a3ee5e6b4b0d3255bfef95601890afd80709")