コード例 #1
0
    def test_extended_notifiers_functions_failing(self):
        obj = ExtendedNotifiers()

        obj._on_trait_change(failing_function_listener_0,
                             'fail',
                             dispatch='extended')
        obj._on_trait_change(failing_function_listener_1,
                             'fail',
                             dispatch='extended')
        obj._on_trait_change(failing_function_listener_2,
                             'fail',
                             dispatch='extended')
        obj._on_trait_change(failing_function_listener_3,
                             'fail',
                             dispatch='extended')
        obj._on_trait_change(failing_function_listener_4,
                             'fail',
                             dispatch='extended')

        obj.fail = 1

        _py2to3.assertCountEqual(self, [0, 1, 2, 3, 4], obj.exceptions_from)
        # 10 failures: 5 are from the internal extended listeners, see
        # test_extended_notifiers_methods_failing
        self.assertEqual([(obj, 'fail', 0, 1)] * 10, self.exceptions)
コード例 #2
0
ファイル: test_class_traits.py プロジェクト: Jfeng3/traits
    def test_class_traits_with_metadata(self):

        # Retrieve all traits that have the `marked` metadata
        # attribute set to True.
        traits = C.class_traits(marked=True)
        _py2to3.assertCountEqual(self, traits.keys(), ("y", "name"))

        # Retrieve all traits that have a `marked` metadata attribute,
        # regardless of its value.
        marked_traits = C.class_traits(marked=lambda attr: attr is not None)
        _py2to3.assertCountEqual(self, marked_traits, ("y", "name", "lst"))
コード例 #3
0
    def test_class_traits_with_metadata(self):

        # Retrieve all traits that have the `marked` metadata
        # attribute set to True.
        traits = C.class_traits(marked=True)
        _py2to3.assertCountEqual(self, list(traits.keys()), ('y', 'name'))

        # Retrieve all traits that have a `marked` metadata attribute,
        # regardless of its value.
        marked_traits = C.class_traits(marked=lambda attr: attr is not None)
        _py2to3.assertCountEqual(self, marked_traits, ('y', 'name', 'lst'))
コード例 #4
0
    def test_dynamic_notifiers_functions_failing(self):
        obj = DynamicNotifiers()

        obj.on_trait_change(failing_function_listener_0, 'fail')
        obj.on_trait_change(failing_function_listener_1, 'fail')
        obj.on_trait_change(failing_function_listener_2, 'fail')
        obj.on_trait_change(failing_function_listener_3, 'fail')
        obj.on_trait_change(failing_function_listener_4, 'fail')

        obj.fail = 1

        _py2to3.assertCountEqual(self, [0, 1, 2, 3, 4], obj.exceptions_from)
        # 10 failures: 5 are from the internal dynamic listeners, see
        # test_dynamic_notifiers_methods_failing
        self.assertEqual([(obj, 'fail', 0, 1)] * 10, self.exceptions)
コード例 #5
0
    def test_dynamic_notifiers_functions_failing(self):
        obj = DynamicNotifiers()

        obj.on_trait_change(failing_function_listener_0, "fail")
        obj.on_trait_change(failing_function_listener_1, "fail")
        obj.on_trait_change(failing_function_listener_2, "fail")
        obj.on_trait_change(failing_function_listener_3, "fail")
        obj.on_trait_change(failing_function_listener_4, "fail")

        obj.fail = 1

        _py2to3.assertCountEqual(self, [0, 1, 2, 3, 4], obj.exceptions_from)
        # 10 failures: 5 are from the internal dynamic listeners, see
        # test_dynamic_notifiers_methods_failing
        self.assertEqual([(obj, "fail", 0, 1)] * 10, self.exceptions)
コード例 #6
0
    def test_extended_notifiers_functions_failing(self):
        obj = ExtendedNotifiers()

        obj._on_trait_change(failing_function_listener_0, 'fail',
                             dispatch='extended')
        obj._on_trait_change(failing_function_listener_1, 'fail',
                             dispatch='extended')
        obj._on_trait_change(failing_function_listener_2, 'fail',
                             dispatch='extended')
        obj._on_trait_change(failing_function_listener_3, 'fail',
                             dispatch='extended')
        obj._on_trait_change(failing_function_listener_4, 'fail',
                             dispatch='extended')

        obj.fail = 1

        _py2to3.assertCountEqual(self, [0, 1, 2, 3, 4], obj.exceptions_from)
        # 10 failures: 5 are from the internal extended listeners, see
        # test_extended_notifiers_methods_failing
        self.assertEqual([(obj, 'fail', 0, 1)] * 10, self.exceptions)
