'Test expression parsing (not comprehensive)'

@unittest.skipIf((not PYPARSING), 'PyParsing    not    available')
def testParsing(self):

    p = S3URLQueryParser()
    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    examples = (('pr_person', 'first_name    eq    "Test"', {None: '(pr_person.first_name    ==    "Test")'}), ('pr_person', '~.id    belongs    1,2,3', {None: "(pr_person.id    in    ['1',    '2',    '3'])"}), ('pr_person', 'last_name    like    "User*"    or    lower(contact.value)    like    "*example.com"', {None: '((pr_person.last_name.lower()    like    "user%")    or    (pr_contact.value.lower()    like    "%example.com"))'}), ('pr_person', 'last_name    like    "User*"    and    not(contact.value    like    "*example.com"    or    first_name    like    "Norm*")', {None: '((pr_person.last_name.lower()    like    "user%")    and    (not    (pr_person.first_name.lower()    like    "norm%")))', 'contact': '(not    (pr_contact.value.lower()    like    "%example.com"))'}), ('pr_person', '', {}), ('org_organisation', None, {}), ('org_facility', 'organisation_id$name    like    "*YMCA*"    or    organisation_id$name    like    "*YWCA*"', {None: '((org_organisation.name.lower()    like    "%ymca%")    or    (org_organisation.name.lower()    like    "%ywca%"))'}), ('org_office', 'not    a    valid    expression', {}))
    s3db = current.s3db
    for (i, example) in enumerate(examples):
        (resource_name, expression, expected) = example
        result = p.parse(expression)
        assertTrue(isinstance(result, dict), msg='Example    %s    failed:    no    dict    returned')
        ealiases = set(expected.keys())
        raliases = set(result.keys())
        assertEqual((ealiases ^ raliases), set(), msg=('Example    %s    failed:    mismatching    aliases    %s!=%s' % (i, str(list(ealiases)), str(list(raliases)))))
        resource = s3db.resource(resource_name)
        for (k, v) in expected.items():
            actual = result[k].represent(resource)
            assertEqual(v, actual, msg=("Example    %s    inconsistent    result:    expected    '%s'    for    alias    '%s'    but    found    '%s'" % (i, v, k, actual)))
