Added Land Shaymin (492-land.png) sprites.
[zzz-pokedex.git] / pokedex / tests / test_lookup.py
1 # encoding: utf8
2 from nose.tools import *
3 import unittest
4
5 import pokedex.lookup
6
7
8 def test_exact_lookup():
9 tests = [
10 # Simple lookups
11 (u'Eevee', 'pokemon', 133),
12 (u'Scratch', 'moves', 10),
13 (u'Master Ball', 'items', 1),
14 (u'normal', 'types', 1),
15 (u'Run Away', 'abilities', 50),
16
17 # Funny characters
18 (u'Mr. Mime', 'pokemon', 122),
19 (u"Farfetch'd", 'pokemon', 83),
20 (u'Poké Ball', 'items', 4),
21
22 # Forms
23 (u'Rotom', 'pokemon', 479),
24 (u'Wash Rotom', 'pokemon', 504),
25
26 # Other languages
27 (u'イーブイ', 'pokemon', 133),
28 (u'Iibui', 'pokemon', 133),
29 (u'Eievui', 'pokemon', 133),
30 (u'이브이', 'pokemon', 133),
31 (u'伊布', 'pokemon', 133),
32 (u'Evoli', 'pokemon', 133),
33 ]
34
35 for input, table, id in tests:
36 results = pokedex.lookup.lookup(input)
37 assert_equal(len(results), 1, u"'%s' returns one result" % input)
38 assert_equal(results[0].exact, True, u"'%s' match exactly" % input)
39
40 row = results[0].object
41 assert_equal(row.__tablename__, table, u"'%s' is in the right table" % input)
42 assert_equal(row.id, id, u"'%s' returns the right id" % input)
43
44
45 def test_id_lookup():
46 results = pokedex.lookup.lookup(u'1')
47 assert_true(len(results) >= 5, u'At least five things have id 1')
48 assert_true(all(_.object.id == 1 for _ in results),
49 u'All results have id 1')
50
51 def test_multi_lookup():
52 results = pokedex.lookup.lookup(u'Metronome')
53 assert_equal(len(results), 2, u'Two things called "Metronome"')
54 assert_true(results[0].exact, u'Metronome matches are exact')
55
56
57 def test_type_lookup():
58 results = pokedex.lookup.lookup(u'pokemon:1')
59 assert_equal(results[0].object.__tablename__, 'pokemon',
60 u'Type restriction works correctly')
61 assert_equal(len(results), 1, u'Only one id result when type is specified')
62 assert_equal(results[0].name, u'Bulbasaur', u'Type + id returns the right result')
63
64 results = pokedex.lookup.lookup(u'1', valid_types=['pokemon'])
65 assert_equal(results[0].name, u'Bulbasaur', u'valid_types works as well as type: prefix')
66
67 def test_fuzzy_lookup():
68 tests = [
69 # Regular English names
70 (u'chamander', u'Charmander'),
71 (u'pokeball', u'Poké Ball'),
72
73 # Names with squiggles in them
74 (u'farfetchd', u"Farfetch'd"),
75 (u'porygonz', u'Porygon-Z'),
76
77 # Sufficiently long foreign names
78 (u'カクレオ', u'Kecleon'),
79 (u'Yamikrasu', u'Murkrow'),
80 ]
81
82 for misspelling, name in tests:
83 results = pokedex.lookup.lookup(misspelling)
84 first_result = results[0]
85 assert_equal(first_result.object.name, name,
86 u'Simple misspellings are corrected')
87
88 results = pokedex.lookup.lookup(u'Nidoran')
89 top_names = [_.object.name for _ in results[0:2]]
90 assert_true(u'Nidoran♂' in top_names, u'Nidoran♂ is a top result for "Nidoran"')
91 assert_true(u'Nidoran♀' in top_names, u'Nidoran♀ is a top result for "Nidoran"')
92
93 def test_wildcard_lookup():
94 tests = [
95 (u'pokemon:*meleon', u'Charmeleon'),
96 (u'item:master*', u'Master Ball'),
97 (u'ee?ee', u'Eevee'),
98 ]
99
100 for wildcard, name in tests:
101 results = pokedex.lookup.lookup(wildcard)
102 first_result = results[0]
103 assert_equal(first_result.object.name, name,
104 u'Wildcards work correctly')
105
106 def test_random_lookup():
107 for _ in xrange(5):
108 results = pokedex.lookup.lookup(u'random')
109 assert_equal(len(results), 1, u'Random returns one result')
110
111 for table_name in [u'pokemon', u'moves', u'items', u'abilities', u'types']:
112 results = pokedex.lookup.lookup(u'random', valid_types=[table_name])
113 assert_equal(len(results), 1, u'Constrained random returns one result')
114 assert_equal(results[0].object.__tablename__, table_name,
115 u'Constrained random returns result from the right table')