1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 from aria.utils import exceptions
24 class TestWrapIfNeeded(object):
26 def test_no_wrapping_required1(self):
27 e = JsonPickleableException1(_ARG1, _ARG2)
28 assert exceptions.wrap_if_needed(e) is e
30 def test_no_wrapping_required2(self):
31 e = JsonPickleableException1(arg1=_ARG1, arg2=_ARG2)
32 assert exceptions.wrap_if_needed(e) is e
34 def test_no_wrapping_required3(self):
35 e = JsonPickleableException2(arg1=_ARG1, arg2=_ARG2)
36 assert exceptions.wrap_if_needed(e) is e
38 def test_wrapping_required1(self):
39 e = NonJsonPickleableException(_ARG1, _ARG2)
40 wrapped_e = exceptions.wrap_if_needed(e)
41 wrapped_e = jsonpickle.loads(jsonpickle.dumps(wrapped_e))
42 assert isinstance(wrapped_e, exceptions._WrappedException)
43 assert wrapped_e.exception_type == type(e).__name__
44 assert wrapped_e.exception_str == str(e)
46 def test_wrapping_required2(self):
47 e = NonJsonPickleableException(arg1=_ARG1, arg2=_ARG2)
48 wrapped_e = exceptions.wrap_if_needed(e)
49 wrapped_e = jsonpickle.loads(jsonpickle.dumps(wrapped_e))
50 assert isinstance(wrapped_e, exceptions._WrappedException)
51 assert wrapped_e.exception_type == type(e).__name__
52 assert wrapped_e.exception_str == str(e)
55 class JsonPickleableException1(Exception):
56 def __init__(self, arg1, arg2):
57 super(JsonPickleableException1, self).__init__(arg1, arg2)
62 class JsonPickleableException2(Exception):
63 def __init__(self, arg1=None, arg2=None):
64 super(JsonPickleableException2, self).__init__()
69 class NonJsonPickleableException(Exception):
70 def __init__(self, arg1, arg2):
71 super(NonJsonPickleableException, self).__init__()