mirror of https://github.com/searxng/searxng.git
Cover searx.utils
This commit is contained in:
parent
e4419a065f
commit
8810273010
|
@ -0,0 +1,20 @@
|
||||||
|
[run]
|
||||||
|
branch = True
|
||||||
|
source =
|
||||||
|
searx/engines
|
||||||
|
searx/__init__.py
|
||||||
|
searx/autocomplete.py
|
||||||
|
searx/https_rewrite.py
|
||||||
|
searx/languages.py
|
||||||
|
searx/search.py
|
||||||
|
searx/testing.py
|
||||||
|
searx/utils.py
|
||||||
|
searx/webapp.py
|
||||||
|
|
||||||
|
[report]
|
||||||
|
show_missing = True
|
||||||
|
exclude_lines =
|
||||||
|
if __name__ == .__main__.:
|
||||||
|
|
||||||
|
[html]
|
||||||
|
directory = coverage
|
6
Makefile
6
Makefile
|
@ -29,9 +29,9 @@ flake8: .installed.cfg
|
||||||
@bin/flake8 ./searx/
|
@bin/flake8 ./searx/
|
||||||
|
|
||||||
coverage: .installed.cfg
|
coverage: .installed.cfg
|
||||||
@bin/coverage run --source=./searx/ --branch bin/test
|
@bin/coverage run bin/test
|
||||||
@bin/coverage report --show-missing
|
@bin/coverage report
|
||||||
@bin/coverage html --directory ./coverage
|
@bin/coverage html
|
||||||
|
|
||||||
production: bin/buildout production.cfg setup.py
|
production: bin/buildout production.cfg setup.py
|
||||||
bin/buildout -c production.cfg $(options)
|
bin/buildout -c production.cfg $(options)
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
import mock
|
||||||
|
from searx.testing import SearxTestCase
|
||||||
|
from searx import utils
|
||||||
|
|
||||||
|
|
||||||
|
class TestUtils(SearxTestCase):
|
||||||
|
|
||||||
|
def test_gen_useragent(self):
|
||||||
|
self.assertIsInstance(utils.gen_useragent(), str)
|
||||||
|
self.assertIsNotNone(utils.gen_useragent())
|
||||||
|
self.assertTrue(utils.gen_useragent().startswith('Mozilla'))
|
||||||
|
|
||||||
|
def test_highlight_content(self):
|
||||||
|
self.assertEqual(utils.highlight_content(0, None), None)
|
||||||
|
self.assertEqual(utils.highlight_content(None, None), None)
|
||||||
|
self.assertEqual(utils.highlight_content('', None), None)
|
||||||
|
self.assertEqual(utils.highlight_content(False, None), None)
|
||||||
|
|
||||||
|
contents = [
|
||||||
|
'<html></html>'
|
||||||
|
'not<'
|
||||||
|
]
|
||||||
|
for content in contents:
|
||||||
|
self.assertEqual(utils.highlight_content(content, None), content)
|
||||||
|
|
||||||
|
content = 'a'
|
||||||
|
query = 'test'
|
||||||
|
self.assertEqual(utils.highlight_content(content, query), content)
|
||||||
|
query = 'a test'
|
||||||
|
self.assertEqual(utils.highlight_content(content, query), content)
|
||||||
|
|
||||||
|
|
||||||
|
class TestHTMLTextExtractor(SearxTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.html_text_extractor = utils.HTMLTextExtractor()
|
||||||
|
|
||||||
|
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(u'\x0f', self.html_text_extractor.result)
|
||||||
|
self.html_text_extractor.handle_charref('XF')
|
||||||
|
self.assertIn(u'\x0f', self.html_text_extractor.result)
|
||||||
|
|
||||||
|
self.html_text_extractor.handle_charref('97')
|
||||||
|
self.assertIn(u'a', self.html_text_extractor.result)
|
||||||
|
|
||||||
|
def test_handle_entityref(self):
|
||||||
|
entity = 'test'
|
||||||
|
self.html_text_extractor.handle_entityref(entity)
|
||||||
|
self.assertIn(entity, self.html_text_extractor.result)
|
||||||
|
|
||||||
|
|
||||||
|
class TestUnicodeWriter(SearxTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.unicode_writer = utils.UnicodeWriter(mock.MagicMock())
|
||||||
|
|
||||||
|
def test_write_row(self):
|
||||||
|
row = [1, 2, 3]
|
||||||
|
self.assertEqual(self.unicode_writer.writerow(row), None)
|
||||||
|
|
||||||
|
def test_write_rows(self):
|
||||||
|
self.unicode_writer.writerow = mock.MagicMock()
|
||||||
|
rows = [1, 2, 3]
|
||||||
|
self.unicode_writer.writerows(rows)
|
||||||
|
self.assertEqual(self.unicode_writer.writerow.call_count, len(rows))
|
Loading…
Reference in New Issue