File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ import inspect
2+ import unittest
3+
4+
5+ def fun ():
6+ return 1
7+
8+
9+ def gen ():
10+ yield 1
11+
12+
13+ class Class :
14+ def meth (self ):
15+ pass
16+
17+
18+ entities = (
19+ fun ,
20+ gen ,
21+ gen (),
22+ Class ,
23+ Class .meth ,
24+ Class ().meth ,
25+ inspect ,
26+ )
27+
28+
29+ class TestInspect (unittest .TestCase ):
30+ def _test_is_helper (self , f , * entities_true ):
31+ for entity in entities :
32+ result = f (entity )
33+ if entity in entities_true :
34+ self .assertTrue (result )
35+ else :
36+ self .assertFalse (result )
37+
38+ def test_isfunction (self ):
39+ self ._test_is_helper (inspect .isfunction , entities [0 ], entities [4 ])
40+
41+ def test_isgeneratorfunction (self ):
42+ self ._test_is_helper (inspect .isgeneratorfunction , entities [1 ])
43+
44+ def test_isgenerator (self ):
45+ self ._test_is_helper (inspect .isgenerator , entities [2 ])
46+
47+ def test_ismethod (self ):
48+ self ._test_is_helper (inspect .ismethod , entities [5 ])
49+
50+ def test_isclass (self ):
51+ self ._test_is_helper (inspect .isclass , entities [3 ])
52+
53+ def test_ismodule (self ):
54+ self ._test_is_helper (inspect .ismodule , entities [6 ])
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ function ci_package_tests_run {
8686 python-stdlib/datetime \
8787 python-stdlib/fnmatch \
8888 python-stdlib/hashlib \
89+ python-stdlib/inspect \
8990 python-stdlib/pathlib \
9091 python-stdlib/quopri \
9192 python-stdlib/shutil \
You can’t perform that action at this time.
0 commit comments