#!/usr/bin/env python2.4 # -*- coding: UTF-8 -*- import py from mindex import mindex def setup_module(mod): mod.testpath = testpath = py.test.ensuretemp('qstest') mod.qs = qs = mindex(testpath) qs.index('/foo', 'foo bar baz qux quux') qs.index('/bar/baz', 'spam eggs spam spam and eggs') qs.index('/one', 'one two three four five six') qs.index('/somedoc', 'so some foo told the ones twenty-four times qux-qux') qs.index('/spiegel', 'Italien wählt. Das Ende einer Ära?') def teardown_module(mod): mod.testpath.remove() def test_basic(): assert qs.search(['foo']) in [['/foo', '/somedoc'], ['/somedoc', '/foo']] assert qs.search(['one']) == ['/one'] def test_order(): assert qs.search(['qux']) == ['/somedoc', '/foo'] def test_non_existent(): assert qs.search(['banana']) == [] def test_multi_and(): assert qs.search(['foo', 'bar']) == ['/foo'] def test_multi_or(): assert qs.search(['foo', 'bar'], False) == ['/foo', '/somedoc'] def test_multi_and_non_existent(): assert qs.search(['foo', 'bar', 'fruityboy']) == [] def test_nonascii(): assert qs.search(['wählt']) == ['/spiegel'] def test_wildcard(): assert qs.search(['f*']) in (['/somedoc', '/one', '/foo'], ['/one', '/somedoc', '/foo']) def test_wildcard_nomatch(): assert qs.search(['x*']) == [] def test_nested(): assert qs.search(['spam']) == ['/bar/baz'] def test_nested_parent_remove_failing(): qs.unindex('/bar') assert qs.search(['spam']) == ['/bar/baz'] def test_nested_remove(): qs.unindex('/bar/baz')