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