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

Method test_funcdef

Lib/test/test_grammar.py:442–688  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

440 self.assertEqual(ns['x'], (1, 2, 3, 4, 5))
441
442 def test_funcdef(self):
443 ### [decorators] 'def' NAME parameters ['->' test] ':' suite
444 ### decorator: '@' namedexpr_test NEWLINE
445 ### decorators: decorator+
446 ### parameters: '(' [typedargslist] ')'
447 ### typedargslist: ((tfpdef ['=' test] ',')*
448 ### ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef)
449 ### | tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
450 ### tfpdef: NAME [':' test]
451 ### varargslist: ((vfpdef ['=' test] ',')*
452 ### ('*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef)
453 ### | vfpdef ['=' test] (',' vfpdef ['=' test])* [','])
454 ### vfpdef: NAME
455 def f1(): pass
456 f1()
457 f1(*())
458 f1(*(), **{})
459 def f2(one_argument): pass
460 def f3(two, arguments): pass
461 self.assertEqual(f2.__code__.co_varnames, ('one_argument',))
462 self.assertEqual(f3.__code__.co_varnames, ('two', 'arguments'))
463 def a1(one_arg,): pass
464 def a2(two, args,): pass
465 def v0(*rest): pass
466 def v1(a, *rest): pass
467 def v2(a, b, *rest): pass
468
469 f1()
470 f2(1)
471 f2(1,)
472 f3(1, 2)
473 f3(1, 2,)
474 v0()
475 v0(1)
476 v0(1,)
477 v0(1,2)
478 v0(1,2,3,4,5,6,7,8,9,0)
479 v1(1)
480 v1(1,)
481 v1(1,2)
482 v1(1,2,3)
483 v1(1,2,3,4,5,6,7,8,9,0)
484 v2(1,2)
485 v2(1,2,3)
486 v2(1,2,3,4)
487 v2(1,2,3,4,5,6,7,8,9,0)
488
489 def d01(a=1): pass
490 d01()
491 d01(1)
492 d01(*(1,))
493 d01(*[] or [2])
494 d01(*() or (), *{} and (), **() or {})
495 d01(**{'a':2})
496 d01(**{'a':2} or {})
497 def d11(a, b=1): pass
498 d11(1)
499 d11(1, 2)

Callers

nothing calls this directly

Calls 8

check_syntax_errorFunction · 0.90
f1Function · 0.85
f2Function · 0.85
strFunction · 0.85
fFunction · 0.70
assertEqualMethod · 0.45
failMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected