Ejemplo n.º 1
0
    def matches_entry(self, model, itr, user_data=None):
        entry_text = self._entry.get_text()
        if not entry_text:
            # everything matches empty string
            return True

        value = model[itr][0]
        eng_value = self._xkl_wrapper.get_layout_variant_description(value, xlated=False)
        xlated_value = self._xkl_wrapper.get_layout_variant_description(value)
        translit_value = strip_accents(xlated_value).lower()
        entry_text = entry_text.lower()

        return have_word_match(entry_text, eng_value) or have_word_match(entry_text, xlated_value) \
            or have_word_match(entry_text, translit_value)
Ejemplo n.º 2
0
    def have_word_match_test(self):
        """Test have_word_match."""

        self.assertTrue(iutil.have_word_match("word1 word2", "word1 word2 word3"))
        self.assertTrue(iutil.have_word_match("word1 word2", "word2 word1 word3"))
        self.assertTrue(iutil.have_word_match("word2 word1", "word3 word1 word2"))
        self.assertTrue(iutil.have_word_match("word1", "word1 word2"))
        self.assertTrue(iutil.have_word_match("word1 word2", "word2word1 word3"))
        self.assertTrue(iutil.have_word_match("word2 word1", "word3 word1word2"))
        self.assertTrue(iutil.have_word_match("word1", "word1word2"))
        self.assertTrue(iutil.have_word_match("", "word1"))

        self.assertFalse(iutil.have_word_match("word3 word1", "word1"))
        self.assertFalse(iutil.have_word_match("word1 word3", "word1 word2"))
        self.assertFalse(iutil.have_word_match("word3 word2", "word1 word2"))
        self.assertFalse(iutil.have_word_match("word1word2", "word1 word2 word3"))
        self.assertFalse(iutil.have_word_match("word1", ""))
        self.assertFalse(iutil.have_word_match("word1", None))
        self.assertFalse(iutil.have_word_match(None, "word1"))
        self.assertFalse(iutil.have_word_match("", None))
        self.assertFalse(iutil.have_word_match(None, ""))
        self.assertFalse(iutil.have_word_match(None, None))

        # Compare unicode and str and make sure nothing crashes
        self.assertTrue(iutil.have_word_match("fête", u"fête champêtre"))
        self.assertTrue(iutil.have_word_match(u"fête", "fête champêtre"))
Ejemplo n.º 3
0
    def have_word_match_test(self):
        """Test have_word_match."""

        self.assertTrue(
            iutil.have_word_match("word1 word2", "word1 word2 word3"))
        self.assertTrue(
            iutil.have_word_match("word1 word2", "word2 word1 word3"))
        self.assertTrue(
            iutil.have_word_match("word2 word1", "word3 word1 word2"))
        self.assertTrue(iutil.have_word_match("word1", "word1 word2"))
        self.assertTrue(
            iutil.have_word_match("word1 word2", "word2word1 word3"))
        self.assertTrue(
            iutil.have_word_match("word2 word1", "word3 word1word2"))
        self.assertTrue(iutil.have_word_match("word1", "word1word2"))
        self.assertTrue(iutil.have_word_match("", "word1"))

        self.assertFalse(iutil.have_word_match("word3 word1", "word1"))
        self.assertFalse(iutil.have_word_match("word1 word3", "word1 word2"))
        self.assertFalse(iutil.have_word_match("word3 word2", "word1 word2"))
        self.assertFalse(
            iutil.have_word_match("word1word2", "word1 word2 word3"))
        self.assertFalse(iutil.have_word_match("word1", ""))
        self.assertFalse(iutil.have_word_match("word1", None))
        self.assertFalse(iutil.have_word_match(None, "word1"))
        self.assertFalse(iutil.have_word_match("", None))
        self.assertFalse(iutil.have_word_match(None, ""))
        self.assertFalse(iutil.have_word_match(None, None))

        # Compare designated unicode and "standard" unicode string and make sure nothing crashes
        self.assertTrue(iutil.have_word_match("fête", u"fête champêtre"))
        self.assertTrue(iutil.have_word_match(u"fête", "fête champêtre"))
Ejemplo n.º 4
0
    def have_word_match_test(self):
        """Test have_word_match."""

        self.assertTrue(iutil.have_word_match("word1 word2", "word1 word2 word3"))
        self.assertTrue(iutil.have_word_match("word1 word2", "word2 word1 word3"))
        self.assertTrue(iutil.have_word_match("word2 word1", "word3 word1 word2"))
        self.assertTrue(iutil.have_word_match("word1", "word1 word2"))
        self.assertTrue(iutil.have_word_match("word1 word2", "word2word1 word3"))
        self.assertTrue(iutil.have_word_match("word2 word1", "word3 word1word2"))
        self.assertTrue(iutil.have_word_match("word1", "word1word2"))
        self.assertTrue(iutil.have_word_match("", "word1"))

        self.assertFalse(iutil.have_word_match("word3 word1", "word1"))
        self.assertFalse(iutil.have_word_match("word1 word3", "word1 word2"))
        self.assertFalse(iutil.have_word_match("word3 word2", "word1 word2"))
        self.assertFalse(iutil.have_word_match("word1word2", "word1 word2 word3"))
        self.assertFalse(iutil.have_word_match("word1", ""))
        self.assertFalse(iutil.have_word_match("word1", None))
        self.assertFalse(iutil.have_word_match(None, "word1"))
        self.assertFalse(iutil.have_word_match("", None))
        self.assertFalse(iutil.have_word_match(None, ""))
        self.assertFalse(iutil.have_word_match(None, None))