Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_collections.ABCTestCase Class Reference
Inheritance diagram for test.test_collections.ABCTestCase:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def validate_abstract_methods
def validate_isinstance
def validate_comparison

Public Attributes

 right_side

Detailed Description

Definition at line 335 of file test_collections.py.


Member Function Documentation

Definition at line 337 of file test_collections.py.

00337 
00338     def validate_abstract_methods(self, abc, *names):
00339         methodstubs = dict.fromkeys(names, lambda s, *args: 0)
00340 
00341         # everything should work will all required methods are present
00342         C = type('C', (abc,), methodstubs)
00343         C()
00344 
00345         # instantiation should fail if a required method is missing
00346         for name in names:
00347             stubs = methodstubs.copy()
00348             del stubs[name]
00349             C = type('C', (abc,), stubs)
00350             self.assertRaises(TypeError, C, name)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 363 of file test_collections.py.

00363 
00364     def validate_comparison(self, instance):
00365         ops = ['lt', 'gt', 'le', 'ge', 'ne', 'or', 'and', 'xor', 'sub']
00366         operators = {}
00367         for op in ops:
00368             name = '__' + op + '__'
00369             operators[name] = getattr(operator, name)
00370 
00371         class Other:
00372             def __init__(self):
00373                 self.right_side = False
00374             def __eq__(self, other):
00375                 self.right_side = True
00376                 return True
00377             __lt__ = __eq__
00378             __gt__ = __eq__
00379             __le__ = __eq__
00380             __ge__ = __eq__
00381             __ne__ = __eq__
00382             __ror__ = __eq__
00383             __rand__ = __eq__
00384             __rxor__ = __eq__
00385             __rsub__ = __eq__
00386 
00387         for name, op in operators.items():
00388             if not hasattr(instance, name):
00389                 continue
00390             other = Other()
00391             op(instance, other)
00392             self.assertTrue(other.right_side,'Right side not called for %s.%s'
00393                             % (type(instance), name))

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_collections.ABCTestCase.validate_isinstance (   self,
  abc,
  name 
)

Definition at line 351 of file test_collections.py.

00351 
00352     def validate_isinstance(self, abc, name):
00353         stub = lambda s, *args: 0
00354 
00355         C = type('C', (object,), {'__hash__': None})
00356         setattr(C, name, stub)
00357         self.assertIsInstance(C(), abc)
00358         self.assertTrue(issubclass(C, abc))
00359 
00360         C = type('C', (object,), {'__hash__': None})
00361         self.assertNotIsInstance(C(), abc)
00362         self.assertFalse(issubclass(C, abc))

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 372 of file test_collections.py.


The documentation for this class was generated from the following file: