OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 """Tests for the time elements implementation.""" | 3 """Tests for the time elements implementation.""" |
4 | 4 |
5 from __future__ import unicode_literals | 5 from __future__ import unicode_literals |
6 | 6 |
| 7 import decimal |
7 import unittest | 8 import unittest |
8 | 9 |
9 from dfdatetime import time_elements | 10 from dfdatetime import time_elements |
10 | 11 |
11 | 12 |
12 class TimeElementsTest(unittest.TestCase): | 13 class TimeElementsTest(unittest.TestCase): |
13 """Tests for the time elements.""" | 14 """Tests for the time elements.""" |
14 | 15 |
15 # pylint: disable=protected-access | 16 # pylint: disable=protected-access |
16 | 17 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 with self.assertRaises(ValueError): | 498 with self.assertRaises(ValueError): |
498 time_elements.TimeElementsInMilliseconds( | 499 time_elements.TimeElementsInMilliseconds( |
499 time_elements_tuple=(2010, 13, 12, 20, 6, 31, 1001)) | 500 time_elements_tuple=(2010, 13, 12, 20, 6, 31, 1001)) |
500 | 501 |
501 def testGetNormalizedTimestamp(self): | 502 def testGetNormalizedTimestamp(self): |
502 """Tests the _GetNormalizedTimestamp function.""" | 503 """Tests the _GetNormalizedTimestamp function.""" |
503 time_elements_object = time_elements.TimeElementsInMilliseconds( | 504 time_elements_object = time_elements.TimeElementsInMilliseconds( |
504 time_elements_tuple=(2010, 8, 12, 20, 6, 31, 429)) | 505 time_elements_tuple=(2010, 8, 12, 20, 6, 31, 429)) |
505 | 506 |
506 normalized_timestamp = time_elements_object._GetNormalizedTimestamp() | 507 normalized_timestamp = time_elements_object._GetNormalizedTimestamp() |
507 self.assertEqual(normalized_timestamp, 1281643591.429) | 508 self.assertEqual(normalized_timestamp, decimal.Decimal('1281643591.429')) |
508 | 509 |
509 time_elements_object = time_elements.TimeElementsInMilliseconds() | 510 time_elements_object = time_elements.TimeElementsInMilliseconds() |
510 | 511 |
511 normalized_timestamp = time_elements_object._GetNormalizedTimestamp() | 512 normalized_timestamp = time_elements_object._GetNormalizedTimestamp() |
512 self.assertIsNone(normalized_timestamp) | 513 self.assertIsNone(normalized_timestamp) |
513 | 514 |
514 # TODO: add tests for _CopyFromDateTimeValues | 515 # TODO: add tests for _CopyFromDateTimeValues |
515 | 516 |
516 def testCopyFromDateTimeString(self): | 517 def testCopyFromDateTimeString(self): |
517 """Tests the CopyFromDateTimeString function.""" | 518 """Tests the CopyFromDateTimeString function.""" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 with self.assertRaises(ValueError): | 753 with self.assertRaises(ValueError): |
753 time_elements.TimeElementsInMicroseconds( | 754 time_elements.TimeElementsInMicroseconds( |
754 time_elements_tuple=(2010, 13, 12, 20, 6, 31, 1001)) | 755 time_elements_tuple=(2010, 13, 12, 20, 6, 31, 1001)) |
755 | 756 |
756 def testGetNormalizedTimestamp(self): | 757 def testGetNormalizedTimestamp(self): |
757 """Tests the _GetNormalizedTimestamp function.""" | 758 """Tests the _GetNormalizedTimestamp function.""" |
758 time_elements_object = time_elements.TimeElementsInMicroseconds( | 759 time_elements_object = time_elements.TimeElementsInMicroseconds( |
759 time_elements_tuple=(2010, 8, 12, 20, 6, 31, 429876)) | 760 time_elements_tuple=(2010, 8, 12, 20, 6, 31, 429876)) |
760 | 761 |
761 normalized_timestamp = time_elements_object._GetNormalizedTimestamp() | 762 normalized_timestamp = time_elements_object._GetNormalizedTimestamp() |
762 self.assertEqual(normalized_timestamp, 1281643591.429876) | 763 self.assertEqual(normalized_timestamp, decimal.Decimal('1281643591.429876')) |
763 | 764 |
764 time_elements_object = time_elements.TimeElementsInMicroseconds() | 765 time_elements_object = time_elements.TimeElementsInMicroseconds() |
765 | 766 |
766 normalized_timestamp = time_elements_object._GetNormalizedTimestamp() | 767 normalized_timestamp = time_elements_object._GetNormalizedTimestamp() |
767 self.assertIsNone(normalized_timestamp) | 768 self.assertIsNone(normalized_timestamp) |
768 | 769 |
769 # TODO: add tests for _CopyFromDateTimeValues | 770 # TODO: add tests for _CopyFromDateTimeValues |
770 | 771 |
771 def testCopyFromDateTimeString(self): | 772 def testCopyFromDateTimeString(self): |
772 """Tests the CopyFromDateTimeString function.""" | 773 """Tests the CopyFromDateTimeString function.""" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 self.assertEqual(date_tuple, (2010, 8, 12)) | 978 self.assertEqual(date_tuple, (2010, 8, 12)) |
978 | 979 |
979 time_elements_object = time_elements.TimeElementsInMicroseconds() | 980 time_elements_object = time_elements.TimeElementsInMicroseconds() |
980 | 981 |
981 date_tuple = time_elements_object.GetDate() | 982 date_tuple = time_elements_object.GetDate() |
982 self.assertEqual(date_tuple, (None, None, None)) | 983 self.assertEqual(date_tuple, (None, None, None)) |
983 | 984 |
984 | 985 |
985 if __name__ == '__main__': | 986 if __name__ == '__main__': |
986 unittest.main() | 987 unittest.main() |
OLD | NEW |