[Python-checkins] cpython (2.7): Rename class attribute "thetype" to "partial" in functools.partial tests

serhiy.storchaka python-checkins at python.org
Sun Jun 12 08:53:31 EDT 2016


https://hg.python.org/cpython/rev/f78be09fbf1a
changeset: 101943:f78be09fbf1a
branch: 2.7
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Jun 12 15:43:57 2016 +0300
summary:
 Rename class attribute "thetype" to "partial" in functools.partial tests
for consistency with Python 3.
files:
 Lib/test/test_functools.py | 68 +++++++++++++-------------
 1 files changed, 34 insertions(+), 34 deletions(-)
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -38,17 +38,17 @@
 
 class TestPartial(unittest.TestCase):
 
- thetype = functools.partial
+ partial = functools.partial
 
 def test_basic_examples(self):
- p = self.thetype(capture, 1, 2, a=10, b=20)
+ p = self.partial(capture, 1, 2, a=10, b=20)
 self.assertEqual(p(3, 4, b=30, c=40),
 ((1, 2, 3, 4), dict(a=10, b=30, c=40)))
- p = self.thetype(map, lambda x: x*10)
+ p = self.partial(map, lambda x: x*10)
 self.assertEqual(p([1,2,3,4]), [10, 20, 30, 40])
 
 def test_attributes(self):
- p = self.thetype(capture, 1, 2, a=10, b=20)
+ p = self.partial(capture, 1, 2, a=10, b=20)
 # attributes should be readable
 self.assertEqual(p.func, capture)
 self.assertEqual(p.args, (1, 2))
@@ -58,7 +58,7 @@
 self.assertRaises(TypeError, setattr, p, 'args', (1, 2))
 self.assertRaises(TypeError, setattr, p, 'keywords', dict(a=1, b=2))
 
- p = self.thetype(hex)
+ p = self.partial(hex)
 try:
 del p.__dict__
 except TypeError:
@@ -67,9 +67,9 @@
 self.fail('partial object allowed __dict__ to be deleted')
 
 def test_argument_checking(self):
- self.assertRaises(TypeError, self.thetype) # need at least a func arg
+ self.assertRaises(TypeError, self.partial) # need at least a func arg
 try:
- self.thetype(2)()
+ self.partial(2)()
 except TypeError:
 pass
 else:
@@ -80,7 +80,7 @@
 def func(a=10, b=20):
 return a
 d = {'a':3}
- p = self.thetype(func, a=5)
+ p = self.partial(func, a=5)
 self.assertEqual(p(**d), 3)
 self.assertEqual(d, {'a':3})
 p(b=7)
@@ -89,21 +89,21 @@
 def test_arg_combinations(self):
 # exercise special code paths for zero args in either partial
 # object or the caller
- p = self.thetype(capture)
+ p = self.partial(capture)
 self.assertEqual(p(), ((), {}))
 self.assertEqual(p(1,2), ((1,2), {}))
- p = self.thetype(capture, 1, 2)
+ p = self.partial(capture, 1, 2)
 self.assertEqual(p(), ((1,2), {}))
 self.assertEqual(p(3,4), ((1,2,3,4), {}))
 
 def test_kw_combinations(self):
 # exercise special code paths for no keyword args in
 # either the partial object or the caller
- p = self.thetype(capture)
+ p = self.partial(capture)
 self.assertEqual(p.keywords, {})
 self.assertEqual(p(), ((), {}))
 self.assertEqual(p(a=1), ((), {'a':1}))
- p = self.thetype(capture, a=1)
+ p = self.partial(capture, a=1)
 self.assertEqual(p.keywords, {'a':1})
 self.assertEqual(p(), ((), {'a':1}))
 self.assertEqual(p(b=2), ((), {'a':1, 'b':2}))
@@ -113,7 +113,7 @@
 def test_positional(self):
 # make sure positional arguments are captured correctly
 for args in [(), (0,), (0,1), (0,1,2), (0,1,2,3)]:
- p = self.thetype(capture, *args)
+ p = self.partial(capture, *args)
 expected = args + ('x',)
 got, empty = p('x')
 self.assertTrue(expected == got and empty == {})
@@ -121,14 +121,14 @@
 def test_keyword(self):
 # make sure keyword arguments are captured correctly
 for a in ['a', 0, None, 3.5]:
- p = self.thetype(capture, a=a)
+ p = self.partial(capture, a=a)
 expected = {'a':a,'x':None}
 empty, got = p(x=None)
 self.assertTrue(expected == got and empty == ())
 
 def test_no_side_effects(self):
 # make sure there are no side effects that affect subsequent calls
- p = self.thetype(capture, 0, a=1)
+ p = self.partial(capture, 0, a=1)
 args1, kw1 = p(1, b=2)
 self.assertTrue(args1 == (0,1) and kw1 == {'a':1,'b':2})
 args2, kw2 = p()
@@ -137,13 +137,13 @@
 def test_error_propagation(self):
 def f(x, y):
 x // y
