def test_lazy_constant(): import time def target(): time.sleep(1) return 12345 with pf.Graph() as graph: value = pf.lazy_constant(target) start = time.time() assert graph(value) == 12345 assert time.time() - start > 1 start = time.time() assert graph(value) == 12345 assert time.time() - start < 0.01
def test_lazy_constant_not_callable(): with pytest.raises(ValueError): with pf.Graph() as graph: pf.lazy_constant(None)