1
0
Fork 0
mirror of https://github.com/veekun/pokedex.git synced 2024-08-20 18:16:34 +00:00

Modernize our use of py.test

This commit updates the tests to take advantage of some of py.test's
newer features.  Requires py.test 2.3 or newer.  Tested with 2.3.0 and
2.5.2.

Tests which were parametrized now use py.test's built-in
parametrization[1].

The session and lookup objects are now implemented as fixtures[2].
The media root is a fixture as well.  Fixtures are automatically passed
to any function that expects them.

Since the session is now created in one place, it is now possible to
provide an engine URI on the command line when running py.test.  Ditto
for the index directory.  (But the environment variables still work of
course.)

Slow tests are now marked as such and not run unless the --all option is
given.

A couple media tests are marked as xfail (expected to fail) because they
are broken.

[1]: http://pytest.org/latest/parametrize.html
[2]: http://pytest.org/latest/fixture.html
This commit is contained in:
Andrew Ekstedt 2014-07-06 20:25:04 -07:00
parent 29824c73f4
commit 0094e9584c
10 changed files with 285 additions and 299 deletions
pokedex/tests

View file

@ -1,49 +1,47 @@
# Encoding: utf8
import pytest
parametrize = pytest.mark.parametrize
from pokedex.tests import single_params
from pokedex.db import connect, tables, util
session = connect()
def test_get_item_identifier():
def test_get_item_identifier(session):
item = util.get(session, tables.Item, identifier='master-ball')
assert item.name == 'Master Ball'
def test_get_item_name():
def test_get_item_name(session):
item = util.get(session, tables.Item, name='Awakening')
assert item.name == 'Awakening'
def test_get_english_by_identifier():
def test_get_english_by_identifier(session):
language = util.get(session, tables.Language, 'en')
assert language.name == 'English'
@single_params(*'burmy shaymin unown cresselia'.split())
def test_get_pokemon_identifier(identifier):
@parametrize('identifier', ['burmy', 'shaymin', 'unown', 'cresselia'])
def test_get_pokemon_identifier(session, identifier):
poke = util.get(session, tables.PokemonSpecies, identifier=identifier)
assert poke.identifier == identifier
@single_params(*'Burmy Shaymin Unown Cresselia'.split())
def test_get_pokemon_name(name):
@parametrize('name', ['Burmy', 'Shaymin', 'Unown', 'Cresselia'])
def test_get_pokemon_name(session, name):
poke = util.get(session, tables.PokemonSpecies, name=name)
assert poke.name == name
@single_params(*'Cheniti Shaymin Zarbi Cresselia'.split())
def test_get_pokemon_name_explicit_language(name):
@parametrize('name', ['Cheniti', 'Shaymin', 'Zarbi', 'Cresselia'])
def test_get_pokemon_name_explicit_language(session, name):
french = util.get(session, tables.Language, 'fr')
poke = util.get(session, tables.PokemonSpecies, name=name, language=french)
assert poke.name_map[french] == name, poke.name_map[french]
def test_types_french_order():
def test_types_french_order(session):
french = util.get(session, tables.Language, 'fr')
types = session.query(tables.Type).filter(tables.Type.id < 10000)
types = list(util.order_by_name(types, tables.Type, language=french))
assert types[0].name_map[french] == 'Acier', types[0].name_map[french]
assert types[-1].name_map[french] == 'Vol', types[-1].name_map[french]
@single_params(*range(1, 10) * 2)
def test_get_pokemon_id(id):
@parametrize('id', range(1, 10))
def test_get_pokemon_id(session, id):
result = util.get(session, tables.Pokemon, id=id)
assert result.id == id
assert result.__tablename__ == 'pokemon'