def test_get_xpath_invalid(self): invalid_xpath = '//a[0].text' with self.assertRaises(SearxXPathSyntaxException) as context: utils.get_xpath(invalid_xpath) self.assertEqual(context.exception.message, 'Invalid expression') self.assertEqual(context.exception.xpath_str, invalid_xpath)
def test_get_xpath_cache(self): xp1 = utils.get_xpath('//a') xp2 = utils.get_xpath('//div') xp3 = utils.get_xpath('//a') self.assertEqual(id(xp1), id(xp3)) self.assertNotEqual(id(xp1), id(xp2))
def test_get_xpath_type(self): utils.get_xpath(lxml.etree.XPath('//a')) with self.assertRaises(TypeError): utils.get_xpath([])