(ty)
| 5885 | return s |
| 5886 | |
| 5887 | def doit(ty): |
| 5888 | p_type = getattr(P, ty) |
| 5889 | c_type = getattr(C, ty) |
| 5890 | for attr in dir(p_type): |
| 5891 | if attr.startswith('_'): |
| 5892 | continue |
| 5893 | p_func = getattr(p_type, attr) |
| 5894 | c_func = getattr(c_type, attr) |
| 5895 | if inspect.isfunction(p_func): |
| 5896 | p_sig = inspect.signature(p_func) |
| 5897 | c_sig = inspect.signature(c_func) |
| 5898 | |
| 5899 | # parameter names: |
| 5900 | p_names = list(p_sig.parameters.keys()) |
| 5901 | c_names = [tr(x) for x in c_sig.parameters.keys()] |
| 5902 | |
| 5903 | self.assertEqual(c_names, p_names, |
| 5904 | msg="parameter name mismatch in %s" % p_func) |
| 5905 | |
| 5906 | p_kind = [x.kind for x in p_sig.parameters.values()] |
| 5907 | c_kind = [x.kind for x in c_sig.parameters.values()] |
| 5908 | |
| 5909 | # 'self' parameter: |
| 5910 | self.assertIs(p_kind[0], POS_KWD) |
| 5911 | self.assertIs(c_kind[0], POS) |
| 5912 | |
| 5913 | # remaining parameters: |
| 5914 | if ty == 'Decimal': |
| 5915 | self.assertEqual(c_kind[1:], p_kind[1:], |
| 5916 | msg="parameter kind mismatch in %s" % p_func) |
| 5917 | else: # Context methods are positional only in the C version. |
| 5918 | self.assertEqual(len(c_kind), len(p_kind), |
| 5919 | msg="parameter kind mismatch in %s" % p_func) |
| 5920 | |
| 5921 | # Run the function: |
| 5922 | args, kwds = mkargs(C, c_sig) |
| 5923 | try: |
| 5924 | getattr(c_type(9), attr)(*args, **kwds) |
| 5925 | except Exception: |
| 5926 | raise TestFailed("invalid signature for %s: %s %s" % (c_func, args, kwds)) |
| 5927 | |
| 5928 | args, kwds = mkargs(P, p_sig) |
| 5929 | try: |
| 5930 | getattr(p_type(9), attr)(*args, **kwds) |
| 5931 | except Exception: |
| 5932 | raise TestFailed("invalid signature for %s: %s %s" % (p_func, args, kwds)) |
| 5933 | |
| 5934 | doit('Decimal') |
| 5935 | doit('Context') |
nothing calls this directly
no test coverage detected