chiark / gitweb /
test search
[disorder] / tests / search.py
diff --git a/tests/search.py b/tests/search.py
new file mode 100755 (executable)
index 0000000..832a6d9
--- /dev/null
@@ -0,0 +1,72 @@
+#! /usr/bin/env python
+#
+# This file is part of DisOrder.
+# Copyright (C) 2007 Richard Kettlewell
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+#
+import dtest,time,disorder,sys
+
+failures = 0
+
+def check_search_results(terms, expected):
+    global failures
+    # We want a consistent encoding and ordering
+    print "terms:    %s" % terms
+    got = client.search(terms)
+    got = map(dtest.nfc, got)
+    expected = map(lambda s: "%s/%s" % (dtest.tracks, s), expected)
+    expected = map(dtest.nfc, expected)
+    got.sort()
+    expected.sort()
+    if got != expected:
+        print "expected: %s" % expected
+        print "got:      %s" % got
+        print
+        failures += 1
+
+def test():
+    """Check that the search produces the right results"""
+    dtest.start_daemon()
+    time.sleep(2)                       # give rescan a chance
+    global client
+    client = disorder.client()
+    # ASCII matches
+    check_search_results(["first"],
+                         ["Joe Bloggs/First Album/01:F\xC3\x8Crst track.ogg",
+                          "Joe Bloggs/First Album/02:Second track.ogg",
+                          "Joe Bloggs/First Album/03:ThI\xCC\x81rd track.ogg",
+                          "Joe Bloggs/First Album/04:Fourth track.ogg",
+                          "Joe Bloggs/First Album/05:Fifth track.ogg",
+                          "Joe Bloggs/Second Album/01:First track.ogg",
+                          "Joe Bloggs/Third Album/01:First_track.ogg"])
+    check_search_results(["second"],
+                         ["Joe Bloggs/First Album/02:Second track.ogg",
+                          "Joe Bloggs/Second Album/01:First track.ogg",
+                          "Joe Bloggs/Second Album/02:Second track.ogg",
+                          "Joe Bloggs/Second Album/03:Third track.ogg",
+                          "Joe Bloggs/Second Album/04:Fourth track.ogg",
+                          "Joe Bloggs/Second Album/05:Fifth track.ogg",
+                          "Joe Bloggs/Third Album/02:Second_track.ogg"])
+    # ASCII Conjunctions
+    check_search_results(["first", "second"],
+                         ["Joe Bloggs/First Album/02:Second track.ogg",
+                          "Joe Bloggs/Second Album/01:First track.ogg"])
+    if failures > 0:
+        sys.exit(1)
+
+if __name__ == '__main__':
+    dtest.run()