Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/isodate/tests/test_pickle.py @ 2:6af9afd405e9 draft
"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author | shellac |
---|---|
date | Thu, 14 May 2020 14:56:58 -0400 |
parents | 26e78fe6e8c4 |
children |
comparison
equal
deleted
inserted
replaced
1:75ca89e9b81c | 2:6af9afd405e9 |
---|---|
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') |