Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions extism/extism.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import functools
import pickle


HOST_FN_REGISTRY: List[Any] = []


Expand Down Expand Up @@ -644,7 +643,7 @@ def _convert_value(x):
return Val(ValType.I64, x.v.i64)
elif x.t == 2:
return Val(ValType.F32, x.v.f32)
elif x.y == 3:
elif x.t == 3:
return Val(ValType.F64, x.v.f64)
return None

Expand Down
19 changes: 19 additions & 0 deletions tests/test_extism.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,25 @@ def _infinite_loop_wasm(self):
return read_test_wasm("loop.wasm")


ExtismVal = namedtuple("ExtismVal", ["t", "v"])


class TestConvertValue(unittest.TestCase):
"""Tests for the _convert_value helper that converts CFFI ExtismVal structs."""

def _make_extism_val(self, t, **kwargs):
"""Create a mock ExtismVal with type tag `t` and value fields."""
val_union = namedtuple("ValUnion", kwargs.keys())(**kwargs)
return ExtismVal(t=t, v=val_union)

def test_convert_f64_value(self):
x = self._make_extism_val(3, f64=3.14)
result = extism.extism._convert_value(x)
self.assertIsNotNone(result, "_convert_value returned None for F64 input")
self.assertEqual(result.t, extism.ValType.F64)
self.assertAlmostEqual(result.value, 3.14)


def read_test_wasm(p):
path = join(dirname(__file__), "..", "wasm", p)
with open(path, "rb") as wasm_file:
Expand Down