Coverage for examples/loader.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-02-20 16:25 +0000

1# This example shows how you can use the `wasmtime.loader` module to load wasm 

2# modules as if they were native Python modules 

3 

4import wasmtime.loader # noqa: F401 

5 

6import loader_load_python # type: ignore 

7import loader_load_wasm # type: ignore 

8import loader_load_wasi # type: ignore # noqa: F401 

9 

10# This imports our `loader_add.wat` file next to this module 

11import loader_add # type: ignore 

12assert(loader_add.add(1, 2) == 3) 

13 

14# This imports our `loader_load_wasm.wat`, which in turn imports 

15# `loader_load_wasm_target.wat`, which gives us the answer of 4 

16assert(loader_load_wasm.call_dependency() == 4) 

17 

18# This imports our `loader_load_python.wat` file which then imports its own 

19# python file. 

20assert(loader_load_python.call_python() == 42) 

21 

22# This imports our `loader_load_wasi.wat`, which in turn imports 

23# the random_get functionality from the wasi runtime environment 

24random_value = loader_load_wasi.wasi_random() 

25assert(random_value >= 0 and random_value < 256)