def test_is_alive(self): """ It should be alive within a with context """ vm = VM(platform) self.assertFalse(vm.is_alive()) with VM(platform) as vm: self.assertTrue(vm.is_alive()) self.assertFalse(vm.is_alive())
def test_assert_on_re_create(self): """ It should allow to re create a vm """ vm = VM(platform) with vm as _: self.assertTrue(vm.is_alive()) self.assertFalse(vm.is_alive()) with vm as _: self.assertTrue(vm.is_alive())
def test_allocate_and_free(self): """ It should allocate and free the C VM """ code_ok = vm_module.lib.E_V8_OK with patch('v8cffi.vm.lib', autospec=True) as r: vm = VM(platform) vm_new = Mock(return_value=code_ok) r.v8cffi_vm_new = vm_new r.E_V8_OK = code_ok vm.__enter__() self.assertTrue(vm_new.called) vm_free = Mock() r.v8cffi_vm_free = vm_free vm.__exit__() self.assertTrue(vm_free.called) self.assertFalse(vm.is_alive()) self.assertRaises(AssertionError, vm.__exit__)