summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_utils.py22
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)