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