summaryrefslogtreecommitdiff
path: root/tests/unit/test_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/test_utils.py')
-rw-r--r--tests/unit/test_utils.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index 1a6fba46d..4306d0790 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -3,6 +3,7 @@
import lxml.etree
from lxml import html
+from parameterized.parameterized import parameterized
from searx.exceptions import SearxXPathSyntaxException, SearxEngineXPathException
from searx import utils
@@ -66,9 +67,15 @@ class TestUtils(SearxTestCase): # pylint: disable=missing-class-docstring
self.assertEqual(utils.extract_text(dom.xpath('boolean(//span)')), 'True')
self.assertEqual(utils.extract_text(dom.xpath('//img/@src')), 'test.jpg')
self.assertEqual(utils.extract_text(dom.xpath('//unexistingtag')), '')
+
+ def test_extract_text_allow_none(self):
self.assertEqual(utils.extract_text(None, allow_none=True), None)
+
+ def test_extract_text_error_none(self):
with self.assertRaises(ValueError):
utils.extract_text(None)
+
+ def test_extract_text_error_empty(self):
with self.assertRaises(ValueError):
utils.extract_text({})
@@ -103,14 +110,16 @@ class TestHTMLTextExtractor(SearxTestCase): # pylint: disable=missing-class-doc
def test__init__(self):
self.assertEqual(self.html_text_extractor.result, [])
- def test_handle_charref(self):
- self.html_text_extractor.handle_charref('xF')
- self.assertIn('\x0f', self.html_text_extractor.result)
- self.html_text_extractor.handle_charref('XF')
- self.assertIn('\x0f', self.html_text_extractor.result)
-
- self.html_text_extractor.handle_charref('97')
- self.assertIn('a', self.html_text_extractor.result)
+ @parameterized.expand(
+ [
+ ('xF', '\x0f'),
+ ('XF', '\x0f'),
+ ('97', 'a'),
+ ]
+ )
+ def test_handle_charref(self, charref: str, expected: str):
+ self.html_text_extractor.handle_charref(charref)
+ self.assertIn(expected, self.html_text_extractor.result)
def test_handle_entityref(self):
entity = 'test'
@@ -191,7 +200,7 @@ class TestXPathUtils(SearxTestCase): # pylint: disable=missing-class-docstring
self.assertEqual(utils.eval_xpath_getindex(doc, '//i/text()', 1, default='something'), 'something')
# default is None
- self.assertEqual(utils.eval_xpath_getindex(doc, '//i/text()', 1, default=None), None)
+ self.assertIsNone(utils.eval_xpath_getindex(doc, '//i/text()', 1, default=None))
# index not found
with self.assertRaises(SearxEngineXPathException) as context: