Пример #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)
Пример #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")
Пример #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")
Пример #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)
Пример #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")
Пример #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")
Пример #7
0
 def testMissingFile(self):
     """Missing files should be treated as empty"""
     assert hashFile("does-not-exist") == binascii.unhexlify(
         "da39a3ee5e6b4b0d3255bfef95601890afd80709")
Пример #8
0
 def testMissingFile(self):
     """Missing files should be treated as empty"""
     assert hashFile("does-not-exist") == binascii.unhexlify(
         "da39a3ee5e6b4b0d3255bfef95601890afd80709")