Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
myfunc.call_count = 0
body = u"""
<p class="foo">First</p>
"""
sel = Selector(text=body)
self.assertRaisesRegexp(
ValueError, 'Unregistered function in myfunc',
sel.xpath, 'myfunc()')
set_xpathfunc('myfunc', myfunc)
sel.xpath('myfunc()')
self.assertEqual(myfunc.call_count, 1)
set_xpathfunc('myfunc', None)
self.assertRaisesRegexp(
ValueError, 'Unregistered function in myfunc',
sel.xpath, 'myfunc()')
def test_set_xpathfunc(self):
def myfunc(ctx):
myfunc.call_count += 1
myfunc.call_count = 0
body = u"""
<p class="foo">First</p>
"""
sel = Selector(text=body)
self.assertRaisesRegexp(
ValueError, 'Unregistered function in myfunc',
sel.xpath, 'myfunc()')
set_xpathfunc('myfunc', myfunc)
sel.xpath('myfunc()')
self.assertEqual(myfunc.call_count, 1)
set_xpathfunc('myfunc', None)
self.assertRaisesRegexp(
ValueError, 'Unregistered function in myfunc',
sel.xpath, 'myfunc()')