def testPersistValidation(self): logger.configureCategory("APP", logger.Severity.ERR) testFile = getTempFileName() p = persist.Persist(testFile, {'test': 1}) p.commit() p = persist.Persist(testFile, [], validator=lambda v: isinstance(v, list)) self.assertEqual(p.data, []) os.unlink(testFile) logger.configureCategory("APP", logger.Severity.WARN)
def testPersistStore(self): testFile = getTempFileName() p = persist.Persist(testFile, {}) self.assertEqual(p.storeFile, testFile) self.assertEqual(p.data, {}) p.data['test'] = 1 p.commit() p = persist.Persist(testFile, {}) self.assert_('test' in p.data) self.assertEqual(p.data['test'], 1) os.unlink(testFile)
def testPersistCorrupted(self): logger.configureCategory("APP", logger.Severity.ERR) testFile = getTempFileName() f = open(testFile, 'w') f.write('garbage') f.close() p = persist.Persist(testFile, {}) self.assertEqual(p.data, {}) os.unlink(testFile) logger.configureCategory("APP", logger.Severity.WARN)