File: test_data_wrapper.py

package info (click to toggle)
python-pyface 8.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,944 kB
  • sloc: python: 54,107; makefile: 82
file content (54 lines) | stat: -rw-r--r-- 2,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

import unittest

try:
    import wx
except ImportError:
    wx_available = False
else:
    from pyface.ui.wx.data_view.data_wrapper import DataWrapper
    wx_available = True


@unittest.skipUnless(wx_available, "Test requires wx")
class TestDataWrapper(unittest.TestCase):

    def test_get_mimedata(self):
        toolkit_data = wx.DataObjectComposite()
        text_data = wx.CustomDataObject(wx.DataFormat('text/plain'))
        text_data.SetData(b'hello world')
        toolkit_data.Add(text_data)
        data_wrapper = DataWrapper(toolkit_data=toolkit_data)
        self.assertEqual(data_wrapper.mimetypes(), {'text/plain'})
        self.assertEqual(data_wrapper.get_mimedata('text/plain'), b'hello world')

    def test_set_mimedata(self):
        data_wrapper = DataWrapper()
        toolkit_data = data_wrapper.toolkit_data
        data_wrapper.set_mimedata('text/plain', b'hello world')
        self.assertEqual(data_wrapper.mimetypes(), {'text/plain'})
        wx_format = wx.DataFormat('text/plain')
        self.assertTrue(toolkit_data.IsSupported(wx_format))
        text_data = toolkit_data.GetObject(wx_format)
        self.assertEqual(text_data.GetData(), b'hello world')

    def test_ignore_non_custom(self):
        toolkit_data = wx.DataObjectComposite()
        html_data = wx.HTMLDataObject()
        html_data.SetHTML("hello world")
        toolkit_data.Add(html_data)
        text_data = wx.CustomDataObject(wx.DataFormat('text/plain'))
        text_data.SetData(b'hello world')
        toolkit_data.Add(text_data)
        data_wrapper = DataWrapper(toolkit_data=toolkit_data)
        self.assertTrue('text/plain' in data_wrapper.mimetypes())
        self.assertEqual(data_wrapper.get_mimedata('text/plain'), b'hello world')