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
|
import unittest
from pyface.ui.qt4.util.gui_test_assistant import \
GuiTestAssistant
from traits.api import Event, HasStrictTraits
class ExampleObject(HasStrictTraits):
""" Test class; target for test_event_loop_until_traits_change. """
spam = Event
eggs = Event
class TestGuiTestAssistant(GuiTestAssistant, unittest.TestCase):
def test_event_loop_until_traits_change_with_single_trait_success(self):
# event_loop_until_traits_change calls self.fail on timeout.
obj = ExampleObject()
# Successful case.
with self.event_loop_until_traits_change(obj, 'spam'):
obj.spam = True
def test_event_loop_until_traits_change_with_single_trait_failure(self):
# event_loop_until_traits_change calls self.fail on timeout.
obj = ExampleObject()
# Failing case.
with self.assertRaises(AssertionError):
with self.event_loop_until_traits_change(obj, 'spam',
timeout=0.1):
obj.eggs = True
def test_event_loop_until_traits_change_with_multiple_traits_success(self):
# event_loop_until_traits_change calls self.fail on timeout.
obj = ExampleObject()
with self.event_loop_until_traits_change(obj, 'spam', 'eggs'):
obj.spam = True
obj.eggs = True
def test_event_loop_until_traits_change_with_multiple_traits_failure(self):
# event_loop_until_traits_change calls self.fail on timeout.
obj = ExampleObject()
with self.assertRaises(AssertionError):
with self.event_loop_until_traits_change(obj, 'spam', 'eggs',
timeout=0.1):
obj.eggs = True
# event_loop_until_traits_change calls self.fail on timeout.
with self.assertRaises(AssertionError):
with self.event_loop_until_traits_change(obj, 'spam', 'eggs',
timeout=0.1):
obj.spam = True
def test_event_loop_until_traits_change_with_no_traits_success(self):
# event_loop_until_traits_change calls self.fail on timeout.
obj = ExampleObject()
# Successful case.
with self.event_loop_until_traits_change(obj):
pass
|