/usr/lib/python2.7/dist-packages/traits/tests/test_category.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 97 98 99 100 101 102 103 104 105 106 107 | #------------------------------------------------------------------------------
# Copyright (c) 2005, Enthought, Inc.
# 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!
#
# Author: David C. Morrill
# Description: <Traits component>
#------------------------------------------------------------------------------
from __future__ import absolute_import
from traits.testing.unittest_tools import unittest
from ..api import HasTraits, Category, Str
class Base(HasTraits):
y = Str("Base y")
z = Str("Base z")
class BaseExtra(Category, Base):
x = Str("BaseExtra x")
class BasePlus(Category, Base):
p = Str("BasePlus p")
# z = Str("BasePlus z") overrides not allowed.
class BasePlusPlus(BasePlus):
pp = Str("BasePlusPlus pp")
class CategoryTestCase(unittest.TestCase):
""" Test cases for traits category """
def setUp(self):
self.base = Base()
return
def test_base_category(self):
""" Base class with traits """
self.assertEqual(self.base.y, "Base y", msg="y != 'Base y'")
self.assertEqual(self.base.z, "Base z", msg="z != 'Base z'")
return
def test_extra_extension_category(self):
""" Base class extended with a category subclass """
self.assertEqual(self.base.x, "BaseExtra x", msg="x != 'BaseExtra x'")
return
def test_plus_extension_category(self):
""" Base class extended with two category subclasses """
self.assertEqual(self.base.x, "BaseExtra x", msg="x != 'BaseExtra x'")
self.assertEqual(self.base.p, "BasePlus p", msg="p != 'BasePlus p'")
return
def test_subclass_extension_category(self):
""" Category subclass does not extend base class.
This test demonstrates that traits allows subclassing of a category
class, but that the traits from the subclass are not actually added
to the base class of the Category.
Seems like the declaration of the subclass (BasePlusPlus) should fail.
"""
try:
x = self.base.pp
self.fail(msg="base.pp should have thrown AttributeError "
"as Category subclassing is not supported.")
except AttributeError:
pass
basepp = BasePlusPlus()
return
def test_subclass_instance_category(self):
""" Category subclass instantiation not supported.
This test demonstrates that traits allows subclassing of a category
class, that subclass can be instantiated, but the traits of the parent
class are not inherited.
Seems like the declaration of the subclass (BasePlusPlus) should fail.
"""
bpp = BasePlusPlus()
self.assertEqual(bpp.pp, "BasePlusPlus pp",
msg="pp != 'BasePlusPlus pp'")
try:
self.assertEqual(bpp.p, "BasePlus p", msg="p != 'BasePlus p'")
self.fail(msg="bpp.p should have thrown SystemError as "
"instantiating a subclass of a category is not "
"supported.")
except SystemError:
pass
return
#
# support running this test individually, from the command-line as a script
#
if __name__ == '__main__':
unittest.main()
#### EOF ######################################################################
|