Пример #1
0
 def test_exception_in_thunk(self):
     from __pypy__ import lazy
     def f(x):
         if x:
             return 42
         raise ValueError
     f = lazy(f)
     y = f(3)
     assert y == 42
     y = f(0)
     raises(ValueError, "str(y)")
     raises(ValueError, "str(y)")
Пример #2
0
 def test_lazy(self):
     from __pypy__ import lazy
     lst = []
     def f(x):
         lst.append(x)
         return x+5
     f = lazy(f)
     y = f(3)
     assert lst == []
     assert type(y) is int
     assert lst == [3]
     assert type(y) is int
     assert lst == [3]