2011-05-02 07:20:28 +00:00
|
|
|
# Encoding: UTF-8
|
2009-08-24 03:43:39 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
import pytest
|
|
|
|
parametrize = pytest.mark.parametrize
|
2009-08-24 03:43:39 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
@parametrize(
|
|
|
|
('input', 'table', 'id'),
|
|
|
|
[
|
2009-08-24 03:43:39 +00:00
|
|
|
# Simple lookups
|
2011-04-29 23:14:34 +00:00
|
|
|
(u'Eevee', 'pokemon_species',133),
|
2009-08-24 03:43:39 +00:00
|
|
|
(u'Scratch', 'moves', 10),
|
|
|
|
(u'Master Ball', 'items', 1),
|
|
|
|
(u'normal', 'types', 1),
|
|
|
|
(u'Run Away', 'abilities', 50),
|
|
|
|
|
|
|
|
# Funny characters
|
2011-04-29 23:14:34 +00:00
|
|
|
(u'Mr. Mime', 'pokemon_species', 122),
|
|
|
|
(u"Farfetch'd", 'pokemon_species', 83),
|
|
|
|
(u'Poké Ball', 'items', 4),
|
2009-08-24 03:43:39 +00:00
|
|
|
|
|
|
|
# Forms
|
2011-04-29 23:14:34 +00:00
|
|
|
(u'Rotom', 'pokemon_species', 479),
|
2013-11-09 08:49:09 +00:00
|
|
|
(u'Wash Rotom', 'pokemon_forms', 10059),
|
|
|
|
(u'East Shellos', 'pokemon_forms', 10039),
|
2009-08-24 03:43:39 +00:00
|
|
|
|
|
|
|
# Other languages
|
2011-04-29 23:14:34 +00:00
|
|
|
(u'イーブイ', 'pokemon_species', 133),
|
|
|
|
(u'Iibui', 'pokemon_species', 133),
|
|
|
|
(u'Eievui', 'pokemon_species', 133),
|
|
|
|
(u'이브이', 'pokemon_species', 133),
|
|
|
|
(u'伊布', 'pokemon_species', 133),
|
|
|
|
(u'Evoli', 'pokemon_species', 133),
|
2014-07-07 03:25:04 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
def test_exact_lookup(lookup, input, table, id):
|
2011-05-02 07:20:28 +00:00
|
|
|
results = lookup.lookup(input)
|
|
|
|
assert len(results) == 1
|
|
|
|
assert results[0].exact == True
|
2009-08-24 03:43:39 +00:00
|
|
|
|
2011-05-02 07:20:28 +00:00
|
|
|
row = results[0].object
|
|
|
|
assert row.__tablename__ == table
|
|
|
|
assert row.id == id
|
2009-08-24 03:43:39 +00:00
|
|
|
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_id_lookup(lookup):
|
2010-03-29 05:14:27 +00:00
|
|
|
results = lookup.lookup(u'1')
|
2011-05-02 07:20:28 +00:00
|
|
|
assert len(results) >= 5
|
|
|
|
assert all(result.object.id == 1 for result in results)
|
|
|
|
|
2009-08-24 03:43:39 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_multi_lookup(lookup):
|
2010-03-29 05:14:27 +00:00
|
|
|
results = lookup.lookup(u'Metronome')
|
2011-05-02 07:20:28 +00:00
|
|
|
assert len(results) == 2
|
|
|
|
assert results[0].exact
|
2009-08-24 03:43:39 +00:00
|
|
|
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_type_lookup(lookup):
|
2010-03-29 05:14:27 +00:00
|
|
|
results = lookup.lookup(u'pokemon:1')
|
2011-05-02 07:20:28 +00:00
|
|
|
assert results[0].object.__tablename__ == 'pokemon_species'
|
|
|
|
assert len(results) == 1
|
|
|
|
assert results[0].object.name == u'Bulbasaur'
|
2009-08-24 03:43:39 +00:00
|
|
|
|
2011-04-29 23:14:34 +00:00
|
|
|
results = lookup.lookup(u'1', valid_types=['pokemon_species'])
|
2011-05-02 07:20:28 +00:00
|
|
|
assert results[0].object.name == u'Bulbasaur'
|
|
|
|
|
2009-08-24 03:43:39 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_language_lookup(lookup):
|
2010-08-25 03:06:40 +00:00
|
|
|
# There are two objects named "charge": the move Charge, and the move
|
|
|
|
# Tackle, which is called "Charge" in French.
|
|
|
|
results = lookup.lookup(u'charge')
|
2011-05-02 07:20:28 +00:00
|
|
|
assert len(results) > 1
|
2010-08-25 03:06:40 +00:00
|
|
|
|
|
|
|
results = lookup.lookup(u'@fr:charge')
|
2011-05-02 07:20:28 +00:00
|
|
|
assert results[0].iso639 == u'fr'
|
|
|
|
assert len(results) == 1
|
|
|
|
assert results[0].object.name == u'Tackle'
|
2010-08-25 03:06:40 +00:00
|
|
|
|
|
|
|
results = lookup.lookup(u'charge', valid_types=['@fr'])
|
2011-05-02 07:20:28 +00:00
|
|
|
assert results[0].object.name == u'Tackle'
|
2010-08-25 03:06:40 +00:00
|
|
|
|
|
|
|
results = lookup.lookup(u'@fr,move:charge')
|
2011-05-02 07:20:28 +00:00
|
|
|
assert results[0].object.name == u'Tackle'
|
2010-08-25 03:06:40 +00:00
|
|
|
|
2010-08-25 04:21:29 +00:00
|
|
|
results = lookup.lookup(u'@fr:charge', valid_types=['move'])
|
2011-05-02 07:20:28 +00:00
|
|
|
assert results[0].object.name, u'Tackle'
|
2010-08-25 04:21:29 +00:00
|
|
|
|
2011-05-02 07:20:28 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
@parametrize(
|
|
|
|
('misspelling', 'name'),
|
|
|
|
[
|
2009-08-24 03:43:39 +00:00
|
|
|
# Regular English names
|
|
|
|
(u'chamander', u'Charmander'),
|
|
|
|
(u'pokeball', u'Poké Ball'),
|
|
|
|
|
|
|
|
# Names with squiggles in them
|
|
|
|
(u'farfetchd', u"Farfetch'd"),
|
|
|
|
(u'porygonz', u'Porygon-Z'),
|
|
|
|
|
|
|
|
# Sufficiently long foreign names
|
|
|
|
(u'カクレオ', u'Kecleon'),
|
|
|
|
(u'Yamikrasu', u'Murkrow'),
|
2014-07-07 03:25:04 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
def test_fuzzy_lookup(lookup, misspelling, name):
|
2011-05-02 07:20:28 +00:00
|
|
|
results = lookup.lookup(misspelling)
|
|
|
|
first_result = results[0]
|
|
|
|
assert first_result.object.name == name
|
2009-08-24 03:43:39 +00:00
|
|
|
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_nidoran(lookup):
|
2010-03-29 05:14:27 +00:00
|
|
|
results = lookup.lookup(u'Nidoran')
|
2011-05-02 07:20:28 +00:00
|
|
|
top_names = [result.object.name for result in results[0:2]]
|
|
|
|
assert u'Nidoran♂' in top_names
|
|
|
|
assert u'Nidoran♀' in top_names
|
|
|
|
|
2009-08-25 05:04:55 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
@parametrize(
|
|
|
|
('wildcard', 'name'),
|
|
|
|
[
|
2009-08-25 05:04:55 +00:00
|
|
|
(u'pokemon:*meleon', u'Charmeleon'),
|
|
|
|
(u'item:master*', u'Master Ball'),
|
|
|
|
(u'ee?ee', u'Eevee'),
|
2014-07-07 03:25:04 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
def test_wildcard_lookup(lookup, wildcard, name):
|
2011-05-02 07:20:28 +00:00
|
|
|
results = lookup.lookup(wildcard)
|
|
|
|
first_result = results[0]
|
|
|
|
assert first_result.object.name == name
|
2009-08-25 05:04:55 +00:00
|
|
|
|
2009-08-25 05:59:39 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_bare_random(lookup):
|
2011-05-02 07:20:28 +00:00
|
|
|
for i in range(5):
|
2010-03-29 05:14:27 +00:00
|
|
|
results = lookup.lookup(u'random')
|
2011-05-02 07:20:28 +00:00
|
|
|
assert len(results) == 1
|
|
|
|
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
@parametrize(
|
|
|
|
'table_name',
|
|
|
|
[
|
|
|
|
u'pokemon_species',
|
|
|
|
u'moves',
|
|
|
|
u'items',
|
|
|
|
u'abilities',
|
|
|
|
u'types'
|
|
|
|
]
|
|
|
|
)
|
|
|
|
def test_qualified_random(lookup, table_name):
|
2011-05-02 07:20:28 +00:00
|
|
|
results = lookup.lookup(u'random', valid_types=[table_name])
|
|
|
|
assert len(results) == 1
|
|
|
|
assert results[0].object.__tablename__ == table_name
|
2009-08-25 05:59:39 +00:00
|
|
|
|
2010-09-13 04:08:50 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_crash_empty_prefix(lookup):
|
2010-09-13 04:08:50 +00:00
|
|
|
"""Searching for ':foo' used to crash, augh!"""
|
2011-03-12 15:30:15 +00:00
|
|
|
results = lookup.lookup(u':Eevee')
|
2011-05-02 07:20:28 +00:00
|
|
|
assert results[0].object.name == u'Eevee'
|