Skip to content

Commit

Permalink
Fixed tests on Python 2.7.
Browse files Browse the repository at this point in the history
Updated list of Pythons to test in tox.ini.
  • Loading branch information
mchaput committed Apr 17, 2015
1 parent 25ad665 commit 86a7920
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 36 deletions.
2 changes: 2 additions & 0 deletions src/whoosh/reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ def vector(self, docnum, fieldname, format_=None):
return self._perdoc.vector(docnum, fieldname, vformat)

def cursor(self, fieldname):
if self.is_closed:
raise ReaderClosed
fieldobj = self.schema[fieldname]
return self._terms.cursor(fieldname, fieldobj)

Expand Down
38 changes: 19 additions & 19 deletions tests/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,38 +173,38 @@ def test_termdocs():
schema = fields.Schema(key=fields.TEXT, city=fields.ID)
ix = RamStorage().create_index(schema)
with ix.writer() as w:
w.add_document(key="ant", city="london")
w.add_document(key="anteater", city="roma")
w.add_document(key="bear", city="london")
w.add_document(key="bees", city="roma")
w.add_document(key="anorak", city="london")
w.add_document(key="antimatter", city="roma")
w.add_document(key="angora", city="london")
w.add_document(key="angels", city="roma")
w.add_document(key=u"ant", city=u"london")
w.add_document(key=u"anteater", city=u"roma")
w.add_document(key=u"bear", city=u"london")
w.add_document(key=u"bees", city=u"roma")
w.add_document(key=u"anorak", city=u"london")
w.add_document(key=u"antimatter", city=u"roma")
w.add_document(key=u"angora", city=u"london")
w.add_document(key=u"angels", city=u"roma")

with ix.searcher() as s:
cond_q = query.Term("city", "london")
pref_q = query.Prefix("key", "an")
cond_q = query.Term("city", u"london")
pref_q = query.Prefix("key", u"an")
q = query.And([cond_q, pref_q]).normalize()
r = s.search(q, scored=False, terms=True)

field = s.schema["key"]
terms = [field.from_bytes(term) for fieldname, term in r.termdocs
if fieldname == "key"]
assert sorted(terms) == ["angora", "anorak", "ant"]
assert sorted(terms) == [u"angora", u"anorak", u"ant"]

def test_termdocs2():
schema = fields.Schema(key=fields.TEXT, city=fields.ID)
ix = RamStorage().create_index(schema)
with ix.writer() as w:
w.add_document(key="ant", city="london")
w.add_document(key="anteater", city="roma")
w.add_document(key="bear", city="london")
w.add_document(key="bees", city="roma")
w.add_document(key="anorak", city="london")
w.add_document(key="antimatter", city="roma")
w.add_document(key="angora", city="london")
w.add_document(key="angels", city="roma")
w.add_document(key=u"ant", city=u"london")
w.add_document(key=u"anteater", city=u"roma")
w.add_document(key=u"bear", city=u"london")
w.add_document(key=u"bees", city=u"roma")
w.add_document(key=u"anorak", city=u"london")
w.add_document(key=u"antimatter", city=u"roma")
w.add_document(key=u"angora", city=u"london")
w.add_document(key=u"angels", city=u"roma")

with ix.searcher() as s:
# A query that matches the applicable documents
Expand Down
10 changes: 5 additions & 5 deletions tests/test_nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ def test_nested_skip():
)

domain = [
("book_1", "The Dark Knight Returns", "book"),
("chapter_1", "The Dark Knight Returns", "chapter"),
("chapter_2", "The Dark Knight Triumphant", "chapter"),
("chapter_3", "Hunt the Dark Knight", "chapter"),
("chapter_4", "The Dark Knight Falls", "chapter")
(u"book_1", u"The Dark Knight Returns", u"book"),
(u"chapter_1", u"The Dark Knight Returns", u"chapter"),
(u"chapter_2", u"The Dark Knight Triumphant", u"chapter"),
(u"chapter_3", u"Hunt the Dark Knight", u"chapter"),
(u"chapter_4", u"The Dark Knight Falls", u"chapter")
]

with TempIndex(schema) as ix:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def test_numeric_filter():

# Add a single document with status = -2
with ix.writer() as w:
w.add_document(status=-2, tags="alfa bravo")
w.add_document(status=-2, tags=u"alfa bravo")

with ix.searcher() as s:
# No document should match the filter
Expand All @@ -565,7 +565,7 @@ def test_numeric_filter():
assert fr.scored_length() == 0

# Make sure the query would otherwise match
q = query.Term("tags", "alfa")
q = query.Term("tags", u"alfa")
r = s.search(q)
assert r.scored_length() == 1

Expand Down
10 changes: 5 additions & 5 deletions tests/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,11 @@ def test_closed_searcher():
with TempStorage() as st:
ix = st.create_index(schema)
with ix.writer() as w:
w.add_document(key=u("alfa"))
w.add_document(key=u("bravo"))
w.add_document(key=u("charlie"))
w.add_document(key=u("delta"))
w.add_document(key=u("echo"))
w.add_document(key=u"alfa")
w.add_document(key=u"bravo")
w.add_document(key=u"charlie")
w.add_document(key=u"delta")
w.add_document(key=u"echo")

s = ix.searcher()
r = s.search(query.TermRange("key", "b", "d"))
Expand Down
8 changes: 4 additions & 4 deletions tests/test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ def test_vector_unicode():
schema = fields.Schema(id=fields.NUMERIC, text=cf)
with TempIndex(schema) as ix:
with ix.writer() as w:
w.add_document(id=0, text="\u13a0\u13a1\u13a2 \u13a3\u13a4\u13a5")
w.add_document(id=1, text="\u13a6\u13a7\u13a8 \u13a9\u13aa\u13ab")
w.add_document(id=0, text=u"\u13a0\u13a1\u13a2 \u13a3\u13a4\u13a5")
w.add_document(id=1, text=u"\u13a6\u13a7\u13a8 \u13a9\u13aa\u13ab")

with ix.writer() as w:
w.add_document(id=2, text="\u13ac\u13ad\u13ae \u13af\u13b0\u13b1")
w.add_document(id=3, text="\u13b2\u13b3\u13b4 \u13b5\u13b6\u13b7")
w.add_document(id=2, text=u"\u13ac\u13ad\u13ae \u13af\u13b0\u13b1")
w.add_document(id=3, text=u"\u13b2\u13b3\u13b4 \u13b5\u13b6\u13b7")

with ix.searcher() as s:
docnum = s.document_number(id=2)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py25, py27, py32, py33
envlist = py27, py33, py34

[testenv]
deps =
Expand Down

0 comments on commit 86a7920

Please sign in to comment.