2 from nose
.tools
import *
5 from pokedex
.lookup
import PokedexLookup
12 lookup
= PokedexLookup()
13 lookup
.rebuild_index()
15 def test_exact_lookup():
18 (u
'Eevee', 'pokemon', 133),
19 (u
'Scratch', 'moves', 10),
20 (u
'Master Ball', 'items', 1),
21 (u
'normal', 'types', 1),
22 (u
'Run Away', 'abilities', 50),
25 (u
'Mr. Mime', 'pokemon', 122),
26 (u
"Farfetch'd", 'pokemon', 83),
27 (u
'Poké Ball', 'items', 4),
30 (u
'Rotom', 'pokemon', 479),
31 (u
'Wash Rotom', 'pokemon', 504),
34 (u
'イーブイ', 'pokemon', 133),
35 (u
'Iibui', 'pokemon', 133),
36 (u
'Eievui', 'pokemon', 133),
37 (u
'이브이', 'pokemon', 133),
38 (u
'伊布', 'pokemon', 133),
39 (u
'Evoli', 'pokemon', 133),
42 for input, table
, id in tests
:
43 results
= lookup
.lookup(input)
44 assert_equal(len(results
), 1, u
"'%s' returns one result" % input
)
45 assert_equal(results
[0].exact
, True, u
"'%s' match exactly" % input
)
47 row
= results
[0].object
48 assert_equal(row
.__tablename__
, table
, u
"'%s' is in the right table" % input
)
49 assert_equal(row
.id, id, u
"'%s' returns the right id" % input
)
53 results
= lookup
.lookup(u
'1')
54 assert_true(len(results
) >= 5, u
'At least five things have id 1')
55 assert_true(all(_
.object.id == 1 for _
in results
),
56 u
'All results have id 1')
58 def test_multi_lookup():
59 results
= lookup
.lookup(u
'Metronome')
60 assert_equal(len(results
), 2, u
'Two things called "Metronome"')
61 assert_true(results
[0].exact
, u
'Metronome matches are exact')
64 def test_type_lookup():
65 results
= lookup
.lookup(u
'pokemon:1')
66 assert_equal(results
[0].object.__tablename__
, 'pokemon',
67 u
'Type restriction works correctly')
68 assert_equal(len(results
), 1, u
'Only one id result when type is specified')
69 assert_equal(results
[0].name
, u
'Bulbasaur', u
'Type + id returns the right result')
71 results
= lookup
.lookup(u
'1', valid_types
=['pokemon'])
72 assert_equal(results
[0].name
, u
'Bulbasaur', u
'valid_types works as well as type: prefix')
74 def test_fuzzy_lookup():
76 # Regular English names
77 (u
'chamander', u
'Charmander'),
78 (u
'pokeball', u
'Poké Ball'),
80 # Names with squiggles in them
81 (u
'farfetchd', u
"Farfetch'd"),
82 (u
'porygonz', u
'Porygon-Z'),
84 # Sufficiently long foreign names
85 (u
'カクレオ', u
'Kecleon'),
86 (u
'Yamikrasu', u
'Murkrow'),
89 for misspelling
, name
in tests
:
90 results
= lookup
.lookup(misspelling
)
91 first_result
= results
[0]
92 assert_equal(first_result
.object.name
, name
,
93 u
'Simple misspellings are corrected')
95 results
= lookup
.lookup(u
'Nidoran')
96 top_names
= [_
.object.name
for _
in results
[0:2]]
97 assert_true(u
'Nidoran♂' in top_names
, u
'Nidoran♂ is a top result for "Nidoran"')
98 assert_true(u
'Nidoran♀' in top_names
, u
'Nidoran♀ is a top result for "Nidoran"')
100 def test_wildcard_lookup():
102 (u
'pokemon:*meleon', u
'Charmeleon'),
103 (u
'item:master*', u
'Master Ball'),
104 (u
'ee?ee', u
'Eevee'),
107 for wildcard
, name
in tests
:
108 results
= lookup
.lookup(wildcard
)
109 first_result
= results
[0]
110 assert_equal(first_result
.object.name
, name
,
111 u
'Wildcards work correctly')
113 def test_random_lookup():
115 results
= lookup
.lookup(u
'random')
116 assert_equal(len(results
), 1, u
'Random returns one result')
118 for table_name
in [u
'pokemon', u
'moves', u
'items', u
'abilities', u
'types']:
119 results
= lookup
.lookup(u
'random', valid_types
=[table_name
])
120 assert_equal(len(results
), 1, u
'Constrained random returns one result')
121 assert_equal(results
[0].object.__tablename__
, table_name
,
122 u
'Constrained random returns result from the right table')