Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(67147)

Side by Side Diff: Lib/test/datetimetester.py

Issue 17267: datetime.time support for '+' and 'now'
Patch Set: Created 6 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 """Test date/time type. 1 """Test date/time type.
2 2
3 See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases 3 See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases
4 """ 4 """
5 5
6 import sys 6 import sys
7 import pickle 7 import pickle
8 import unittest 8 import unittest
9 9
10 from operator import lt, le, gt, ge, eq, ne, truediv, floordiv, mod 10 from operator import lt, le, gt, ge, eq, ne, truediv, floordiv, mod
(...skipping 2311 matching lines...) Expand 10 before | Expand all | Expand 10 after
2322 self.assertEqual(dt2.extra, 7) 2322 self.assertEqual(dt2.extra, 7)
2323 self.assertEqual(dt1.isoformat(), dt2.isoformat()) 2323 self.assertEqual(dt1.isoformat(), dt2.isoformat())
2324 self.assertEqual(dt2.newmeth(-7), dt1.hour + dt1.second - 7) 2324 self.assertEqual(dt2.newmeth(-7), dt1.hour + dt1.second - 7)
2325 2325
2326 def test_backdoor_resistance(self): 2326 def test_backdoor_resistance(self):
2327 # see TestDate.test_backdoor_resistance(). 2327 # see TestDate.test_backdoor_resistance().
2328 base = '2:59.0' 2328 base = '2:59.0'
2329 for hour_byte in ' ', '9', chr(24), '\xff': 2329 for hour_byte in ' ', '9', chr(24), '\xff':
2330 self.assertRaises(TypeError, self.theclass, 2330 self.assertRaises(TypeError, self.theclass,
2331 hour_byte + base[1:]) 2331 hour_byte + base[1:])
2332
2333 def test_computations(self):
2334 a = self.theclass(0, 0, 0)
2335 b = self.theclass(23, 59)
2336
2337 minute = timedelta(minutes=1)
2338 hour = timedelta(hours=1)
2339 week = timedelta(days=7)
2340 self.assertEqual(a + minute, self.theclass(0, 1, 0))
2341 self.assertEqual(b + minute + minute, self.theclass(0, 1))
2342 self.assertEqual(b + minute, self.theclass(0, 0))
2343 self.assertEqual(a + week, self.theclass(0))
2344 self.assertEqual(a + week, self.theclass(0))
2345 self.assertEqual(b + hour * 12, self.theclass(11, 59))
2346
2332 2347
2333 # A mixin for classes with a tzinfo= argument. Subclasses must define 2348 # A mixin for classes with a tzinfo= argument. Subclasses must define
2334 # theclass as a class atribute, and theclass(1, 1, 1, tzinfo=whatever) 2349 # theclass as a class atribute, and theclass(1, 1, 1, tzinfo=whatever)
2335 # must be legit (which is true for time and datetime). 2350 # must be legit (which is true for time and datetime).
2336 class TZInfoBase: 2351 class TZInfoBase:
2337 2352
2338 def test_argument_passing(self): 2353 def test_argument_passing(self):
2339 cls = self.theclass 2354 cls = self.theclass
2340 # A datetime passes itself on, a time passes None. 2355 # A datetime passes itself on, a time passes None.
2341 class introspective(tzinfo): 2356 class introspective(tzinfo):
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
3760 datetime_sc = SubclassDatetime(as_datetime.year, as_datetime.month, 3775 datetime_sc = SubclassDatetime(as_datetime.year, as_datetime.month,
3761 as_date.day, 0, 0, 0) 3776 as_date.day, 0, 0, 0)
3762 self.assertEqual(as_datetime, datetime_sc) 3777 self.assertEqual(as_datetime, datetime_sc)
3763 self.assertEqual(datetime_sc, as_datetime) 3778 self.assertEqual(datetime_sc, as_datetime)
3764 3779
3765 def test_main(): 3780 def test_main():
3766 support.run_unittest(__name__) 3781 support.run_unittest(__name__)
3767 3782
3768 if __name__ == "__main__": 3783 if __name__ == "__main__":
3769 test_main() 3784 test_main()
OLDNEW
« no previous file with comments | « Lib/datetime.py ('k') | Modules/_datetimemodule.c » ('j') | Modules/_datetimemodule.c » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+