File: test_field_action.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 (115 lines) | stat: -rw-r--r-- 3,133 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# (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

from pyface.fields.api import ComboField, SpinField, TextField
from pyface.gui import GUI
from pyface.window import Window
from ..field_action import FieldAction


class TestFieldAction(unittest.TestCase):
    def setUp(self):
        self.gui = GUI()

        self.parent = Window()
        self.parent.create()
        self.addCleanup(self._destroy_parent)

    def _destroy_parent(self):
        self.parent.destroy()
        self.parent = None

    def test_combo_field_action(self):
        # test whether function is called by updating list
        # XXX should really use mock
        memo = []

        def perform(value):
            memo.append(value)

        action = FieldAction(
            name="Dummy",
            field_type=ComboField,
            field_defaults={
                "values": ["a", "b", "c"],
                "value": "a",
                "tooltip": "Dummy",
            },
            on_perform=perform,
        )
        control = action.create_control(self.parent.control)
        try:
            self.gui.process_events()

            control._field.value = "b"
            self.gui.process_events()

            self.assertEqual(memo, ["b"])
        finally:
            control._field.destroy()

    def test_text_field_action(self):
        # test whether function is called by updating list
        # XXX should really use mock
        memo = []

        def perform(value):
            memo.append(value)

        action = FieldAction(
            name="Dummy",
            field_type=TextField,
            field_defaults={"value": "a", "tooltip": "Dummy"},
            on_perform=perform,
        )
        control = action.create_control(self.parent.control)

        try:
            self.gui.process_events()

            control._field.value = "b"
            self.gui.process_events()

            self.assertEqual(memo, ["b"])
        finally:
            control._field.destroy()

    def test_spin_field_action(self):
        # test whether function is called by updating list
        # XXX should really use mock
        memo = []

        def perform(value):
            memo.append(value)

        action = FieldAction(
            name="Dummy",
            field_type=SpinField,
            field_defaults={
                "value": 1,
                "bounds": (0, 100),
                "tooltip": "Dummy",
            },
            on_perform=perform,
        )
        control = action.create_control(self.parent.control)

        try:
            self.gui.process_events()

            control._field.value = 5
            self.gui.process_events()

            self.assertEqual(memo, [5])
        finally:
            control._field.destroy()