|
Revision 415, 1.5 KB
(checked in by matt, 7 months ago)
|
|
Work on NUMERIC, DATETIME, and BOOLEAN field types.
Changes instances of test_index to testindex.
|
| Line | |
|---|
| 1 | import unittest |
|---|
| 2 | |
|---|
| 3 | import os, random |
|---|
| 4 | |
|---|
| 5 | from whoosh import fields, index, writing |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | class TestWriting(unittest.TestCase): |
|---|
| 9 | def make_dir(self, name): |
|---|
| 10 | if not os.path.exists(name): |
|---|
| 11 | os.mkdir(name) |
|---|
| 12 | |
|---|
| 13 | def destroy_dir(self, name): |
|---|
| 14 | try: |
|---|
| 15 | os.rmdir("testindex") |
|---|
| 16 | except: |
|---|
| 17 | pass |
|---|
| 18 | |
|---|
| 19 | def clean_file(self, path): |
|---|
| 20 | if os.path.exists(path): |
|---|
| 21 | os.remove(path) |
|---|
| 22 | |
|---|
| 23 | def test_asyncwriter(self): |
|---|
| 24 | self.make_dir("testindex") |
|---|
| 25 | schema = fields.Schema(id=fields.ID, text=fields.TEXT) |
|---|
| 26 | ix = index.create_in("testindex", schema) |
|---|
| 27 | |
|---|
| 28 | domain = (u"alfa", u"bravo", u"charlie", u"delta", u"echo", u"foxtrot", u"golf", u"hotel", u"india") |
|---|
| 29 | |
|---|
| 30 | writers = [] |
|---|
| 31 | for i in xrange(20): |
|---|
| 32 | w = writing.AsyncWriter(ix.writer) |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | writers.append(w) |
|---|
| 37 | w.add_document(id=unicode(i), text=u" ".join(random.sample(domain, 5))) |
|---|
| 38 | w.commit() |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | for w in writers: |
|---|
| 42 | if w.running: |
|---|
| 43 | w.join() |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | r = ix.reader() |
|---|
| 47 | self.assertEqual(sorted([int(id) for id in r.lexicon("id")]), range(20)) |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | if __name__ == '__main__': |
|---|
| 52 | unittest.main() |
|---|