2022-05-08 07:52:08 +00:00
|
|
|
from pyodide_test_runner import run_in_pyodide
|
2022-04-02 12:07:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
@run_in_pyodide(packages=["lazy-object-proxy"])
|
2022-05-26 02:47:43 +00:00
|
|
|
def test_lazy_object_proxy(selenium):
|
2022-04-02 12:07:50 +00:00
|
|
|
import lazy_object_proxy
|
|
|
|
|
|
|
|
def expensive_func():
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
print("starting calculation")
|
|
|
|
# just as example for a slow computation
|
|
|
|
sleep(0.1)
|
|
|
|
print("finished calculation")
|
|
|
|
# return the result of the calculation
|
|
|
|
return 10
|
|
|
|
|
|
|
|
obj = lazy_object_proxy.Proxy(expensive_func)
|
|
|
|
# function is called only when object is actually used
|
|
|
|
assert obj == 10 # now expensive_func is called
|
|
|
|
|
|
|
|
assert obj == 10 # the result without calling the expensive_func
|