mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Implement the trunc builtin for PEP 3141
This commit is contained in:
parent
a62b45c95d
commit
86d8b3497f
2 changed files with 36 additions and 0 deletions
|
@ -1515,6 +1515,20 @@ class BuiltinTest(unittest.TestCase):
|
|||
raise ValueError
|
||||
self.assertRaises(ValueError, sum, BadSeq())
|
||||
|
||||
def test_trunc(self):
|
||||
class TestTrunc:
|
||||
def __trunc__(self):
|
||||
return 23
|
||||
|
||||
class TestNoTrunc:
|
||||
pass
|
||||
|
||||
self.assertEqual(trunc(TestTrunc()), 23)
|
||||
|
||||
self.assertRaises(TypeError, trunc)
|
||||
self.assertRaises(TypeError, trunc, 1, 2)
|
||||
self.assertRaises(TypeError, trunc, TestNoTrunc())
|
||||
|
||||
def test_tuple(self):
|
||||
self.assertEqual(tuple(()), ())
|
||||
t0_3 = (0, 1, 2, 3)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue