Changeset 416

Show
Ignore:
Timestamp:
02/05/2010 11:32:32 AM (7 months ago)
Author:
matt
Message:

Added unit tests.

Location:
projects/whoosh/trunk/tests
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • projects/whoosh/trunk/tests/test_indexing.py

    r355 r416  
    224224        tr.close() 
    225225 
     226    def test_writer_delete(self): 
     227        s = fields.Schema(key=fields.ID(stored=True), value=fields.TEXT(stored=True)) 
     228        st = RamStorage() 
     229        ix = st.create_index(s) 
     230         
     231        w = ix.writer() 
     232        w.add_document(key=u"1", value=u"alfa") 
     233        w.add_document(key=u"2", value=u"bravo") 
     234        w.add_document(key=u"3", value=u"charlie") 
     235        w.commit() 
     236         
     237        s = ix.searcher() 
     238        self.assertEqual(s.document(key=u"1")["value"], "alfa") 
     239        self.assertEqual(s.document(key=u"2")["value"], "bravo") 
     240        self.assertEqual(s.document(key=u"3")["value"], "charlie") 
     241        s.close() 
     242         
     243        from whoosh.filedb.filewriting import OPTIMIZE 
     244        w = ix.writer() 
     245        w.delete_by_term("key", u"2") 
     246        w.commit(OPTIMIZE) 
     247         
     248        s = ix.searcher() 
     249        self.assertEqual(s.document(key=u"1")["value"], "alfa") 
     250        self.assertEqual(s.document(key=u"3")["value"], "charlie") 
     251        self.assertEqual(list(s.reader().lexicon("key")), ["1", "3"]) 
     252        s.close() 
     253 
    226254    def test_update(self): 
    227255        # Test update with multiple unique keys 
  • projects/whoosh/trunk/tests/test_writing.py

    r415 r416  
    11import unittest 
    22 
    3 import os, random 
     3import os, os.path, random 
    44 
    55from whoosh import fields, index, writing 
     
    2020        if os.path.exists(path): 
    2121            os.remove(path) 
     22     
     23    def clean_dir(self, path): 
     24        for filename in os.listdir(path): 
     25            os.remove(os.path.join(path, filename)) 
     26        os.rmdir(path) 
    2227     
    2328    def test_asyncwriter(self): 
     
    4651        r = ix.reader() 
    4752        self.assertEqual(sorted([int(id) for id in r.lexicon("id")]), range(20)) 
     53        r.close() 
     54        ix.close() 
    4855 
     56        self.clean_dir("test_index") 
    4957 
    5058