def test_close_with_write(self): # Test close with a write self.fh_wrapper.write("some things") self.fh_wrapper.close() assert_equal(self.fh_wrapper._fh, NullFileHandle) assert_equal(self.fh_wrapper.manager, self.manager) # This is somewhat coupled assert_not_in(self.fh_wrapper, self.manager.cache)
def test_remove(self): # In cache fh_wrapper = self.manager.open(self.file1.name) assert_in(fh_wrapper.name, self.manager.cache) self.manager.remove(fh_wrapper) assert_not_in(fh_wrapper.name, self.manager.cache) # Not in cache self.manager.remove(fh_wrapper) assert_not_in(fh_wrapper.name, self.manager.cache)
def test_cleanup_single(self): fh_wrapper = self.manager.open(self.file1.name) fh_wrapper.last_accessed = 123456 def time_func(): return 123458.1 self.manager.cleanup(time_func) assert_not_in(fh_wrapper.name, self.manager.cache) assert_equal(len(self.manager.cache), 0)
def test_cleanup_natural(self): FileHandleManager.set_max_idle_time(1) fh_wrapper1 = self.manager.open(self.file1.name) fh_wrapper2 = self.manager.open(self.file2.name) fh_wrapper1.write("Some things") time.sleep(1.5) fh_wrapper2.write("Other things.") assert_not_in(fh_wrapper1.name, self.manager.cache) assert_in(fh_wrapper2.name, self.manager.cache) # Now that 1 is closed, try writing again fh_wrapper1.write("Some things") assert_in(fh_wrapper1.name, self.manager.cache) assert not fh_wrapper1._fh.closed
def test_cleanup_many(self): fh_wrappers = [ self.manager.open(self.file1.name), self.manager.open(self.file2.name), self.manager.open(NamedTemporaryFile('r').name), self.manager.open(NamedTemporaryFile('r').name), self.manager.open(NamedTemporaryFile('r').name), ] for i, fh_wrapper in enumerate(fh_wrappers): fh_wrapper.last_accessed = 123456 + i def time_func(): return 123460.1 self.manager.cleanup(time_func) assert_equal(len(self.manager.cache), 2) for fh_wrapper in fh_wrappers[:3]: assert_not_in(fh_wrapper.name, self.manager.cache) for fh_wrapper in fh_wrappers[3:]: assert_in(fh_wrapper.name, self.manager.cache)
def test_clear(self): self.repo.clear() assert_not_in(self.node, self.repo.nodes) assert_not_in(self.node, self.repo.pools)
def test_add_contains(self): autospec_method(self.collection.contains_item) item, update_func = mock.Mock(), mock.Mock() assert not self.collection.add(item, update_func) assert_not_in(item.get_name(), self.collection)
def test_remove(self): name = 'the_name' self.collection[name] = item = mock.Mock() self.collection.remove(name) assert_not_in(name, self.collection) item.disable.assert_called_with()