X-Git-Url: http://git.veekun.com/zzz-pokedex.git/blobdiff_plain/367f9d875282304de9c2390d5dbda410545226a2..8e3697d8cc803ba77326f63ae948fceb610bccc4:/pokedex/tests/test_lookup.py?ds=inline diff --git a/pokedex/tests/test_lookup.py b/pokedex/tests/test_lookup.py index 4a17265..a5c30c4 100644 --- a/pokedex/tests/test_lookup.py +++ b/pokedex/tests/test_lookup.py @@ -9,7 +9,8 @@ lookup = None def setup(): # Recreate data global lookup - lookup = PokedexLookup(recreate=True) + lookup = PokedexLookup() + lookup.rebuild_index() def test_exact_lookup(): tests = [ @@ -27,7 +28,8 @@ def test_exact_lookup(): # Forms (u'Rotom', 'pokemon', 479), - (u'Wash Rotom', 'pokemon', 504), + (u'Wash Rotom', 'pokemon_forms',10059), + (u'East Shellos', 'pokemon_forms',10039), # Other languages (u'イーブイ', 'pokemon', 133), @@ -65,10 +67,36 @@ def test_type_lookup(): assert_equal(results[0].object.__tablename__, 'pokemon', u'Type restriction works correctly') assert_equal(len(results), 1, u'Only one id result when type is specified') - assert_equal(results[0].name, u'Bulbasaur', u'Type + id returns the right result') + assert_equal(results[0].object.name, u'Bulbasaur', + u'Type + id returns the right result') results = lookup.lookup(u'1', valid_types=['pokemon']) - assert_equal(results[0].name, u'Bulbasaur', u'valid_types works as well as type: prefix') + assert_equal(results[0].object.name, u'Bulbasaur', + u'valid_types works as well as type: prefix') + +def test_language_lookup(): + # There are two objects named "charge": the move Charge, and the move + # Tackle, which is called "Charge" in French. + results = lookup.lookup(u'charge') + assert_true(len(results) > 1, u'There are multiple "charge"s') + + results = lookup.lookup(u'@fr:charge') + assert_equal(results[0].iso639, u'fr', u'Language restriction works correctly') + assert_equal(len(results), 1, u'Only one "charge" result when language is specified') + assert_equal(results[0].object.name, u'Tackle', + u'Language + vague name returns the right result') + + results = lookup.lookup(u'charge', valid_types=['@fr']) + assert_equal(results[0].object.name, u'Tackle', + u'valid_types works as well as @lang: prefix') + + results = lookup.lookup(u'@fr,move:charge') + assert_equal(results[0].object.name, u'Tackle', + u'Languages and types both work together') + + results = lookup.lookup(u'@fr:charge', valid_types=['move']) + assert_equal(results[0].object.name, u'Tackle', + u'valid_types and language prefixes get along') def test_fuzzy_lookup(): tests = [ @@ -119,3 +147,8 @@ def test_random_lookup(): assert_equal(len(results), 1, u'Constrained random returns one result') assert_equal(results[0].object.__tablename__, table_name, u'Constrained random returns result from the right table') + +def test_crash_empty_prefix(): + """Searching for ':foo' used to crash, augh!""" + results = lookup.lookup(u'Eevee') + assert_equal(results[0].object.name, u'Eevee', u'Empty prefix dun crash')