|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
| 15 | +import pickle |
15 | 16 | import sys
|
16 | 17 | import traceback
|
17 | 18 |
|
18 | 19 | sys.path[0:0] = [""]
|
19 | 20 |
|
20 |
| -from pymongo.errors import (NotMasterError, |
| 21 | +from pymongo.errors import (BulkWriteError, |
| 22 | + EncryptionError, |
| 23 | + NotMasterError, |
21 | 24 | OperationFailure)
|
22 | 25 | from test import (PyMongoTestCase,
|
23 | 26 | unittest)
|
@@ -67,6 +70,37 @@ def test_unicode_strs_not_master_error(self):
|
67 | 70 | {"errmsg": u'unicode \U0001f40d'})
|
68 | 71 | self._test_unicode_strs(exc)
|
69 | 72 |
|
| 73 | + def assertPyMongoErrorEqual(self, exc1, exc2): |
| 74 | + self.assertEqual(exc1._message, exc2._message) |
| 75 | + self.assertEqual(exc1._error_labels, exc2._error_labels) |
| 76 | + self.assertEqual(exc1.args, exc2.args) |
| 77 | + self.assertEqual(str(exc1), str(exc2)) |
| 78 | + |
| 79 | + def assertOperationFailureEqual(self, exc1, exc2): |
| 80 | + self.assertPyMongoErrorEqual(exc1, exc2) |
| 81 | + self.assertEqual(exc1.code, exc2.code) |
| 82 | + self.assertEqual(exc1.details, exc2.details) |
| 83 | + self.assertEqual(exc1._max_wire_version, exc2._max_wire_version) |
| 84 | + |
| 85 | + def test_pickle_NotMasterError(self): |
| 86 | + exc = NotMasterError("not master test", {"errmsg": "error"}) |
| 87 | + self.assertPyMongoErrorEqual(exc, pickle.loads(pickle.dumps(exc))) |
| 88 | + |
| 89 | + def test_pickle_OperationFailure(self): |
| 90 | + exc = OperationFailure('error', code=5, details={}, max_wire_version=7) |
| 91 | + self.assertOperationFailureEqual(exc, pickle.loads(pickle.dumps(exc))) |
| 92 | + |
| 93 | + def test_pickle_BulkWriteError(self): |
| 94 | + exc = BulkWriteError({}) |
| 95 | + self.assertOperationFailureEqual(exc, pickle.loads(pickle.dumps(exc))) |
| 96 | + |
| 97 | + def test_pickle_EncryptionError(self): |
| 98 | + cause = OperationFailure('error', code=5, details={}, |
| 99 | + max_wire_version=7) |
| 100 | + exc = EncryptionError(cause) |
| 101 | + exc2 = pickle.loads(pickle.dumps(exc)) |
| 102 | + self.assertPyMongoErrorEqual(exc, exc2) |
| 103 | + self.assertOperationFailureEqual(cause, exc2.cause) |
70 | 104 |
|
71 | 105 |
|
72 | 106 | if __name__ == "__main__":
|
|
0 commit comments