diff options
Diffstat (limited to 'Lib/test/test_datetime.py')
-rw-r--r-- | Lib/test/test_datetime.py | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py index 7c08f9e..8ac7160 100644 --- a/Lib/test/test_datetime.py +++ b/Lib/test/test_datetime.py @@ -851,29 +851,29 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase): def test_format(self): dt = self.theclass(2007, 9, 10) - self.assertEqual(format(dt, ''), str(dt)) + self.assertEqual(dt.__format__(''), str(dt)) # check that a derived class's __str__() gets called class A(self.theclass): def __str__(self): return 'A' a = A(2007, 9, 10) - self.assertEqual(format(a, ''), 'A') + self.assertEqual(a.__format__(''), 'A') # check that a derived class's strftime gets called class B(self.theclass): def strftime(self, format_spec): return 'B' b = B(2007, 9, 10) - self.assertEqual(format(b, ''), str(dt)) + self.assertEqual(b.__format__(''), str(dt)) for fmt in ["m:%m d:%d y:%y", "m:%m d:%d y:%y H:%H M:%M S:%S", "%z %Z", ]: - self.assertEqual(format(dt, fmt), dt.strftime(fmt)) - self.assertEqual(format(a, fmt), dt.strftime(fmt)) - self.assertEqual(format(b, fmt), 'B') + self.assertEqual(dt.__format__(fmt), dt.strftime(fmt)) + self.assertEqual(a.__format__(fmt), dt.strftime(fmt)) + self.assertEqual(b.__format__(fmt), 'B') def test_resolution_info(self): self.assert_(isinstance(self.theclass.min, self.theclass)) @@ -1178,31 +1178,29 @@ class TestDateTime(TestDate): def test_format(self): dt = self.theclass(2007, 9, 10, 4, 5, 1, 123) - self.assertEqual(format(dt, ''), str(dt)) + self.assertEqual(dt.__format__(''), str(dt)) # check that a derived class's __str__() gets called class A(self.theclass): def __str__(self): return 'A' a = A(2007, 9, 10, 4, 5, 1, 123) - self.assertEqual(format(a, ''), 'A') + self.assertEqual(a.__format__(''), 'A') # check that a derived class's strftime gets called class B(self.theclass): def strftime(self, format_spec): return 'B' b = B(2007, 9, 10, 4, 5, 1, 123) - self.assertEqual(format(b, ''), str(dt)) + self.assertEqual(b.__format__(''), str(dt)) for fmt in ["m:%m d:%d y:%y", "m:%m d:%d y:%y H:%H M:%M S:%S", "%z %Z", ]: - self.assertEqual(format(dt, fmt), dt.strftime(fmt)) - self.assertEqual(format(a, fmt), dt.strftime(fmt)) - self.assertEqual(format(b, fmt), 'B') - - + self.assertEqual(dt.__format__(fmt), dt.strftime(fmt)) + self.assertEqual(a.__format__(fmt), dt.strftime(fmt)) + self.assertEqual(b.__format__(fmt), 'B') def test_more_ctime(self): # Test fields that TestDate doesn't touch. @@ -1837,27 +1835,27 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase): def test_format(self): t = self.theclass(1, 2, 3, 4) - self.assertEqual(format(t, ''), str(t)) + self.assertEqual(t.__format__(''), str(t)) # check that a derived class's __str__() gets called class A(self.theclass): def __str__(self): return 'A' a = A(1, 2, 3, 4) - self.assertEqual(format(a, ''), 'A') + self.assertEqual(a.__format__(''), 'A') # check that a derived class's strftime gets called class B(self.theclass): def strftime(self, format_spec): return 'B' b = B(1, 2, 3, 4) - self.assertEqual(format(b, ''), str(t)) + self.assertEqual(b.__format__(''), str(t)) for fmt in ['%H %M %S', ]: - self.assertEqual(format(t, fmt), t.strftime(fmt)) - self.assertEqual(format(a, fmt), t.strftime(fmt)) - self.assertEqual(format(b, fmt), 'B') + self.assertEqual(t.__format__(fmt), t.strftime(fmt)) + self.assertEqual(a.__format__(fmt), t.strftime(fmt)) + self.assertEqual(b.__format__(fmt), 'B') def test_str(self): self.assertEqual(str(self.theclass(1, 2, 3, 4)), "01:02:03.000004") |