<NME> multiword_completion_test.py
<BEF> ADDFILE
<MSG> Merge pull request #58 from hendrik-cliqz/test-coverage

add test for mw completion
<DFF> @@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+# Usage: py.test tests
+
+import contextlib
+import os
+
+import pykeyvi
+
+import sys
+import os
+
+root = os.path.dirname(os.path.abspath(__file__))
+sys.path.append(os.path.join(root, "../"))
+
+from test_tools import tmp_dictionary
+
+MULTIWORD_QUERY_SEPARATOR = '\x1b'
+
+def test_mw_completion():
+    c=pykeyvi.CompletionDictionaryCompiler()
+    c.Add("mozilla firefox" + '\x1b' + "mozilla firefox", 80)
+    c.Add("mozilla footprint" + '\x1b' + "mozilla footprint", 30)
+    c.Add("mozilla fans" + '\x1b' + "mozilla fans", 43)
+    c.Add("mozilla firebird" + '\x1b' + "mozilla firebird", 12)
+    c.Add("internet microsoft explorer" + '\x1b' + "microsoft internet explorer", 21)
+    c.Add("google chrome" + '\x1b' + "google chrome", 54)
+    c.Add("netscape navigator" + '\x1b' + "netscape navigator", 10)
+    with tmp_dictionary(c, 'mw_completion.kv') as d:
+        mw = pykeyvi.MultiWordCompletion(d)
+        matches = sorted([(match.GetAttribute('weight'), match.GetMatchedString())
+                          for match in mw.GetCompletions("mozilla f")], reverse=True)
+        assert len(matches) == 4
+        assert matches[0][1] == 'mozilla firefox'
+        assert matches[1][1] == 'mozilla fans'
+        assert matches[2][1] == 'mozilla footprint'
+        assert matches[3][1] == 'mozilla firebird'

{'commit': 'diff --git a/pykeyvi/tests/completion/multiword_completion_test.py b/pykeyvi/tests/completion/multiword_completion_test.py\nnew file mode 100644\nindex 00000000..2b2f5650\n--- /dev/null\n+++ b/pykeyvi/tests/completion/multiword_completion_test.py\n@@ -0,0 +1,36 @@\n+# -*- coding: utf-8 -*-\n+# Usage: py.test tests\n+\n+import contextlib\n+import os\n+\n+import pykeyvi\n+\n+import sys\n+import os\n+\n+root = os.path.dirname(os.path.abspath(__file__))\n+sys.path.append(os.path.join(root, "../"))\n+\n+from test_tools import tmp_dictionary\n+\n+MULTIWORD_QUERY_SEPARATOR = \'\\x1b\'\n+\n+def test_mw_completion():\n+    c=pykeyvi.CompletionDictionaryCompiler()\n+    c.Add("mozilla firefox" + \'\\x1b\' + "mozilla firefox", 80)\n+    c.Add("mozilla footprint" + \'\\x1b\' + "mozilla footprint", 30)\n+    c.Add("mozilla fans" + \'\\x1b\' + "mozilla fans", 43)\n+    c.Add("mozilla firebird" + \'\\x1b\' + "mozilla firebird", 12)\n+    c.Add("internet microsoft explorer" + \'\\x1b\' + "microsoft internet explorer", 21)\n+    c.Add("google chrome" + \'\\x1b\' + "google chrome", 54)\n+    c.Add("netscape navigator" + \'\\x1b\' + "netscape navigator", 10)\n+    with tmp_dictionary(c, \'mw_completion.kv\') as d:\n+        mw = pykeyvi.MultiWordCompletion(d)\n+        matches = sorted([(match.GetAttribute(\'weight\'), match.GetMatchedString())\n+                          for match in mw.GetCompletions("mozilla f")], reverse=True)\n+        assert len(matches) == 4\n+        assert matches[0][1] == \'mozilla firefox\'\n+        assert matches[1][1] == \'mozilla fans\'\n+        assert matches[2][1] == \'mozilla footprint\'\n+        assert matches[3][1] == \'mozilla firebird\'\n', 'commit_subject': 'Merge pull request #58 from hendrik-cliqz/test-coverage', 'repo_name': 'cliqz-oss/keyvi', 'committer': {'name': 'Hendrik Muhs', 'email': '1c4919b668907a9a2d3be3c85faa4408172273d2@gmail.com', 'time_sec': '1448182745', 'tz_offset': '60', 'date': {'seconds': '1448182745'}}, 'commit_tree': '89ea90940679964c9eae51d7b6e7a795310e7f33', 'commit_message': 'Merge pull request #58 from hendrik-cliqz/test-coverage\n\nadd test for mw completion', 'language_name': 'Python', 'license': 'apache-2.0', 'hunks': '@@ -0,0 +1,36 @@\n+# -*- coding: utf-8 -*-\n+# Usage: py.test tests\n+\n+import contextlib\n+import os\n+\n+import pykeyvi\n+\n+import sys\n+import os\n+\n+root = os.path.dirname(os.path.abspath(__file__))\n+sys.path.append(os.path.join(root, "../"))\n+\n+from test_tools import tmp_dictionary\n+\n+MULTIWORD_QUERY_SEPARATOR = \'\\x1b\'\n+\n+def test_mw_completion():\n+    c=pykeyvi.CompletionDictionaryCompiler()\n+    c.Add("mozilla firefox" + \'\\x1b\' + "mozilla firefox", 80)\n+    c.Add("mozilla footprint" + \'\\x1b\' + "mozilla footprint", 30)\n+    c.Add("mozilla fans" + \'\\x1b\' + "mozilla fans", 43)\n+    c.Add("mozilla firebird" + \'\\x1b\' + "mozilla firebird", 12)\n+    c.Add("internet microsoft explorer" + \'\\x1b\' + "microsoft internet explorer", 21)\n+    c.Add("google chrome" + \'\\x1b\' + "google chrome", 54)\n+    c.Add("netscape navigator" + \'\\x1b\' + "netscape navigator", 10)\n+    with tmp_dictionary(c, \'mw_completion.kv\') as d:\n+        mw = pykeyvi.MultiWordCompletion(d)\n+        matches = sorted([(match.GetAttribute(\'weight\'), match.GetMatchedString())\n+                          for match in mw.GetCompletions("mozilla f")], reverse=True)\n+        assert len(matches) == 4\n+        assert matches[0][1] == \'mozilla firefox\'\n+        assert matches[1][1] == \'mozilla fans\'\n+        assert matches[2][1] == \'mozilla footprint\'\n+        assert matches[3][1] == \'mozilla firebird\'\n', 'addition_count': 36, 'deletion_count': 0, 'src_file': '/dev/null', 'tgt_file': 'b/pykeyvi/tests/completion/multiword_completion_test.py', 'file_extension': '.py', 'before_file': 'ADDFILE', 'message': 'Merge pull request #58 from hendrik-cliqz/test-coverage\n\nadd test for mw completion', 'author_name': 'Hendrik Muhs', 'lang': 'py'}