Coverage for tests/test_tag.py: 100%

58 statements  

« prev     ^ index     » next       coverage.py v7.11.3, created at 2026-05-07 14:30 +0000

1import unittest 

2from wasmtime import * 

3 

4 

5class TestTag(unittest.TestCase): 

6 def test_new(self): 

7 store = Store() 

8 functype = FuncType([ValType.i32()], []) 

9 tagtype = TagType(functype) 

10 tag = Tag(store, tagtype) 

11 self.assertIsNotNone(tag) 

12 

13 def test_type(self): 

14 functype = FuncType([ValType.i32()], []) 

15 tagtype = TagType(functype) 

16 

17 self.assertEqual(tagtype.functype.params, [ValType.i32()]) 

18 self.assertEqual(tagtype.functype.results, []) 

19 

20 config = Config() 

21 config.wasm_exceptions = True 

22 engine = Engine(config) 

23 

24 module = Module(engine, """ 

25 (module 

26 (tag (export "mytag") (param i32)) 

27 ) 

28 """) 

29 ty = module.exports[0].type 

30 assert isinstance(ty, TagType) 

31 self.assertEqual(ty.functype.params, [ValType.i32()]) 

32 self.assertEqual(ty.functype.results, []) 

33 

34 store = Store(engine) 

35 tag = Tag(store, tagtype) 

36 retrieved = tag.type(store) 

37 self.assertIsInstance(retrieved, TagType) 

38 

39 def test_eq(self): 

40 store = Store() 

41 functype = FuncType([ValType.i32()], []) 

42 tagtype = TagType(functype) 

43 tag1 = Tag(store, tagtype) 

44 tag2 = Tag(store, tagtype) 

45 self.assertFalse(tag1.eq(store, tag2)) 

46 self.assertTrue(tag1.eq(store, tag1)) 

47 

48 def test_wrong_type(self): 

49 store = Store() 

50 with self.assertRaises(TypeError): 

51 Tag(store, "not a tagtype") # type: ignore 

52 

53 def test_tag_import(self): 

54 config = Config() 

55 config.wasm_exceptions = True 

56 engine = Engine(config) 

57 

58 module = Module(engine, """ 

59 (module (import "" "" (tag))) 

60 """) 

61 store = Store(engine) 

62 with self.assertRaises(WasmtimeError): 

63 Instance(store, module, []) 

64 Instance(store, module, [Tag(store, TagType(FuncType([], [])))]) 

65 

66 def test_tag_export(self): 

67 config = Config() 

68 config.wasm_exceptions = True 

69 engine = Engine(config) 

70 

71 module = Module(engine, """ 

72 (module (tag (export ""))) 

73 """) 

74 store = Store(engine) 

75 i = Instance(store, module, []) 

76 tag = i.exports(store)[''] 

77 assert isinstance(tag, Tag) 

78 self.assertEqual(tag.type(store).functype.params, []) 

79 self.assertEqual(tag.type(store).functype.results, [])