/usr/lib/python2.7/dist-packages/traits/tests/test_static_notifiers.py is in python-traits 4.5.0-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | ##############################################################################
# Copyright 2014 Enthought, Inc.
##############################################################################
""" Tests for the static notifiers. """
from traits.api import Float, HasTraits
from traits.testing.unittest_tools import unittest
from traits import trait_notifiers
calls_0 = []
class StaticNotifiers0(HasTraits):
ok = Float
def _ok_changed():
calls_0.append(True)
fail = Float
def _fail_changed():
raise Exception('error')
class StaticNotifiers1(HasTraits):
ok = Float
def _ok_changed(self):
if not hasattr(self, 'calls'):
self.calls = []
self.calls.append(True)
fail = Float
def _fail_changed(self):
raise Exception('error')
class StaticNotifiers2(HasTraits):
ok = Float
def _ok_changed(self, new):
if not hasattr(self, 'calls'):
self.calls = []
self.calls.append(new)
fail = Float
def _fail_changed(self, new):
raise Exception('error')
class StaticNotifiers3(HasTraits):
ok = Float
def _ok_changed(self, old, new):
if not hasattr(self, 'calls'):
self.calls = []
self.calls.append((old, new))
fail = Float
def _fail_changed(self, old, new):
raise Exception('error')
class StaticNotifiers4(HasTraits):
ok = Float
def _ok_changed(self, name, old, new):
if not hasattr(self, 'calls'):
self.calls = []
self.calls.append((name, old, new))
fail = Float
def _fail_changed(self, name, old, new):
raise Exception('error')
class TestNotifiers(unittest.TestCase):
""" Tests for the static notifiers, and the "anytrait" static notifiers.
"""
def setUp(self):
self.exceptions = []
trait_notifiers.push_exception_handler(self._handle_exception)
def tearDown(self):
trait_notifiers.pop_exception_handler()
def _handle_exception(self, obj, name, old, new):
self.exceptions.append((obj, name, old, new))
def test_static_notifiers_0(self):
obj = StaticNotifiers0(ok=2)
obj.ok = 3
self.assertEqual(len(calls_0), 2)
obj.fail = 1
self.assertEqual(self.exceptions, [(obj, 'fail', 0, 1)])
def test_static_notifiers_1(self):
obj = StaticNotifiers1(ok=2)
obj.ok = 3
self.assertEqual(len(obj.calls), 2)
obj.fail = 1
self.assertEqual(self.exceptions, [(obj, 'fail', 0, 1)])
def test_static_notifiers_2(self):
obj = StaticNotifiers2(ok=2)
obj.ok = 3
self.assertEqual(obj.calls, [2, 3])
obj.fail = 1
self.assertEqual(self.exceptions, [(obj, 'fail', 0, 1)])
def test_static_notifiers_3(self):
obj = StaticNotifiers3(ok=2)
obj.ok = 3
self.assertEqual(obj.calls, [(0, 2), (2, 3)])
obj.fail = 1
self.assertEqual(self.exceptions, [(obj, 'fail', 0, 1)])
def test_static_notifiers_4(self):
obj = StaticNotifiers4(ok=2)
obj.ok = 3
self.assertEqual(obj.calls, [('ok', 0, 2), ('ok', 2, 3)])
obj.fail = 1
self.assertEqual(self.exceptions, [(obj, 'fail', 0, 1)])
if __name__ == '__main__':
unittest.main()
|