def test_assert_on_re_enter(self): """ It should fail to re enter """ s = context._String() with s as _: self.assertRaises(AssertionError, s.__enter__)
def test_to_bytes(self): """ It should return the string bytes """ with context._String() as s: string_ptr = s.string_ptr s.string_ptr = [context.ffi.new('char[]', b'foo')] s.len_ptr[0] = 3 self.assertEqual(s.to_bytes(), b'foo') s.string_ptr = string_ptr
def test_to_str(self): """ It should support str call """ with context._String() as s: string_ptr = s.string_ptr s.string_ptr = [context.ffi.new('char[]', b'foo')] s.len_ptr[0] = 3 self.assertEqual(six.text_type(s), 'foo') s.string_ptr = string_ptr
def test_assert_on_re_exit(self): """ It should fail to re exit """ s = context._String() self.assertRaises(AssertionError, s.__exit__) with s as _: pass self.assertRaises(AssertionError, s.__exit__)
def test_free(self): """ It should free the string """ with patch('v8cffi.context.lib', autospec=True) as r: s = context._String() s.__enter__() free = Mock() r.v8cffi_free = free s.__exit__() self.assertTrue(free.called)
def test_with(self): """ It should support with statement """ with context._String() as s: self.assertIsInstance(s, context._String) self.assertEqual(context.ffi.typeof('char **'), context.ffi.typeof(s.string_ptr)) self.assertEqual(context.ffi.typeof('size_t *'), context.ffi.typeof(s.len_ptr)) self.assertEqual(s.string_ptr[0], context.ffi.NULL) self.assertEqual(s.len_ptr[0], 0)
def test_assert_on_re_create(self): """ It should allow to re create """ s = context._String() with s as _: self.assertIsNotNone(s.string_ptr) self.assertIsNone(s.string_ptr) with s as _: self.assertIsNotNone(s.string_ptr)
def test_with(self): """ It should support with statement """ with context._String() as s: self.assertIsInstance(s, context._String) self.assertEqual( context.ffi.typeof('char **'), context.ffi.typeof(s.string_ptr)) self.assertEqual( context.ffi.typeof('size_t *'), context.ffi.typeof(s.len_ptr)) self.assertEqual(s.string_ptr[0], context.ffi.NULL) self.assertEqual(s.len_ptr[0], 0)