Where: work with methods, ala Rules

This commit is contained in:
Doug Blank 2016-05-06 10:04:24 -04:00
parent 61c2ed3240
commit 6d95cd5dd3
2 changed files with 15 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#
from gramps.gen.db.where import eval_where
from gramps.gen.lib import Person
import unittest
##########
@ -40,6 +41,9 @@ class Thing(object):
def where(self):
return lambda person: person.gramps_id == self.list[1]
def apply(self, db, person):
return person.gender == Person.MALE
class ClosureTest(unittest.TestCase):
def check(self, test):
result = eval_where(test[0])
@ -98,5 +102,9 @@ class ClosureTest(unittest.TestCase):
(lambda person: LIKE(person.gramps_id, "I000%"),
["gramps_id", "LIKE", "I000%"]))
def test_11(self):
self.check(
[Thing().apply, ["gender", "==", 1]])
if __name__ == "__main__":
unittest.main()

View File

@ -115,6 +115,13 @@ class ParseFilter(Visitor):
self.parameter = self.visit(node.args)[0]
return self.visit(node.body)
def visitFunctionDef(self, node):
self.parameter = self.visit(node.args)[2] # ['self', 'db', 'person']
return self.visit(node.body)[0]
def visitReturn(self, node):
return self.visit(node.value)
def visitarguments(self, node):
return [self.visit(arg) for arg in node.args]