chiark / gitweb /
Tests use 'api rtp' to avoid (harmless) error message
[disorder] / tests / search.py
CommitLineData
abf54aca 1#! /usr/bin/env python
de5ccb1a
RK
2#
3# This file is part of DisOrder.
3ece470d 4# Copyright (C) 2007, 2008 Richard Kettlewell
de5ccb1a 5#
e7eb3a27 6# This program is free software: you can redistribute it and/or modify
de5ccb1a 7# it under the terms of the GNU General Public License as published by
e7eb3a27 8# the Free Software Foundation, either version 3 of the License, or
de5ccb1a
RK
9# (at your option) any later version.
10#
e7eb3a27
RK
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
de5ccb1a 16# You should have received a copy of the GNU General Public License
e7eb3a27 17# along with this program. If not, see <http://www.gnu.org/licenses/>.
de5ccb1a
RK
18#
19import dtest,time,disorder,sys
20
21failures = 0
22
23def check_search_results(terms, expected):
24 global failures
25 # We want a consistent encoding and ordering
26 print "terms: %s" % terms
27 got = client.search(terms)
28 got = map(dtest.nfc, got)
29 expected = map(lambda s: "%s/%s" % (dtest.tracks, s), expected)
30 expected = map(dtest.nfc, expected)
31 got.sort()
32 expected.sort()
33 if got != expected:
34 print "expected: %s" % expected
35 print "got: %s" % got
36 print
37 failures += 1
38
39def test():
40 """Check that the search produces the right results"""
41 dtest.start_daemon()
f0feb22e 42 dtest.create_user()
f40beeb3 43 dtest.rescan()
de5ccb1a
RK
44 global client
45 client = disorder.client()
3c82b504
RK
46 first = ["Joe Bloggs/First Album/01:F\xC3\x8Crst track.ogg",
47 "Joe Bloggs/First Album/02:Second track.ogg",
48 "Joe Bloggs/First Album/03:ThI\xCC\x81rd track.ogg",
49 "Joe Bloggs/First Album/04:Fourth track.ogg",
50 "Joe Bloggs/First Album/05:Fifth track.ogg",
51 "Joe Bloggs/Second Album/01:First track.ogg",
52 "Joe Bloggs/Third Album/01:First_track.ogg"]
53 second = ["Joe Bloggs/First Album/02:Second track.ogg",
54 "Joe Bloggs/Second Album/01:First track.ogg",
55 "Joe Bloggs/Second Album/02:Second track.ogg",
56 "Joe Bloggs/Second Album/03:Third track.ogg",
57 "Joe Bloggs/Second Album/04:Fourth track.ogg",
58 "Joe Bloggs/Second Album/05:Fifth track.ogg",
59 "Joe Bloggs/Third Album/02:Second_track.ogg"]
60 third = ["Joe Bloggs/First Album/03:ThI\xCC\x81rd track.ogg",
61 "Joe Bloggs/Second Album/03:Third track.ogg",
62 "Joe Bloggs/Third Album/01:First_track.ogg",
63 "Joe Bloggs/Third Album/02:Second_track.ogg",
64 "Joe Bloggs/Third Album/03:Third_track.ogg",
65 "Joe Bloggs/Third Album/04:Fourth_track.ogg",
66 "Joe Bloggs/Third Album/05:Fifth_track.ogg"]
67 first_and_second = filter(lambda s: s in second, first)
de5ccb1a 68 # ASCII matches
3c82b504
RK
69 check_search_results(["first"], first)
70 check_search_results(["Second"], second)
71 check_search_results(["THIRD"], third)
de5ccb1a 72 # ASCII Conjunctions
3c82b504 73 check_search_results(["FIRST", "SECOND"], first_and_second)
351da565
RK
74 # Non-ASCII Characters
75 # 00CC is LATIN CAPITAL LETTER I WITH GRAVE
76 # 00EC is LATIN SMALL LETTER I WITH GRAVE
3c82b504
RK
77 check_search_results([u"F\u00CCRST"], first)
78 check_search_results([u"f\u00ECrst"], first)
df2cc2d8
RK
79 # 00CD is LATIN CAPITAL LETTER I WITH ACUTE
80 # 00ED is LATIN SMALL LETTER I WITH ACUTE
3c82b504
RK
81 check_search_results([u"TH\u00CDRD"], third)
82 check_search_results([u"th\u00EDrd"], third)
df2cc2d8
RK
83 # ...and again in denormalized form
84 # 0300 is COMBINING GRAVE ACCENT
85 # 0301 is COMBINING ACUTE ACCENT
3c82b504
RK
86 check_search_results([u"FI\u0300RST"], first)
87 check_search_results([u"fi\u0300rst"], first)
88 check_search_results([u"THI\u0301RD"], third)
89 check_search_results([u"thI\u0301rd"], third)
86be0c30 90 # stopwords shouldn't show up
91 check_search_results(["01"], [])
351da565 92
de5ccb1a
RK
93 if failures > 0:
94 sys.exit(1)
95
96if __name__ == '__main__':
97 dtest.run()