[tracker-miners/sam/search-sentence] functional-tests: Properly test searching for a quoted sentence
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/search-sentence] functional-tests: Properly test searching for a quoted sentence
- Date: Sat, 21 Dec 2019 11:35:32 +0000 (UTC)
commit e111cc48aa7dfd7342c43e3d28037ef2a856beed
Author: Sam Thursfield <sam afuera me uk>
Date: Sat Dec 21 11:34:10 2019 +0000
functional-tests: Properly test searching for a quoted sentence
tests/functional-tests/310-fts-basic.py | 13 +++++++++++--
tests/functional-tests/minertest.py | 32 +++++++++++++++++++++++++++++++-
2 files changed, 42 insertions(+), 3 deletions(-)
---
diff --git a/tests/functional-tests/310-fts-basic.py b/tests/functional-tests/310-fts-basic.py
index 8678656ed..83d2665e9 100755
--- a/tests/functional-tests/310-fts-basic.py
+++ b/tests/functional-tests/310-fts-basic.py
@@ -32,7 +32,7 @@ import locale
import time
import unittest as ut
-from minertest import CommonTrackerMinerFTSTest, DEFAULT_TEXT
+from minertest import CommonTrackerMinerFTSTest, DEFAULT_TEXT, NFO_DOCUMENT
import configuration as cfg
@@ -77,7 +77,16 @@ class MinerFTSBasicTest (CommonTrackerMinerFTSTest):
def test_06_sentence(self):
TEXT = "plastic is fantastic"
- self.basic_test(TEXT, TEXT)
+
+ self.create_text_files({
+ 'test-monitored/match.txt': "I think that plastic is fantastic.",
+ 'test-monitored/non-match-1.txt': "Plastic plastic plastic plastic plastic.",
+ 'test-monitored/non-match-2.txt': "Plastic is OK, but wood is really something fantastic.",
+ })
+
+ results = self.search_sentence(TEXT)
+ self.assertEqual(len(results), 1)
+ self.assertIn(self.uri('test-monitored/match.txt'), results)
def test_07_partial_sentence(self):
TEXT = "plastic is fantastic"
diff --git a/tests/functional-tests/minertest.py b/tests/functional-tests/minertest.py
index 7feb4195a..f386263a8 100644
--- a/tests/functional-tests/minertest.py
+++ b/tests/functional-tests/minertest.py
@@ -196,11 +196,27 @@ class CommonTrackerMinerFTSTest (CommonTrackerMinerTest):
self.tracker.reset_graph_updates_tracking()
+ def create_text_files(self, file_contents):
+ """
+ Create and index a set of files.
+
+ The `file-contents` parameter should be a dict mapping filename to
+ contents.
+ """
+ for filename, contents in file_contents.items():
+ with open(self.path(filename), 'w') as f:
+ f.write(contents)
+ for filename in file_contents:
+ self.tracker.await_resource_inserted(
+ rdf_class=NFO_DOCUMENT, url=self.uri(filename),
+ required_property='nie:plainTextContent')
+ self.tracker.reset_graph_updates_tracking()
+
def search_word(self, word):
"""
Return list of URIs with the word in them
"""
- log.info("Search for: %s", word)
+ log.info("Search for word: %s", word)
results = self.tracker.query("""
SELECT ?url WHERE {
?u a nfo:TextDocument ;
@@ -210,6 +226,20 @@ class CommonTrackerMinerFTSTest (CommonTrackerMinerTest):
""" % (word))
return [r[0] for r in results]
+ def search_sentence(self, sentence):
+ """
+ Return list of URIs with the sentence in them
+ """
+ log.info("Search for sentence: %s" % sentence)
+ results = self.tracker.query("""
+ SELECT ?url WHERE {
+ ?u a nfo:TextDocument ;
+ nie:url ?url ;
+ fts:match \"%s\".
+ }
+ """ % (sentence))
+ return [r[0] for r in results]
+
def basic_test(self, text, word):
"""
Save the text on the testfile, search the word
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]