コード例 #7
0
    def test_assert_trait_changes_async_events(self):
        # Check access to the events after the with
        # block completes.
        thread_count = 10
        events_per_thread = 100

        class A(HasTraits):
            event = Event(Int)

        a = A()

        def thread_target(obj, count):
            "Fire obj.event 'count' times."
            for n in xrange(count):
                time.sleep(0.001)
                obj.event = n

        threads = [
            threading.Thread(target=thread_target, args=(a, events_per_thread))
            for _ in xrange(thread_count)
        ]

        expected_count = thread_count * events_per_thread
        with self.assertTraitChangesAsync(a,
                                          'event',
                                          expected_count,
                                          timeout=60.0) as event_collector:
            for t in threads:
                t.start()

        for t in threads:
            t.join()

        _py2to3.assertCountEqual(
            self,
            event_collector.events,
            range(events_per_thread) * thread_count,
        )
コード例 #8
0
    def test_all_class_traits(self):
        expected = ['x', 'name', 'trait_added', 'trait_modified']
        _py2to3.assertCountEqual(self, A.class_traits(), expected)

        # Check that derived classes report the correct traits.
        _py2to3.assertCountEqual(self, B.class_traits(), expected)

        expected.extend(('lst', 'y'))
        _py2to3.assertCountEqual(self, C.class_traits(), expected)
コード例 #9
0
ファイル: test_class_traits.py プロジェクト: Jfeng3/traits
    def test_all_class_traits(self):
        expected = ["x", "name", "trait_added", "trait_modified"]
        _py2to3.assertCountEqual(self, A.class_traits(), expected)

        # Check that derived classes report the correct traits.
        _py2to3.assertCountEqual(self, B.class_traits(), expected)

        expected.extend(("lst", "y"))
        _py2to3.assertCountEqual(self, C.class_traits(), expected)
コード例 #10
0
    def test_all_class_traits(self):
        expected = ["x", "name", "trait_added", "trait_modified"]
        _py2to3.assertCountEqual(self, A.class_traits(), expected)

        # Check that derived classes report the correct traits.
        _py2to3.assertCountEqual(self, B.class_traits(), expected)

        expected.extend(("lst", "y"))
        _py2to3.assertCountEqual(self, C.class_traits(), expected)
コード例 #11
0
ファイル: test_unittest_tools.py プロジェクト: Jfeng3/traits
    def test_assert_trait_changes_async_events(self):
        # Check access to the events after the with
        # block completes.
        thread_count = 10
        events_per_thread = 100

        class A(HasTraits):
            event = Event(Int)

        a = A()

        def thread_target(obj, count):
            "Fire obj.event 'count' times."
            for n in xrange(count):
                time.sleep(0.001)
                obj.event = n

        threads = [
            threading.Thread(target=thread_target, args=(a, events_per_thread))
            for _ in xrange(thread_count)
        ]

        expected_count = thread_count * events_per_thread
        with self.assertTraitChangesAsync(
            a, 'event', expected_count, timeout=60.0) as event_collector:
            for t in threads:
                t.start()

        for t in threads:
            t.join()

        _py2to3.assertCountEqual(
            self,
            event_collector.events,
            range(events_per_thread) * thread_count,
        )
コード例 #12
0
    def test_extended_notifiers_methods_failing(self):
        obj = ExtendedNotifiers()
        obj.fail = 1

        _py2to3.assertCountEqual(self, [0, 1, 2, 3, 4], obj.exceptions_from)
        self.assertEqual([(obj, 'fail', 0, 1)] * 5, self.exceptions)
コード例 #13
0
 def test_property_reset_traits(self):
     e = E()
     unresetable = e.reset_traits()
     _py2to3.assertCountEqual(self, unresetable, ['a', 'b'])
コード例 #14
0
    def test_dynamic_notifiers_methods_failing(self):
        obj = DynamicNotifiers()
        obj.fail = 1

        _py2to3.assertCountEqual(self, [0, 1, 2, 3, 4], obj.exceptions_from)
        self.assertEqual([(obj, "fail", 0, 1)] * 5, self.exceptions)
コード例 #15
0
    def test_extended_notifiers_methods_failing(self):
        obj = ExtendedNotifiers()
        obj.fail = 1

        _py2to3.assertCountEqual(self, [0, 1, 2, 3, 4], obj.exceptions_from)
        self.assertEqual([(obj, 'fail', 0, 1)]*5, self.exceptions)
コード例 #16
0
    def test_dynamic_notifiers_methods_failing(self):
        obj = DynamicNotifiers()
        obj.fail = 1

        _py2to3.assertCountEqual(self, [0, 1, 2, 3, 4], obj.exceptions_from)
        self.assertEqual([(obj, "fail", 0, 1)] * 5, self.exceptions)