annotate timedelta_tests.py @ 1:5fa902852779 default tip

add unit tests for timedelta function
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sat, 10 Jan 2009 04:09:22 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 import unittest
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3 from timedelta import timedelta
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4 from datetime import time
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 class TimeDeltaTests(unittest.TestCase):
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7 def testDeltaWrongArgumentOrder(self):
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8 t1 = time(microsecond=4)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9 t2 = time(microsecond=5)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10 expected = time(microsecond=1)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11 self.assert_(expected == timedelta(t2, t1))
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
12
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
13 def testDeltaMicroseconds(self):
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 t1 = time(microsecond=4)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15 t2 = time(microsecond=5)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
16 expected = time(microsecond=1)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17 self.assert_(expected == timedelta(t1, t2))
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
19 def testDeltaSeconds(self):
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
20 t1 = time(second=4)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
21 t2 = time(second=5)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
22 expected = time(second=1)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
23 self.assert_(expected == timedelta(t1, t2))
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
24
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
25 def testDeltaMinutes(self):
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
26 t1 = time(minute=4)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
27 t2 = time(minute=5)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
28 expected = time(minute=1)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
29 self.assert_(expected == timedelta(t1, t2))
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
30
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
31 def testDeltaHours(self):
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
32 t1 = time(hour=4)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
33 t2 = time(hour=5)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
34 expected = time(hour=1)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
35 self.assert_(expected == timedelta(t1, t2))
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
36
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
37 def testDeltaMixed(self):
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
38 t1 = time(11, 32, 10)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
39 t2 = time(11, 35, 30)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
40 expected = time(minute=3, second=20)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
41 self.assert_(expected == timedelta(t1, t2))
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
42
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
43 def testDeltaMax(self):
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
44 t1 = time(0, 0, 0, 0)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
45 t2 = time(23, 59, 59, 999999)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
46 expected = time(23, 59, 59, 999999)
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
47 self.assert_(expected == timedelta(t1, t2))
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
48
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
49 if __name__ == "__main__":
5fa902852779 add unit tests for timedelta function
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
50 unittest.main()