310-fts-basic.py 3.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#!/usr/bin/python
#-*- coding: utf-8 -*-

# Copyright (C) 2010, Nokia (ivan.frade@nokia.com)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA  02110-1301, USA.

#
# TODO:
#     These tests are for files... we need to write them for folders!
#
"""
Monitor a directory, copy/move/remove/update text files and check that
the text contents are updated accordingly in the indexes.
"""
import os
import shutil
import locale
import time

34
import unittest as ut
35
from common.utils.helpers import log
36
from common.utils.minertest import CommonTrackerMinerFTSTest, DEFAULT_TEXT
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
from common.utils import configuration as cfg


class MinerFTSBasicTest (CommonTrackerMinerFTSTest):
    """
    Tests different contents in a single file
    """

    def test_01_single_word (self):
        TEXT = "automobile"
        self.basic_test (TEXT, TEXT)

    def test_02_multiple_words (self):
        TEXT = "automobile with unlimited power"
        self.set_text (TEXT)
        
        results = self.search_word ("automobile")
        self.assertEquals (len (results), 1)
55
        self.assertIn (self.uri (self.testfile), results)
56 57 58

        results = self.search_word ("unlimited")
        self.assertEquals (len (results), 1)
59
        self.assertIn (self.uri (self.testfile), results)
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75


    def test_03_long_word (self):
        # TEXT is longer than the 20 characters specified in the fts configuration
        TEXT = "fsfsfsdfskfweeqrewqkmnbbvkdasdjefjewriqjfnc"
        self.set_text (TEXT)

        results = self.search_word (TEXT)
        self.assertEquals (len (results), 0)

    def test_04_non_existent_word (self):
        TEXT = "This a trick"
        self.set_text (TEXT)
        results = self.search_word ("trikc")
        self.assertEquals (len (results), 0)

76
    def test_05_word_multiple_times_in_file (self):
77 78 79
        TEXT = "automobile is red. automobile is big. automobile is great!"
        self.basic_test (TEXT, "automobile")

80
    def test_06_sentence (self):
81 82 83
        TEXT = "plastic is fantastic"
        self.basic_test (TEXT, TEXT)

84
    def test_07_partial_sentence (self):
85 86 87
        TEXT = "plastic is fantastic"
        self.basic_test (TEXT, "is fantastic")

88
    @ut.skip("Currently fails with: fts5: syntax error near '.'")
89
    def test_08_strange_word (self):
90 91 92 93 94 95
        # FIXME Not sure what are we testing here
        TEXT = "'summer.time'"
        self.basic_test (TEXT, "summer.time")

    # Skip the test 'search for .'

96
    def test_09_mixed_letters_and_numbers (self):
97 98 99
        TEXT = "abc123"
        self.basic_test (TEXT, "abc123")

100
    def test_10_ignore_numbers (self):
101 102 103 104 105 106 107
        TEXT = "palabra 123123"
        self.set_text (TEXT)
        results = self.search_word ("123123")
        self.assertEquals (len (results), 0)


if __name__ == "__main__":
108
    ut.main (failfast=True)