Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_memory_view():
assert isinstance(Instance(TEST_BYTES).memory.uint8_view(), Uint8Array)
def test_is_a_class(self):
self.assertTrue(inspect.isclass(Instance))
def test_bytes_per_element(self):
self.assertEqual(Instance(TEST_BYTES).uint8_memory_view().bytes_per_element, 1)
self.assertEqual(Instance(TEST_BYTES).int8_memory_view().bytes_per_element, 1)
self.assertEqual(Instance(TEST_BYTES).uint16_memory_view().bytes_per_element, 2)
self.assertEqual(Instance(TEST_BYTES).int16_memory_view().bytes_per_element, 2)
self.assertEqual(Instance(TEST_BYTES).uint32_memory_view().bytes_per_element, 4)
self.assertEqual(Instance(TEST_BYTES).int32_memory_view().bytes_per_element, 4)
def test_call_i32_i64_f32_f64_f64(self):
self.assertEqual(
round(Instance(TEST_BYTES).exports['i32_i64_f32_f64_f64'](1, 2, 3.4, 5.6), 6),
1 + 2 + 3.4 + 5.6
)
def test_set_bytearray():
memory = Instance(TEST_BYTES).memory.uint8_view()
memory[7:12] = bytearray(b'abcde')
assert memory[7:12] == [97, 98, 99, 100, 101]
def test_set_single_value():
memory = Instance(TEST_BYTES).memory.uint8_view()
assert memory[7] == 0
memory[7] = 42
assert memory[7] == 42
def test_hello_world(self):
instance = Instance(TEST_BYTES)
pointer = instance.exports['string']()
memory = instance.uint8_memory_view(pointer)
nth = 0
string = ''
while (0 != memory[nth]):
string += chr(memory[nth])
nth += 1
self.assertEqual(string, 'Hello, World!')
def test_hello_world():
instance = Instance(TEST_BYTES)
pointer = instance.exports.string()
memory = instance.memory.uint8_view(pointer)
nth = 0
string = ''
while (0 != memory[nth]):
string += chr(memory[nth])
nth += 1
assert string, 'Hello, World!'
def test_deserialize():
serialized_module = Module(TEST_BYTES).serialize()
module = Module.deserialize(serialized_module)
del serialized_module
assert module.instantiate().exports.sum(1, 2) == 3
def test_compile():
assert isinstance(Module(TEST_BYTES), Module)