2 from nose
.tools
import *
8 def test_exact_lookup():
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),
18 (u
'Mr. Mime', 'pokemon', 122),
19 (u
"Farfetch'd", 'pokemon', 83),
20 (u
'Poké Ball', 'items', 4),
23 (u
'Rotom', 'pokemon', 479),
24 (u
'Wash Rotom', 'pokemon', 504),
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),
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
)
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
)
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')
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')
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')
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')
67 def test_fuzzy_lookup():
69 # Regular English names
70 (u
'chamander', u
'Charmander'),
71 (u
'pokeball', u
'Poké Ball'),
73 # Names with squiggles in them
74 (u
'farfetchd', u
"Farfetch'd"),
75 (u
'porygonz', u
'Porygon-Z'),
77 # Sufficiently long foreign names
78 (u
'カクレオ', u
'Kecleon'),
79 (u
'Yamikrasu', u
'Murkrow'),
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')
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"')