MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_funcdef

Method test_funcdef

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

Source from the content-addressed store, hash-verified

467 self.assertEqual(ns['x'], (1, 2, 3, 4, 5))
468
469 def test_funcdef(self):
470 ### [decorators] 'def' NAME parameters ['->' test] ':' suite
471 ### decorator: '@' namedexpr_test NEWLINE
472 ### decorators: decorator+
473 ### parameters: '(' [typedargslist] ')'
474 ### typedargslist: ((tfpdef ['=' test] ',')*
475 ### ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef)
476 ### | tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
477 ### tfpdef: NAME [':' test]
478 ### varargslist: ((vfpdef ['=' test] ',')*
479 ### ('*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef)
480 ### | vfpdef ['=' test] (',' vfpdef ['=' test])* [','])
481 ### vfpdef: NAME
482 def f1(): pass
483 f1()
484 f1(*())
485 f1(*(), **{})
486 def f2(one_argument): pass
487 def f3(two, arguments): pass
488 self.assertEqual(f2.__code__.co_varnames, ('one_argument',))
489 self.assertEqual(f3.__code__.co_varnames, ('two', 'arguments'))
490 def a1(one_arg,): pass
491 def a2(two, args,): pass
492 def v0(*rest): pass
493 def v1(a, *rest): pass
494 def v2(a, b, *rest): pass
495
496 f1()
497 f2(1)
498 f2(1,)
499 f3(1, 2)
500 f3(1, 2,)
501 v0()
502 v0(1)
503 v0(1,)
504 v0(1,2)
505 v0(1,2,3,4,5,6,7,8,9,0)
506 v1(1)
507 v1(1,)
508 v1(1,2)
509 v1(1,2,3)
510 v1(1,2,3,4,5,6,7,8,9,0)
511 v2(1,2)
512 v2(1,2,3)
513 v2(1,2,3,4)
514 v2(1,2,3,4,5,6,7,8,9,0)
515
516 def d01(a=1): pass
517 d01()
518 d01(1)
519 d01(*(1,))
520 d01(*[] or [2])
521 d01(*() or (), *{} and (), **() or {})
522 d01(**{'a':2})
523 d01(**{'a':2} or {})
524 def d11(a, b=1): pass
525 d11(1)
526 d11(1, 2)

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected