コード例 #1
0
ファイル: tests_context.py プロジェクト: yaaminu/v8-cffi
    def test_assert_on_re_enter(self):
        """
        It should fail to re enter
        """
        s = context._String()

        with s as _:
            self.assertRaises(AssertionError, s.__enter__)
コード例 #2
0
ファイル: tests_context.py プロジェクト: theatlantic/v8-cffi
    def test_assert_on_re_enter(self):
        """
        It should fail to re enter
        """
        s = context._String()

        with s as _:
            self.assertRaises(AssertionError, s.__enter__)
コード例 #3
0
ファイル: tests_context.py プロジェクト: theatlantic/v8-cffi
 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
コード例 #4
0
ファイル: tests_context.py プロジェクト: theatlantic/v8-cffi
 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
コード例 #5
0
ファイル: tests_context.py プロジェクト: yaaminu/v8-cffi
 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
コード例 #6
0
ファイル: tests_context.py プロジェクト: yaaminu/v8-cffi
 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
コード例 #7
0
ファイル: tests_context.py プロジェクト: theatlantic/v8-cffi
    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__)
コード例 #8
0
ファイル: tests_context.py プロジェクト: theatlantic/v8-cffi
    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)
コード例 #9
0
ファイル: tests_context.py プロジェクト: yaaminu/v8-cffi
    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__)
コード例 #10
0
ファイル: tests_context.py プロジェクト: yaaminu/v8-cffi
    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)
コード例 #11
0
ファイル: tests_context.py プロジェクト: yaaminu/v8-cffi
 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)
コード例 #12
0
ファイル: tests_context.py プロジェクト: theatlantic/v8-cffi
    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)
コード例 #13
0
ファイル: tests_context.py プロジェクト: yaaminu/v8-cffi
    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)
コード例 #14
0
ファイル: tests_context.py プロジェクト: theatlantic/v8-cffi
 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)