def test_clear(self): lazy_constant = ThreadLocalLazyConstant(qcore.utime) lazy_time = lazy_constant.get_value() with qcore.TimeOffset(qcore.HOUR): assert_eq(lazy_time, lazy_constant.get_value(), tolerance=qcore.MINUTE) lazy_constant.clear() assert_ne(lazy_time, lazy_constant.get_value(), tolerance=qcore.MINUTE)
def test_not_compute(self): lazy_constant = ThreadLocalLazyConstant(lambda: not_computed) assert_is(None, lazy_constant.compute()) assert_is(None, lazy_constant.get_value())
def execute(): with lock: results.append(lazy_constant.get_value())