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

PicklabilityTestCase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
dl 0
loc 18
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_return_value() 0 6 2
A test_exception() 0 6 2
A test_action() 0 3 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