Commit f0fb1a29 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

Let yams_match respect Predicate.__call__ interface

CubicWeb's Predicate's __call__ method's interface is:

  def __call__(self, cls, req, **kwargs):

In yams_match, we had 'rtype' and 'role' as non-keyword arguments, thus
producing TypeError upon calls of a class's __select__ without all
required arguments. We change this to have 'rtype' and 'role' option
(though score will still be 0 if they are unspecified) so that we now
respect base interface.
parent 615ee5601d70
......@@ -105,7 +105,7 @@ class yams_match(Predicate):
target_types = frozenset(target_types)
self.target_types = target_types
def __call__(self, cls, cnx, rtype, role, **kwargs):
def __call__(self, cls, cnx, rtype=None, role=None, **kwargs):
etype = _etype_from_context(kwargs)
score = 0
for key in ('etype', 'rtype', 'role'):
......@@ -1714,6 +1714,15 @@ class PredicatesTC(CubicWebTC):
etype='etype', rtype='rtype', role='notrole',
# Make that __call__ without both rtype and role yields 0
self.assertEqual(predicate(None, None),
self.assertEqual(predicate(None, None,
self.assertEqual(predicate(None, None,
etype='etype', rtype='rtype'),
def test_yams_match_entity(self):
predicate = yams_match(etype='CWUser')
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