Skip to content

Commit afb620b

Browse files
committed
inspect: Add basic unit tests.
Signed-off-by: Damien George <[email protected]>
1 parent b251c59 commit afb620b

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Diff for: python-stdlib/inspect/test_inspect.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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])

Diff for: tools/ci.sh

+1
Original file line numberDiff line numberDiff 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 \

0 commit comments

Comments
 (0)