MCPcopy Index your code
hub / github.com/python/cpython / test_unused_param

Method test_unused_param

Lib/test/test_clinic.py:2680–2716  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2678 self.expect_failure(block, err, lineno=2)
2679
2680 def test_unused_param(self):
2681 block = self.parse("""
2682 module foo
2683 foo.func
2684 fn: object
2685 k: float
2686 i: float(unused=True)
2687 /
2688 *
2689 flag: bool(unused=True) = False
2690 """)
2691 sig = block.signatures[1] # Function index == 1
2692 params = sig.parameters
2693 conv = lambda fn: params[fn].converter
2694 dataset = (
2695 {"name": "fn", "unused": False},
2696 {"name": "k", "unused": False},
2697 {"name": "i", "unused": True},
2698 {"name": "flag", "unused": True},
2699 )
2700 for param in dataset:
2701 name, unused = param.values()
2702 with self.subTest(name=name, unused=unused):
2703 p = conv(name)
2704 # Verify that the unused flag is parsed correctly.
2705 self.assertEqual(unused, p.unused)
2706
2707 # Now, check that we'll produce correct code.
2708 decl = p.simple_declaration(in_parser=False)
2709 if unused:
2710 self.assertIn("Py_UNUSED", decl)
2711 else:
2712 self.assertNotIn("Py_UNUSED", decl)
2713
2714 # Make sure the Py_UNUSED macro is not used in the parser body.
2715 parser_decl = p.simple_declaration(in_parser=True)
2716 self.assertNotIn("Py_UNUSED", parser_decl)
2717
2718 def test_scaffolding(self):
2719 # test repr on special values

Callers

nothing calls this directly

Calls 8

parseMethod · 0.95
convFunction · 0.85
simple_declarationMethod · 0.80
assertInMethod · 0.80
assertNotInMethod · 0.80
valuesMethod · 0.45
subTestMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected