def test_key_lock_creates(self): with TempDir() as cache_dir, TempDir() as d: cache = Directory(path=cache_dir) key = 'foo_key' self.assertFalse(cache.exists(key)) with cache.lease(key, create=True): self.assertTrue(cache.exists(key)) self.assertTrue(cache.exists(key)) self.assertTrue(os.listdir(cache_dir))
def test_key_lock_unlock(self): with TempDir() as cache_dir, TempDir() as d: cache = Directory(path=cache_dir) foo_file = os.path.join(d, 'foo_file') with open(foo_file, 'w') as f: f.write('foo') key = 'foo_key' cache.store_file(foo_file, key) self.assertTrue(self.try_lock_from_another_process(cache_dir, key)) with cache.lease(key): self.assertFalse(self.try_lock_from_another_process(cache_dir, key)) self.assertTrue(self.try_lock_from_another_process(cache_dir, key))