this repo has no description
1#!/usr/bin/env python3
2# Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com)
3import inspect
4import math
5import unittest
6
7
8class InspectModuleTest(unittest.TestCase):
9 def test_signature_with_function_returns_signature(self):
10 def foo(arg0, arg1):
11 pass
12
13 result = inspect.signature(foo)
14 self.assertEqual(str(result), "(arg0, arg1)")
15
16 def test_signature_with_classmethod_returns_signature(self):
17 class C:
18 @classmethod
19 def foo(cls, arg0, arg1):
20 pass
21
22 result = inspect.signature(C.foo)
23 self.assertEqual(str(result), "(arg0, arg1)")
24
25 def test_signature_with_dunder_call_returns_signature(self):
26 class C:
27 def __call__(self, arg0, arg1):
28 pass
29
30 instance = C()
31 result = inspect.signature(instance)
32 self.assertEqual(str(result), "(arg0, arg1)")
33
34 def test_signature_with_c_function_raises_value_error(self):
35 with self.assertRaises(ValueError):
36 inspect.signature(math.log)
37
38 def test_getmodule_with_frame_returns_module(self):
39 from types import ModuleType
40
41 frame = inspect.currentframe()
42 module = inspect.getmodule(frame)
43 self.assertIsInstance(module, ModuleType)
44 self.assertIs(module.__name__, __name__)
45
46
47if __name__ == "__main__":
48 unittest.main()