UnpicklableReturnValue.do_execute()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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