pytilities.test.attributecollection

Package pytilities :: Package test :: Module attributecollection |
[hide private]
[frames] | no frames]

# Source Code for Module pytilities.test.attributecollection

     1  # Copyright (C) 2010 Tim Diels <limyreth@users.sourceforge.net>
     2  #
     3  # This file is part of pytilities.
     4  #
     5  # pytilities is free software: you can redistribute it and/or modify
     6  # it under the terms of the GNU General Public License as published by
     7  # the Free Software Foundation, either version 3 of the License, or
     8  # (at your option) any later version.
     9  #
    10  # pytilities is distributed in the hope that it will be useful,
    11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  # GNU General Public License for more details.
    14  #
    15  # You should have received a copy of the GNU General Public License
    16  # along with pytilities.  If not, see <http://www.gnu.org/licenses/>.
    17  #
    18
    19  __docformat__ = 'reStructuredText'
    20
    21  import unittest
    22
    23  from ..attributecollectionbase import AttributeCollectionBase
    24
    25 -class A(object):
    26 -    def __init__(self):
    27          self.__x = 5
    28
    29 -    def get(self):
    30          return self.__x
    31
    32 -class B(AttributeCollectionBase, A):
    33 -    def __init__(self):
    34          AttributeCollectionBase.__init__(self)
    35          A.__init__(self)
    36          self.y = 4
    37
    38 -class C(object):
    39 -    def __init__(self):
    40          self.z = 3
    41
    42 -class D(C, B):
    43 -    def __init__(self):
    44          C.__init__(self)
    45          B.__init__(self)
    46
    47 -class DisturbanceTestCase(unittest.TestCase):
    48      """Test whether or not basic inheritance is left unharmed by
    49      AttributeCollectionBase
    50      """
    51
    52 -    def test_direct_subclass(self):
    53          """A class that inherits from attrib base and another class
    54          """
    55          b = B()
    56          self.assertEquals(b.get(), 5)
    57
    58          b.x = 3
    59          self.assertEquals(b.x, 3)
    60
    61 -    def test_derived(self):
    62          """A class that inherits from a class that inherits from attrib base
    63          and another class
    64          """
    65          d = D()
    66
    67          self.assertEquals(d.z, 3)
    68          self.assertEquals(d.y, 4)
    69
    70          self.assertEquals(d.get(), 5)
    71
    72          d.x = 3
    73          self.assertEquals(d.x, 3)
    74