Esempio n. 1
0
 def testOpeningNonExistingFile(self):
     """Test we don't throw exception when opening non-existing file."""
     randomfile = tempfile.NamedTemporaryFile()
     randomfile.close()
     self.assertFalse(os.path.exists(randomfile.name),
                      "Expected file to not exist.")
     eventstores._KeyValuePersister(randomfile.name)
Esempio n. 2
0
    def _check_md5_is_correct(self, dirpath):
        print("Directory:", dirpath)
        md5filename = os.path.join(dirpath, 'checksums.md5')
        self.assertTrue(os.path.exists(md5filename))

        checksums = eventstores._KeyValuePersister(md5filename)
        files = [fname for fname in os.listdir(dirpath) if
                 fname != 'checksums.md5']
        self.assertEqual(set(files), set(checksums.keys()))

        for fname, checksum in checksums.items():
            hasher = hashlib.md5()
            abspath = os.path.join(dirpath, fname)
            with open(abspath, 'rb') as f:
                eventstores._hashfile(f, hasher)
            self.assertEqual(hasher.hexdigest(), checksum)
Esempio n. 3
0
 def _open_persister(self):
     """Return a newly opened prepopulated `_KeyValuePersister`."""
     return eventstores._KeyValuePersister(self.keyvalfile)