comparison env/lib/python3.9/site-packages/isodate/tests/test_pickle.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import unittest
2
3 from six.moves import cPickle as pickle
4
5 import isodate
6
7
8 class TestPickle(unittest.TestCase):
9 '''
10 A test case template to parse an ISO datetime string into a
11 datetime object.
12 '''
13
14 def test_pickle_datetime(self):
15 '''
16 Parse an ISO datetime string and compare it to the expected value.
17 '''
18 dti = isodate.parse_datetime('2012-10-26T09:33+00:00')
19 for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
20 pikl = pickle.dumps(dti, proto)
21 self.assertEqual(dti, pickle.loads(pikl),
22 "pickle proto %d failed" % proto)
23
24 def test_pickle_duration(self):
25 '''
26 Pickle / unpickle duration objects.
27 '''
28 from isodate.duration import Duration
29 dur = Duration()
30 failed = []
31 for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
32 try:
33 pikl = pickle.dumps(dur, proto)
34 if dur != pickle.loads(pikl):
35 raise Exception("not equal")
36 except Exception as e:
37 failed.append("pickle proto %d failed (%s)" % (proto, repr(e)))
38 self.assertEqual(len(failed), 0, "pickle protos failed: %s" %
39 str(failed))
40
41 def test_pickle_utc(self):
42 '''
43 isodate.UTC objects remain the same after pickling.
44 '''
45 self.assertTrue(isodate.UTC is pickle.loads(pickle.dumps(isodate.UTC)))
46
47
48 def test_suite():
49 '''
50 Construct a TestSuite instance for all test cases.
51 '''
52 suite = unittest.TestSuite()
53 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestPickle))
54 return suite
55
56
57 # load_tests Protocol
58 def load_tests(loader, tests, pattern):
59 return test_suite()
60
61
62 if __name__ == '__main__':
63 unittest.main(defaultTest='test_suite')