Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 7
0
 def testMissingFile(self):
     """Missing files should be treated as empty"""
     assert hashFile("does-not-exist") == binascii.unhexlify(
         "da39a3ee5e6b4b0d3255bfef95601890afd80709")
Exemplo n.º 8
0
 def testMissingFile(self):
     """Missing files should be treated as empty"""
     assert hashFile("does-not-exist") == binascii.unhexlify(
         "da39a3ee5e6b4b0d3255bfef95601890afd80709")