Browse Source

Unittest testing if pickling of exceptions works on the current installation, if this test doesn't pass please report it!

Ask Solem 16 years ago
parent
commit
b25dd22bbf
1 changed files with 49 additions and 0 deletions
  1. 49 0
      celery/tests/test_pickle.py

+ 49 - 0
celery/tests/test_pickle.py

@@ -0,0 +1,49 @@
+import unittest
+import pickle
+from django.http import Http404
+
+class RegularException(Exception):
+    pass
+
+
+class ArgOverrideException(Exception):
+    def __init__(self, message, status_code=10):
+        self.status_code = status_code
+        super(ArgOverrideException, self).__init__(message, status_code)
+
+
+class TestPickle(unittest.TestCase):
+
+    def test_pickle_regular_exception(self):
+
+        e = None
+        try:
+            raise RegularException("RegularException raised")
+        except RegularException, e:
+            pass
+
+        pickled = pickle.dumps({"exception": e})
+        unpickled = pickle.loads(pickled)
+        exception = unpickled.get("exception")
+        self.assertTrue(exception)
+        self.assertTrue(isinstance(exception, RegularException))
+        self.assertEquals(exception.args, ("RegularException raised", ))
+
+
+    def test_pickle_arg_override_exception(self):
+
+        e = None
+        try:
+            raise ArgOverrideException("ArgOverrideException raised",
+                    status_code=100)
+        except ArgOverrideException, e:
+            pass
+
+        pickled = pickle.dumps({"exception": e})
+        unpickled = pickle.loads(pickled)
+        exception = unpickled.get("exception")
+        self.assertTrue(exception)
+        self.assertTrue(isinstance(exception, ArgOverrideException))
+        self.assertEquals(exception.args, ("ArgOverrideException raised",
+                                          100))
+        self.assertEquals(exception.status_code, 100)