Implement the trunc builtin for PEP 3141

This commit is contained in:
Alex Martelli 2007-08-22 22:39:42 +00:00
parent a62b45c95d
commit 86d8b3497f
2 changed files with 36 additions and 0 deletions

View file

@ -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)