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

Method test_user_command

Lib/test/test_tcl.py:560–625  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

558 self.assertEqual(self.passValue(values := List([Value(), "pad"])), expect)
559
560 def test_user_command(self):
561 result = None
562 def testfunc(arg):
563 nonlocal result
564 result = arg
565 return arg
566 self.interp.createcommand('testfunc', testfunc)
567 self.addCleanup(self.interp.tk.deletecommand, 'testfunc')
568 def check(value, expected1=None, expected2=None, *, eq=self.assertEqual):
569 expected = value
570 if self.wantobjects >= 2:
571 if expected2 is not None:
572 expected = expected2
573 expected_type = type(expected)
574 else:
575 if expected1 is not None:
576 expected = expected1
577 expected_type = str
578 nonlocal result
579 result = None
580 r = self.interp.call('testfunc', value)
581 self.assertIsInstance(result, expected_type)
582 eq(result, expected)
583 self.assertIsInstance(r, expected_type)
584 eq(r, expected)
585 def float_eq(actual, expected):
586 self.assertAlmostEqual(float(actual), expected,
587 delta=abs(expected) * 1e-10)
588
589 check(True, '1', 1)
590 check(False, '0', 0)
591 check('string')
592 check('string\xbd')
593 check('string\u20ac')
594 check('string\U0001f4bb')
595 if sys.platform != 'win32':
596 check('<\udce2\udc82\udcac>', '<\u20ac>', '<\u20ac>')
597 check('<\udced\udca0\udcbd\udced\udcb2\udcbb>', '<\U0001f4bb>', '<\U0001f4bb>')
598 check('')
599 check(b'string', 'string')
600 check(b'string\xe2\x82\xac', 'string\xe2\x82\xac')
601 check(b'string\xbd', 'string\xbd')
602 check(b'', '')
603 check('str\x00ing')
604 check('str\x00ing\xbd')
605 check('str\x00ing\u20ac')
606 check(b'str\x00ing', 'str\x00ing')
607 check(b'str\xc0\x80ing', 'str\xc0\x80ing')
608 check(b'str\xc0\x80ing\xe2\x82\xac', 'str\xc0\x80ing\xe2\x82\xac')
609 for i in self.get_integers():
610 check(i, str(i))
611 for f in (0.0, 1.0, -1.0):
612 check(f, repr(f))
613 for f in (1/3.0, sys.float_info.min, sys.float_info.max,
614 -sys.float_info.min, -sys.float_info.max):
615 check(f, eq=float_eq)
616 check(float('inf'), eq=float_eq)
617 check(-float('inf'), eq=float_eq)

Callers

nothing calls this directly

Calls 4

get_integersMethod · 0.95
strFunction · 0.85
addCleanupMethod · 0.80
checkFunction · 0.70

Tested by

no test coverage detected