mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Fixed lookup tests to, um, run.
This commit is contained in:
parent
d995942b4f
commit
82e797c6d0
3 changed files with 20 additions and 22 deletions
|
@ -143,7 +143,7 @@ class PokedexLookup(object):
|
|||
# especially when e.g. German names are very similar to English names
|
||||
speller_entries = []
|
||||
for cls in self.indexed_tables.values():
|
||||
q = session.query(cls)
|
||||
q = self.session.query(cls)
|
||||
|
||||
for row in q.yield_per(5):
|
||||
row_key = dict(table=unicode(cls.__tablename__),
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from pokedex.lookup import open_index
|
||||
from pokedex.db import connect
|
||||
from pokedex.db.load import load
|
||||
|
||||
def setup():
|
||||
# Reload data just in case
|
||||
session = connect()
|
||||
open_index(session=session, recreate=True)
|
||||
|
||||
# XXX This needs to recreate the database, someday. :(
|
||||
pass
|
||||
|
||||
def teardown():
|
||||
pass
|
||||
|
|
|
@ -2,8 +2,14 @@
|
|||
from nose.tools import *
|
||||
import unittest
|
||||
|
||||
import pokedex.lookup
|
||||
from pokedex.lookup import PokedexLookup
|
||||
|
||||
lookup = None
|
||||
|
||||
def setup():
|
||||
# Recreate data
|
||||
global lookup
|
||||
lookup = PokedexLookup(recreate=True)
|
||||
|
||||
def test_exact_lookup():
|
||||
tests = [
|
||||
|
@ -33,7 +39,7 @@ def test_exact_lookup():
|
|||
]
|
||||
|
||||
for input, table, id in tests:
|
||||
results = pokedex.lookup.lookup(input)
|
||||
results = lookup.lookup(input)
|
||||
assert_equal(len(results), 1, u"'%s' returns one result" % input)
|
||||
assert_equal(results[0].exact, True, u"'%s' match exactly" % input)
|
||||
|
||||
|
@ -43,25 +49,25 @@ def test_exact_lookup():
|
|||
|
||||
|
||||
def test_id_lookup():
|
||||
results = pokedex.lookup.lookup(u'1')
|
||||
results = lookup.lookup(u'1')
|
||||
assert_true(len(results) >= 5, u'At least five things have id 1')
|
||||
assert_true(all(_.object.id == 1 for _ in results),
|
||||
u'All results have id 1')
|
||||
|
||||
def test_multi_lookup():
|
||||
results = pokedex.lookup.lookup(u'Metronome')
|
||||
results = lookup.lookup(u'Metronome')
|
||||
assert_equal(len(results), 2, u'Two things called "Metronome"')
|
||||
assert_true(results[0].exact, u'Metronome matches are exact')
|
||||
|
||||
|
||||
def test_type_lookup():
|
||||
results = pokedex.lookup.lookup(u'pokemon:1')
|
||||
results = lookup.lookup(u'pokemon:1')
|
||||
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')
|
||||
|
||||
results = pokedex.lookup.lookup(u'1', valid_types=['pokemon'])
|
||||
results = lookup.lookup(u'1', valid_types=['pokemon'])
|
||||
assert_equal(results[0].name, u'Bulbasaur', u'valid_types works as well as type: prefix')
|
||||
|
||||
def test_fuzzy_lookup():
|
||||
|
@ -80,12 +86,12 @@ def test_fuzzy_lookup():
|
|||
]
|
||||
|
||||
for misspelling, name in tests:
|
||||
results = pokedex.lookup.lookup(misspelling)
|
||||
results = lookup.lookup(misspelling)
|
||||
first_result = results[0]
|
||||
assert_equal(first_result.object.name, name,
|
||||
u'Simple misspellings are corrected')
|
||||
|
||||
results = pokedex.lookup.lookup(u'Nidoran')
|
||||
results = lookup.lookup(u'Nidoran')
|
||||
top_names = [_.object.name for _ in results[0:2]]
|
||||
assert_true(u'Nidoran♂' in top_names, u'Nidoran♂ is a top result for "Nidoran"')
|
||||
assert_true(u'Nidoran♀' in top_names, u'Nidoran♀ is a top result for "Nidoran"')
|
||||
|
@ -98,18 +104,18 @@ def test_wildcard_lookup():
|
|||
]
|
||||
|
||||
for wildcard, name in tests:
|
||||
results = pokedex.lookup.lookup(wildcard)
|
||||
results = lookup.lookup(wildcard)
|
||||
first_result = results[0]
|
||||
assert_equal(first_result.object.name, name,
|
||||
u'Wildcards work correctly')
|
||||
|
||||
def test_random_lookup():
|
||||
for _ in xrange(5):
|
||||
results = pokedex.lookup.lookup(u'random')
|
||||
results = lookup.lookup(u'random')
|
||||
assert_equal(len(results), 1, u'Random returns one result')
|
||||
|
||||
for table_name in [u'pokemon', u'moves', u'items', u'abilities', u'types']:
|
||||
results = pokedex.lookup.lookup(u'random', valid_types=[table_name])
|
||||
results = lookup.lookup(u'random', valid_types=[table_name])
|
||||
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')
|
||||
|
|
Loading…
Reference in a new issue