/usr/lib/python2.7/dist-packages/traits/tests/test_abc.py is in python-traits 4.6.0-1.
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 | """ Test the ABC functionality.
"""
import abc
import warnings
from traits.testing.unittest_tools import unittest
from ..api import ABCHasTraits, ABCMetaHasTraits, HasTraits, Int, Float
class TestNew(unittest.TestCase):
""" Test that __new__ works correctly.
"""
def setUp(self):
self.old_filters = warnings.filters[:]
warnings.simplefilter('error', DeprecationWarning)
def tearDown(self):
warnings.filters[:] = self.old_filters
def test_new(self):
# Should not raise DeprecationWarning.
HasTraits(x=10)
class AbstractFoo(ABCHasTraits):
x = Int(10)
y = Float(20.0)
@abc.abstractmethod
def foo(self):
raise NotImplementedError()
@abc.abstractproperty
def bar(self):
raise NotImplementedError()
class ConcreteFoo(AbstractFoo):
def foo(self):
return 'foo'
@property
def bar(self):
return 'bar'
class FooLike(HasTraits):
x = Int(10)
y = Float(20.0)
def foo(self):
return 'foo'
@property
def bar(self):
return 'bar'
AbstractFoo.register(FooLike)
class AbstractBar(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def bar(self):
raise NotImplementedError()
class TestABC(unittest.TestCase):
def test_basic_abc(self):
self.assertRaises(TypeError, AbstractFoo)
concrete = ConcreteFoo()
self.assertEqual(concrete.foo(), 'foo')
self.assertEqual(concrete.bar, 'bar')
self.assertEqual(concrete.x, 10)
self.assertEqual(concrete.y, 20.0)
self.assertTrue(isinstance(concrete, AbstractFoo))
def test_registered(self):
foolike = FooLike()
self.assertTrue(isinstance(foolike, AbstractFoo))
def test_post_hoc_mixing(self):
class TraitedBar(HasTraits, AbstractBar):
__metaclass__ = ABCMetaHasTraits
x = Int(10)
def bar(self):
return 'bar'
traited = TraitedBar()
self.assertTrue(isinstance(traited, AbstractBar))
self.assertEqual(traited.x, 10)
|