def test_docids(self): from hypatia._compat import u index = self._makeOne() index.index_doc(1, u('now is the time')) index.index_doc(2, u("l'ora \xe9 ora")) index.index_doc(3, u("you have nice hair.")) self.assertEqual(set(index.docids()), set((1, 2, 3)))
def test_applyNotContains(self): from hypatia._compat import u index = self._makeOne() index.index_doc(1, u('now is the time')) index.index_doc(2, u("l'ora \xe9 ora")) result = sorted(index.applyNotContains('time')) self.assertEqual(result, [2])
def test_applyNotContains_nothing_indexed(self): from hypatia._compat import u def discriminator(obj, default): return default index = self._makeOne(discriminator) index.index_doc(1, u('now is the time')) index.index_doc(2, u("l'ora \xe9 ora")) index.index_doc(3, 3) result = sorted(index.applyNotContains('time')) self.assertEqual(result, [1, 2, 3])
def test_document_repr(self): index = self._makeOne() # Fake out _get_frequencies, which is supposed to be overridden. def _faux_get_frequencies(wids): return dict([(y, x) for x, y in enumerate(wids)]), 1 index._get_frequencies = _faux_get_frequencies index.index_doc(1, u('one two \u00dcnic\u00f6de')) self.assertEqual(index.document_repr(1), u('one two \u00dcnic\u00f6de')) self.assertEqual(index.document_repr(50, True), True)
def test_applyNotContains_with_unindexed_doc(self): from hypatia._compat import u from hypatia._compat import string_types def discriminator(obj, default): if isinstance(obj, string_types): return obj return default index = self._makeOne(discriminator) index.index_doc(1, u('now is the time')) index.index_doc(2, u("l'ora \xe9 ora")) index.index_doc(3, 3) result = sorted(index.applyNotContains('time')) self.assertEqual(result, [2, 3])
def test_docids_with_indexed_and_not_indexed(self): from hypatia._compat import u index = self._makeOne() index.index_doc(1, u("Am I rich yet?")) index.index_doc(2, _marker) self.assertEqual(set([1, 2]), set(index.docids()))
def test_index_doc_missing_value_then_with_value(self): from hypatia._compat import u index = self._makeOne() index.index_doc(20, _marker) self.assertEqual(set(), set(index.applyContains('rich'))) self.assertTrue(20 in index.docids()) index.index_doc(20, u('Am I rich yet?')) self.assertEqual(set([20]), set(index.applyContains('rich'))) self.assertTrue(20 in index.docids())
def document_repr(self, docid, default=None): try: words = [] wids = self.get_words(docid) for wid in wids: words.append(self._lexicon.get_word(wid)) return u(' ').join(words) except KeyError: return default
def test_index_doc_then_missing_value(self): from hypatia._compat import u index = self._makeOne() index.index_doc(3, u("Am I rich yet?")) self.assertEqual(set([3]), set(index.applyContains("rich"))) self.assertTrue(3 in index.docids()) index.index_doc(3, _marker) self.assertEqual(set(), set(index.applyEq("rich"))) self.assertTrue(3 in index.docids())
def test_unicode(self): from hypatia._compat import u self.assertEqual(self._call_fut('u"foo"'), u("foo"))
def test_docids_with_indexed_and_not_indexed(self): from hypatia._compat import u index = self._makeOne() index.index_doc(1, u('Am I rich yet?')) index.index_doc(2, _marker) self.assertEqual(set([1, 2]), set(index.docids()))
def test_unicode(self): from hypatia._compat import u self.assertEqual(self._call_fut('u"foo"'), u('foo'))