Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_inspect.TestPredicates Class Reference
Inheritance diagram for test.test_inspect.TestPredicates:
Inheritance graph
[legend]
Collaboration diagram for test.test_inspect.TestPredicates:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_sixteen
def test_excluding_predicates
def test_isroutine
def test_isclass
def test_get_slot_members
def test_isabstract
def istest

Static Public Attributes

tuple predicates

Detailed Description

Definition at line 71 of file test_inspect.py.


Member Function Documentation

def test.test_inspect.IsTestBase.istest (   self,
  predicate,
  exp 
) [inherited]

Definition at line 57 of file test_inspect.py.

00057 
00058     def istest(self, predicate, exp):
00059         obj = eval(exp)
00060         self.assertTrue(predicate(obj), '%s(%s)' % (predicate.__name__, exp))
00061 
00062         for other in self.predicates - set([predicate]):
00063             if predicate == inspect.isgeneratorfunction and\
00064                other == inspect.isfunction:
00065                 continue
00066             self.assertFalse(other(obj), 'not %s(%s)' % (other.__name__, exp))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 81 of file test_inspect.py.

00081 
00082     def test_excluding_predicates(self):
00083         self.istest(inspect.isbuiltin, 'sys.exit')
00084         self.istest(inspect.isbuiltin, '[].append')
00085         self.istest(inspect.iscode, 'mod.spam.__code__')
00086         self.istest(inspect.isframe, 'tb.tb_frame')
00087         self.istest(inspect.isfunction, 'mod.spam')
00088         self.istest(inspect.isfunction, 'mod.StupidGit.abuse')
00089         self.istest(inspect.ismethod, 'git.argue')
00090         self.istest(inspect.ismodule, 'mod')
00091         self.istest(inspect.istraceback, 'tb')
00092         self.istest(inspect.isdatadescriptor, 'collections.defaultdict.default_factory')
00093         self.istest(inspect.isgenerator, '(x for x in range(2))')
00094         self.istest(inspect.isgeneratorfunction, 'generator_function_example')
00095         if hasattr(types, 'GetSetDescriptorType'):
00096             self.istest(inspect.isgetsetdescriptor,
00097                         'type(tb.tb_frame).f_locals')
00098         else:
00099             self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals))
00100         if hasattr(types, 'MemberDescriptorType'):
00101             self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days')
00102         else:
00103             self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))

Here is the call graph for this function:

Definition at line 117 of file test_inspect.py.

00117 
00118     def test_get_slot_members(self):
00119         class C(object):
00120             __slots__ = ("a", "b")
00121 
00122         x = C()
00123         x.a = 42
00124         members = dict(inspect.getmembers(x))
00125         self.assertIn('a', members)
00126         self.assertNotIn('b', members)

Here is the call graph for this function:

Definition at line 127 of file test_inspect.py.

00127 
00128     def test_isabstract(self):
00129         from abc import ABCMeta, abstractmethod
00130 
00131         class AbstractClassExample(metaclass=ABCMeta):
00132 
00133             @abstractmethod
00134             def foo(self):
00135                 pass
00136 
00137         class ClassExample(AbstractClassExample):
00138             def foo(self):
00139                 pass
00140 
00141         a = ClassExample()
00142 
00143         # Test general behaviour.
00144         self.assertTrue(inspect.isabstract(AbstractClassExample))
00145         self.assertFalse(inspect.isabstract(ClassExample))
00146         self.assertFalse(inspect.isabstract(a))
00147         self.assertFalse(inspect.isabstract(int))
00148         self.assertFalse(inspect.isabstract(5))
00149 

Definition at line 108 of file test_inspect.py.

00108 
00109     def test_isclass(self):
00110         self.istest(inspect.isclass, 'mod.StupidGit')
00111         self.assertTrue(inspect.isclass(list))
00112 
00113         class CustomGetattr(object):
00114             def __getattr__(self, attr):
00115                 return None
00116         self.assertFalse(inspect.isclass(CustomGetattr()))

Here is the call graph for this function:

Definition at line 104 of file test_inspect.py.

00104 
00105     def test_isroutine(self):
00106         self.assertTrue(inspect.isroutine(mod.spam))
00107         self.assertTrue(inspect.isroutine([].count))

Here is the call graph for this function:

Definition at line 72 of file test_inspect.py.

00072 
00073     def test_sixteen(self):
00074         count = len([x for x in dir(inspect) if x.startswith('is')])
00075         # This test is here for remember you to update Doc/library/inspect.rst
00076         # which claims there are 16 such functions
00077         expected = 16
00078         err_msg = "There are %d (not %d) is* functions" % (count, expected)
00079         self.assertEqual(count, expected, err_msg)
00080 

Here is the call graph for this function:


Member Data Documentation

tuple test.test_inspect.IsTestBase.predicates [static, inherited]
Initial value:
set([inspect.isbuiltin, inspect.isclass, inspect.iscode,
                      inspect.isframe, inspect.isfunction, inspect.ismethod,
                      inspect.ismodule, inspect.istraceback,
                      inspect.isgenerator, inspect.isgeneratorfunction])

Definition at line 52 of file test_inspect.py.


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