Commit 35171704 authored by Jérome Perrin's avatar Jérome Perrin

stack/erp5: backport some Zope fixes WIP

parent 3f3f64b8
From d439b58562670886b3247829aa9ff053b6aaf7fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 19 Sep 2023 06:28:54 +0200
Subject: [PATCH 2/2] mapply wip
---
src/ZPublisher/mapply.py | 5 ++++-
src/ZPublisher/tests/test_mapply.py | 21 ++++++++++++++++++---
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/ZPublisher/mapply.py b/src/ZPublisher/mapply.py
index 19deeacf4..41c9ed7e1 100644
--- a/src/ZPublisher/mapply.py
+++ b/src/ZPublisher/mapply.py
@@ -21,7 +21,7 @@ def default_call_object(object, args, context):
def default_missing_name(name, context):
- raise TypeError('argument %s was ommitted' % name)
+ raise TypeError('argument %s was omitted' % name)
def default_handle_class(klass, context):
@@ -61,6 +61,9 @@ def mapply(object, positional=(), keyword={},
positional.insert(0, missing_name('self', context))
if len(positional) > nargs:
raise TypeError('too many arguments')
+ for a, name in zip(positional, names):
+ if name in keyword:
+ raise TypeError('multiple values for argument %s' % name)
args = positional
else:
if bind and nargs and names[0] == 'self':
diff --git a/src/ZPublisher/tests/test_mapply.py b/src/ZPublisher/tests/test_mapply.py
index d31f6d61b..d08a5c979 100644
--- a/src/ZPublisher/tests/test_mapply.py
+++ b/src/ZPublisher/tests/test_mapply.py
@@ -28,11 +28,10 @@ class MapplyTests(unittest.TestCase):
def compute(a, b, c=4):
return '%d%d%d' % (a, b, c)
- values = {'a': 2, 'b': 3, 'c': 5}
- v = mapply(compute, (), values)
+ v = mapply(compute, (), {'a': 2, 'b': 3, 'c': 5})
self.assertEqual(v, '235')
- v = mapply(compute, (7,), values)
+ v = mapply(compute, (7,), {'b': 3, 'c': 5})
self.assertEqual(v, '735')
def testClass(self):
@@ -115,3 +114,19 @@ class MapplyTests(unittest.TestCase):
ob = NoCallButAcquisition().__of__(Root())
self.assertRaises(TypeError, mapply, ob, (), {})
+
+ def testErrors(self):
+ def compute(a, b, c=4):
+ return '%d%d%d' % (a, b, c)
+
+ with self.assertRaisesRegex(TypeError, 'argument a was omitted'):
+ mapply(compute, (), {})
+
+ with self.assertRaisesRegex(TypeError, 'argument b was omitted'):
+ mapply(compute, (1, ), {})
+
+ with self.assertRaisesRegex(TypeError, 'multiple values for argument b'):
+ mapply(compute, (1, 2, ), {'b': 3})
+
+ with self.assertRaisesRegex(TypeError, 'too many arguments'):
+ mapply(compute, (1, 2, 3, 4), {})
--
2.39.2
......@@ -687,6 +687,7 @@ urlnorm-patches = ${:_profile_base_location_}/../../component/egg-patch/urlnorm/
urlnorm-patch-options = -p1
Zope-patches =
${:_profile_base_location_}/../../component/egg-patch/Zope/0001-WSGIPublisher-set-REMOTE_USER-even-in-case-of-error-.patch#a437f4da28975f94dd07db0b02954111
${:_profile_base_location_}/../../component/egg-patch/Zope/0002-mapply-wip.patch#56928a9d0b25b344feb0b6ead7bc5e48
Zope-patch-options = -p1
[eggs:python2]
......@@ -761,7 +762,7 @@ PyPDF2 = 1.26.0+SlapOSPatched002
pysvn = 1.9.15+SlapOSPatched001
python-ldap = 2.4.32+SlapOSPatched001
python-magic = 0.4.12+SlapOSPatched001
Zope = 4.8.9+SlapOSPatched001
Zope = 4.8.9+SlapOSPatched002
## https://lab.nexedi.com/nexedi/slapos/merge_requests/648
pylint = 1.4.4+SlapOSPatched002
# astroid 1.4.1 breaks testDynamicClassGeneration
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment