- Timestamp:
- 07/23/17 15:47:48 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
titan/mediathek/localhoster/lib/python2.7/test/test_functools.py
r40658 r40661 1 import copy2 1 import functools 3 2 import sys … … 26 25 """ return the signature of a partial object """ 27 26 return (part.func, part.args, part.keywords, part.__dict__) 28 29 class MyTuple(tuple):30 pass31 32 class BadTuple(tuple):33 def __add__(self, other):34 return list(self) + list(other)35 36 class MyDict(dict):37 pass38 27 39 28 class TestPartial(unittest.TestCase): … … 158 147 159 148 def test_pickle(self): 160 f = self.thetype(signature, ['asdf'], bar=[True])161 f.a ttr = []149 f = self.thetype(signature, 'asdf', bar=True) 150 f.add_something_to__dict__ = True 162 151 for proto in range(pickle.HIGHEST_PROTOCOL + 1): 163 152 f_copy = pickle.loads(pickle.dumps(f, proto)) 164 self.assertEqual(signature(f_copy), signature(f)) 165 166 def test_copy(self): 167 f = self.thetype(signature, ['asdf'], bar=[True]) 168 f.attr = [] 169 f_copy = copy.copy(f) 170 self.assertEqual(signature(f_copy), signature(f)) 171 self.assertIs(f_copy.attr, f.attr) 172 self.assertIs(f_copy.args, f.args) 173 self.assertIs(f_copy.keywords, f.keywords) 174 175 def test_deepcopy(self): 176 f = self.thetype(signature, ['asdf'], bar=[True]) 177 f.attr = [] 178 f_copy = copy.deepcopy(f) 179 self.assertEqual(signature(f_copy), signature(f)) 180 self.assertIsNot(f_copy.attr, f.attr) 181 self.assertIsNot(f_copy.args, f.args) 182 self.assertIsNot(f_copy.args[0], f.args[0]) 183 self.assertIsNot(f_copy.keywords, f.keywords) 184 self.assertIsNot(f_copy.keywords['bar'], f.keywords['bar']) 185 186 def test_setstate(self): 187 f = self.thetype(signature) 188 f.__setstate__((capture, (1,), dict(a=10), dict(attr=[]))) 189 self.assertEqual(signature(f), 190 (capture, (1,), dict(a=10), dict(attr=[]))) 191 self.assertEqual(f(2, b=20), ((1, 2), {'a': 10, 'b': 20})) 192 193 f.__setstate__((capture, (1,), dict(a=10), None)) 194 self.assertEqual(signature(f), (capture, (1,), dict(a=10), {})) 195 self.assertEqual(f(2, b=20), ((1, 2), {'a': 10, 'b': 20})) 196 197 f.__setstate__((capture, (1,), None, None)) 198 #self.assertEqual(signature(f), (capture, (1,), {}, {})) 199 self.assertEqual(f(2, b=20), ((1, 2), {'b': 20})) 200 self.assertEqual(f(2), ((1, 2), {})) 201 self.assertEqual(f(), ((1,), {})) 202 203 f.__setstate__((capture, (), {}, None)) 204 self.assertEqual(signature(f), (capture, (), {}, {})) 205 self.assertEqual(f(2, b=20), ((2,), {'b': 20})) 206 self.assertEqual(f(2), ((2,), {})) 207 self.assertEqual(f(), ((), {})) 208 209 def test_setstate_errors(self): 210 f = self.thetype(signature) 211 self.assertRaises(TypeError, f.__setstate__, (capture, (), {})) 212 self.assertRaises(TypeError, f.__setstate__, (capture, (), {}, {}, None)) 213 self.assertRaises(TypeError, f.__setstate__, [capture, (), {}, None]) 214 self.assertRaises(TypeError, f.__setstate__, (None, (), {}, None)) 215 self.assertRaises(TypeError, f.__setstate__, (capture, None, {}, None)) 216 self.assertRaises(TypeError, f.__setstate__, (capture, [], {}, None)) 217 self.assertRaises(TypeError, f.__setstate__, (capture, (), [], None)) 218 219 def test_setstate_subclasses(self): 220 f = self.thetype(signature) 221 f.__setstate__((capture, MyTuple((1,)), MyDict(a=10), None)) 222 s = signature(f) 223 self.assertEqual(s, (capture, (1,), dict(a=10), {})) 224 self.assertIs(type(s[1]), tuple) 225 self.assertIs(type(s[2]), dict) 226 r = f() 227 self.assertEqual(r, ((1,), {'a': 10})) 228 self.assertIs(type(r[0]), tuple) 229 self.assertIs(type(r[1]), dict) 230 231 f.__setstate__((capture, BadTuple((1,)), {}, None)) 232 s = signature(f) 233 self.assertEqual(s, (capture, (1,), {}, {})) 234 self.assertIs(type(s[1]), tuple) 235 r = f(2) 236 self.assertEqual(r, ((1, 2), {})) 237 self.assertIs(type(r[0]), tuple) 153 self.assertEqual(signature(f), signature(f_copy)) 238 154 239 155 # Issue 6083: Reference counting bug … … 252 168 253 169 f = self.thetype(object) 254 self.assertRaises( TypeError, f.__setstate__, BadSequence())170 self.assertRaises(SystemError, f.__setstate__, BadSequence()) 255 171 256 172 class PartialSubclass(functools.partial): … … 266 182 267 183 # the python version isn't picklable 268 test_pickle = None 269 test_setstate = None 270 test_setstate_errors = None 271 test_setstate_subclasses = None 272 test_setstate_refcount = None 273 274 # the python version isn't deepcopyable 275 test_deepcopy = None 184 test_pickle = test_setstate_refcount = None 276 185 277 186 # the python version isn't a type
Note: See TracChangeset
for help on using the changeset viewer.