- self.assertRaises(ZeroDivisionError, self.thetype(f, 1, 0))
- self.assertRaises(ZeroDivisionError, self.thetype(f, 1), 0)
- self.assertRaises(ZeroDivisionError, self.thetype(f), 1, 0)
- self.assertRaises(ZeroDivisionError, self.thetype(f, y=0), 1)
+ self.assertRaises(ZeroDivisionError, self.partial(f, 1, 0))
+ self.assertRaises(ZeroDivisionError, self.partial(f, 1), 0)
+ self.assertRaises(ZeroDivisionError, self.partial(f), 1, 0)
+ self.assertRaises(ZeroDivisionError, self.partial(f, y=0), 1)
 
 def test_weakref(self):
- f = self.thetype(int, base=16)
+ f = self.partial(int, base=16)
 p = proxy(f)
 self.assertEqual(f.func, p.func)
 f = None
@@ -151,20 +151,20 @@
 
 def test_with_bound_and_unbound_methods(self):
 data = map(str, range(10))
- join = self.thetype(str.join, '')
+ join = self.partial(str.join, '')
 self.assertEqual(join(data), '0123456789')
- join = self.thetype(''.join)
+ join = self.partial(''.join)
 self.assertEqual(join(data), '0123456789')
 
 def test_pickle(self):
- f = self.thetype(signature, ['asdf'], bar=[True])
+ f = self.partial(signature, ['asdf'], bar=[True])
 f.attr = []
 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
 f_copy = pickle.loads(pickle.dumps(f, proto))
 self.assertEqual(signature(f_copy), signature(f))
 
 def test_copy(self):
- f = self.thetype(signature, ['asdf'], bar=[True])
+ f = self.partial(signature, ['asdf'], bar=[True])
 f.attr = []
 f_copy = copy.copy(f)
 self.assertEqual(signature(f_copy), signature(f))
@@ -173,7 +173,7 @@
 self.assertIs(f_copy.keywords, f.keywords)
 
 def test_deepcopy(self):
- f = self.thetype(signature, ['asdf'], bar=[True])
+ f = self.partial(signature, ['asdf'], bar=[True])
 f.attr = []
 f_copy = copy.deepcopy(f)
 self.assertEqual(signature(f_copy), signature(f))
@@ -184,7 +184,7 @@
 self.assertIsNot(f_copy.keywords['bar'], f.keywords['bar'])
 
 def test_setstate(self):
- f = self.thetype(signature)
+ f = self.partial(signature)
 f.__setstate__((capture, (1,), dict(a=10), dict(attr=[])))
 self.assertEqual(signature(f),
 (capture, (1,), dict(a=10), dict(attr=[])))
@@ -207,7 +207,7 @@
 self.assertEqual(f(), ((), {}))
 
 def test_setstate_errors(self):
- f = self.thetype(signature)
+ f = self.partial(signature)
 self.assertRaises(TypeError, f.__setstate__, (capture, (), {}))
 self.assertRaises(TypeError, f.__setstate__, (capture, (), {}, {}, None))
 self.assertRaises(TypeError, f.__setstate__, [capture, (), {}, None])
@@ -217,7 +217,7 @@
 self.assertRaises(TypeError, f.__setstate__, (capture, (), [], None))
 
 def test_setstate_subclasses(self):
- f = self.thetype(signature)
+ f = self.partial(signature)
 f.__setstate__((capture, MyTuple((1,)), MyDict(a=10), None))
 s = signature(f)
 self.assertEqual(s, (capture, (1,), dict(a=10), {}))
@@ -237,19 +237,19 @@
 self.assertIs(type(r[0]), tuple)
 
 def test_recursive_pickle(self):
- f = self.thetype(capture)
+ f = self.partial(capture)
 f.__setstate__((f, (), {}, {}))
 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
 with self.assertRaises(RuntimeError):
 pickle.dumps(f, proto)
 
- f = self.thetype(capture)
+ f = self.partial(capture)
 f.__setstate__((capture, (f,), {}, {}))
 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
 f_copy = pickle.loads(pickle.dumps(f, proto))
 self.assertIs(f_copy.args[0], f_copy)
 
- f = self.thetype(capture)
+ f = self.partial(capture)
 f.__setstate__((capture, (), {'a': f}, {}))
 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
 f_copy = pickle.loads(pickle.dumps(f, proto))
@@ -269,7 +269,7 @@
 return {}
 raise IndexError
 
- f = self.thetype(object)
+ f = self.partial(object)
 self.assertRaises(TypeError, f.__setstate__, BadSequence())
 
 class PartialSubclass(functools.partial):
@@ -277,11 +277,11 @@
 
 class TestPartialSubclass(TestPartial):
 
- thetype = PartialSubclass
+ partial = PartialSubclass
 
 class TestPythonPartial(TestPartial):
 
- thetype = PythonPartial
+ partial = PythonPartial
 
 # the python version isn't picklable
 test_pickle = None
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /