'Test parser response and error logging'

def testParser(self):

    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    assertIn = self.assertIn
    assertNotIn = self.assertNotIn
    settings = current.deployment_settings
    debug = settings.base.debug
    settings.base.debug = True
    from s3log import S3Log
    del current.log
    S3Log.setup()
    try:
        p = S3URLQueryParser()
        log_recorder = current.log.recorder()
        expr = '~.test    eq    1'
        q = p.parse(expr)
        log_messages = log_recorder.read()
        assertTrue(isinstance(q, dict))
        if PYPARSING:
            assertTrue((None in q))
            assertNotIn('Invalid    URL    Filter    Expression', log_messages)
        else:
            assertEqual(q, {})
        expr = 'invalidexpression'
        log_recorder.clear()
        q = p.parse(expr)
        log_messages = log_recorder.read()
        assertEqual(q, {})
        if PYPARSING:
            assertIn('Invalid    URL    Filter    Expression', log_messages)
        expr = ''
        log_recorder.clear()
        q = p.parse(expr)
        log_messages = log_recorder.read()
        assertEqual(q, {})
        if PYPARSING:
            assertNotIn('Invalid    URL    Filter    Expression', log_messages)
        expr = None
        log_recorder.clear()
        q = p.parse(expr)
        log_messages = log_recorder.stop()
        assertEqual(q, {})
        if PYPARSING:
            assertNotIn('Invalid    URL    Filter    Expression', log_messages)
    finally:
        settings.base.debug = debug
        del current.log
        S3Log.setup()
