diff options
author | ArtikusHG <artiomoleynic@gmail.com> | 2022-12-11 17:45:47 +0200 |
---|---|---|
committer | ArtikusHG <artiomoleynic@gmail.com> | 2022-12-16 21:07:39 +0200 |
commit | 1f8f8c1e91040fd10bacdc473b8d5f97dda6424e (patch) | |
tree | 30ed501e9a052ae4a9d81af45026af9a1deecfcf /tests | |
parent | a6d870d5cfecfee78dcdd2a67cce318c894da2da (diff) | |
download | searxng-1f8f8c1e91040fd10bacdc473b8d5f97dda6424e.tar.gz searxng-1f8f8c1e91040fd10bacdc473b8d5f97dda6424e.zip |
Replace langdetect with fasttext
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_utils.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 8ac7db479..6f51f1ee3 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -232,3 +232,25 @@ class TestXPathUtils(SearxTestCase): with self.assertRaises(SearxEngineXPathException) as context: utils.eval_xpath_getindex(doc, 'count(//i)', 1) self.assertEqual(context.exception.message, 'the result is not a list') + + def test_detect_language(self): + # make sure new line are not an issue + # fasttext.predict('') does not accept new line. + l = utils.detect_language('The quick brown fox jumps over\nthe lazy dog') + self.assertEqual(l, 'en') + + l = utils.detect_language('いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす') + self.assertEqual(l, 'ja') + + l = utils.detect_language('Pijamalı hasta yağız şoföre çabucak güvendi.') + self.assertEqual(l, 'tr') + + l = utils.detect_language('') + self.assertIsNone(l) + + # mix languages --> None + l = utils.detect_language('The いろはにほへと Pijamalı') + self.assertIsNone(l) + + with self.assertRaises(ValueError): + utils.detect_language(None) |