Completed
Push — master ( 2ae69e...39840a )
by Vincent
01:14
created

PicklabilityTestCase.test_return_value()   A

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
1
# coding: utf8
2
3
# Copyright 2013-2015 Vincent Jacques <[email protected]>
4
5
from __future__ import division, absolute_import, print_function
6
7
import pickle
8
import unittest
9
import sys
10
import tempfile
11
12
from ActionTree import *
13
from . import *
14
15
16
class Unpicklable(object):
17
    def __reduce__(self):
18
        raise pickle.PicklingError
19
20
21
unpicklable = Unpicklable()
22
23
24
class UnpicklableReturnValue(Action):
25
    def do_execute(self):
26
        return unpicklable
27
28
29
class UnpicklableException(Action):
30
    def do_execute(self):
31
        raise Exception(unpicklable)
32
33
34
class PicklabilityTestCase(ActionTreeTestCase):
35
    def test_action(self):
36
        with self.assertRaises(pickle.PicklingError):
37
            execute(self._action(unpicklable))
38
39
    def test_return_value(self):
40
        with self.assertRaises(pickle.PicklingError):
41
            # DO NOT use self._action(return_value=unpicklable)
42
            # because the *Action* would be unpicklable and we're testing what happens
43
            # when the *return value* is unpicklable
44
            execute(UnpicklableReturnValue("x"))
45
46
    def test_exception(self):
47
        with self.assertRaises(pickle.PicklingError):
48
            # DO NOT use self._action(return_value=unpicklable)
49
            # because the *Action* would be unpicklable and we're testing what happens
50
            # when the *exception* is unpicklable
51
            execute(UnpicklableException("x"))
52