def test_lease_file(self): with TempDir() as cache_dir: cache = Directory(path=cache_dir) key = 'foo' self.assertFalse(cache.exists(key)) with cache.lease_file(key, create=True) as path: self.assertTrue(cache.exists(key)) self.assertTrue(os.path.exists(path)) with open(path, 'r') as f: self.assertNotEqual(f.read(), key) with open(path, 'w') as f: f.write(key) self.assertTrue(cache.exists(key)) with cache.lease_file(key) as path: with open(path, 'r') as f: self.assertEqual(f.read(), key)