2011-04-09 15:20:58 +00:00
|
|
|
"""Test the media accessors.
|
|
|
|
|
|
|
|
If run directly from the command line, also tests the accessors and the names
|
|
|
|
of all the media by getting just about everything in a naive brute-force way.
|
|
|
|
This, of course, takes a lot of time to run.
|
|
|
|
"""
|
|
|
|
|
2011-05-02 07:20:28 +00:00
|
|
|
import pytest
|
|
|
|
|
2011-04-09 15:20:58 +00:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
from pokedex.db import tables
|
2011-04-18 05:35:24 +00:00
|
|
|
from pokedex.util import media
|
2011-04-09 15:20:58 +00:00
|
|
|
|
|
|
|
path_re = re.compile('^[-a-z0-9./]*$')
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_totodile(session, media_root):
|
2011-04-09 15:20:58 +00:00
|
|
|
"""Totodile's female sprite -- same as male"""
|
2011-04-30 00:21:37 +00:00
|
|
|
totodile = session.query(tables.PokemonSpecies).filter_by(identifier=u'totodile').one()
|
2014-07-07 03:25:04 +00:00
|
|
|
accessor = media.PokemonSpeciesMedia(media_root, totodile)
|
2011-04-09 15:20:58 +00:00
|
|
|
assert accessor.sprite() == accessor.sprite(female=True)
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_chimecho(session, media_root):
|
2011-04-09 15:20:58 +00:00
|
|
|
"""Chimecho's Platinum female backsprite -- diffeent from male"""
|
2011-04-30 00:21:37 +00:00
|
|
|
chimecho = session.query(tables.PokemonSpecies).filter_by(identifier=u'chimecho').one()
|
2014-07-07 03:25:04 +00:00
|
|
|
accessor = media.PokemonSpeciesMedia(media_root, chimecho)
|
2011-04-09 15:20:58 +00:00
|
|
|
male = accessor.sprite('platinum', back=True, frame=2)
|
|
|
|
female = accessor.sprite('platinum', back=True, female=True, frame=2)
|
|
|
|
assert male != female
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_venonat(session, media_root):
|
2011-04-09 15:20:58 +00:00
|
|
|
"""Venonat's shiny Yellow sprite -- same as non-shiny"""
|
2011-04-30 00:21:37 +00:00
|
|
|
venonat = session.query(tables.PokemonSpecies).filter_by(identifier=u'venonat').one()
|
2014-07-07 03:25:04 +00:00
|
|
|
accessor = media.PokemonSpeciesMedia(media_root, venonat)
|
2011-04-09 15:20:58 +00:00
|
|
|
assert accessor.sprite('yellow') == accessor.sprite('yellow', shiny=True)
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
@pytest.mark.xfail
|
|
|
|
def test_arceus_icon(session, media_root):
|
|
|
|
"""Arceus normal-form icon -- same as base icon"""
|
2011-04-30 00:21:37 +00:00
|
|
|
arceus = session.query(tables.PokemonSpecies).filter_by(identifier=u'arceus').one()
|
2014-07-07 03:25:04 +00:00
|
|
|
accessor = media.PokemonSpeciesMedia(media_root, arceus)
|
|
|
|
normal_arceus = [f for f in arceus.forms if f.form_identifier == 'normal'][0]
|
|
|
|
normal_accessor = media.PokemonFormMedia(media_root, normal_arceus)
|
|
|
|
assert accessor.icon() == normal_accessor.icon()
|
2011-04-09 15:20:58 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_strict_castform(session, media_root):
|
2011-04-09 15:20:58 +00:00
|
|
|
"""Castform rainy form overworld with strict -- unavailable"""
|
2011-05-02 07:20:28 +00:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
castform = session.query(tables.PokemonSpecies).filter_by(identifier=u'castform').first()
|
|
|
|
rainy_castform = [f for f in castform.forms if f.form_identifier == 'rainy'][0]
|
|
|
|
print rainy_castform
|
2014-07-07 03:25:04 +00:00
|
|
|
rainy_castform = media.PokemonFormMedia(media_root, rainy_castform)
|
2011-05-02 07:20:28 +00:00
|
|
|
rainy_castform.overworld('up', strict=True)
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_strict_exeggcute(session, media_root):
|
2011-04-09 15:20:58 +00:00
|
|
|
"""Exeggcutes's female backsprite, with strict -- unavailable"""
|
2011-05-02 07:20:28 +00:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
exeggcute = session.query(tables.PokemonSpecies).filter_by(identifier=u'exeggcute').one()
|
2014-07-07 03:25:04 +00:00
|
|
|
accessor = media.PokemonSpeciesMedia(media_root, exeggcute)
|
2011-05-02 07:20:28 +00:00
|
|
|
accessor.sprite(female=True, strict=True)
|
2011-04-09 15:20:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def get_all_filenames(media_root):
|
2011-04-09 15:20:58 +00:00
|
|
|
all_filenames = set()
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
for dirpath, dirnames, filenames in os.walk(media_root):
|
2011-04-19 11:44:47 +00:00
|
|
|
dirnames[:] = [dirname for dirname in dirnames if dirname != '.git']
|
2011-04-09 15:20:58 +00:00
|
|
|
for filename in filenames:
|
|
|
|
path = os.path.join(dirpath, filename)
|
|
|
|
assert path_re.match(path), path
|
|
|
|
all_filenames.add(path)
|
|
|
|
|
|
|
|
return all_filenames
|
|
|
|
|
|
|
|
def hit(filenames, method, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Run the given accessor method with args & kwargs; if found remove the
|
|
|
|
result path from filenames and return True, else return False.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
medium = method(*args, **kwargs)
|
|
|
|
#print 'Hit', medium.relative_path
|
|
|
|
assert medium.exists
|
|
|
|
except ValueError, e:
|
|
|
|
#print 'DNF', e
|
|
|
|
return False
|
|
|
|
except:
|
|
|
|
print 'Error while processing', method, args, kwargs
|
|
|
|
raise
|
|
|
|
try:
|
|
|
|
filenames.remove(medium.path)
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
return True
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
@pytest.mark.slow
|
|
|
|
@pytest.mark.xfail
|
|
|
|
def test_get_everything(session, media_root):
|
2011-04-09 15:20:58 +00:00
|
|
|
"""
|
|
|
|
For every the accessor method, loop over the Cartesian products of all
|
|
|
|
possible values for its arguments.
|
|
|
|
Make sure we get every file in the repo, and that we get a file whenever
|
|
|
|
we should.
|
|
|
|
|
|
|
|
Well, there are exceptions of course.
|
|
|
|
"""
|
|
|
|
|
|
|
|
versions = list(session.query(tables.Version).all())
|
|
|
|
versions.append('red-green')
|
|
|
|
|
2012-03-16 00:46:25 +00:00
|
|
|
# We don't have any graphics for Colosseum or XD
|
|
|
|
versions.remove(session.query(tables.Version).filter_by(identifier=u'colosseum').one())
|
|
|
|
versions.remove(session.query(tables.Version).filter_by(identifier=u'xd').one())
|
|
|
|
|
2011-04-09 15:20:58 +00:00
|
|
|
black = session.query(tables.Version).filter_by(identifier=u'black').one()
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
filenames = get_all_filenames(media_root)
|
2011-04-09 15:20:58 +00:00
|
|
|
|
|
|
|
# Some small stuff first
|
|
|
|
|
|
|
|
for damage_class in session.query(tables.MoveDamageClass).all():
|
2014-07-07 03:25:04 +00:00
|
|
|
assert hit(filenames, media.DamageClassMedia(media_root, damage_class).icon)
|
2011-04-09 15:20:58 +00:00
|
|
|
|
|
|
|
for habitat in session.query(tables.PokemonHabitat).all():
|
2014-07-07 03:25:04 +00:00
|
|
|
assert hit(filenames, media.HabitatMedia(media_root, habitat).icon)
|
2011-04-09 15:20:58 +00:00
|
|
|
|
|
|
|
for shape in session.query(tables.PokemonShape).all():
|
2014-07-07 03:25:04 +00:00
|
|
|
assert hit(filenames, media.ShapeMedia(media_root, shape).icon)
|
2011-04-09 15:20:58 +00:00
|
|
|
|
|
|
|
for item_pocket in session.query(tables.ItemPocket).all():
|
2014-07-07 03:25:04 +00:00
|
|
|
assert hit(filenames, media.ItemPocketMedia(media_root, item_pocket).icon)
|
|
|
|
assert hit(filenames, media.ItemPocketMedia(media_root, item_pocket).icon, selected=True)
|
2011-04-09 15:20:58 +00:00
|
|
|
|
|
|
|
for contest_type in session.query(tables.ContestType).all():
|
2014-07-07 03:25:04 +00:00
|
|
|
assert hit(filenames, media.ContestTypeMedia(media_root, contest_type).icon)
|
2011-04-09 15:20:58 +00:00
|
|
|
|
|
|
|
for elemental_type in session.query(tables.Type).all():
|
2014-07-07 03:25:04 +00:00
|
|
|
assert hit(filenames, media.TypeMedia(media_root, elemental_type).icon)
|
2011-04-09 15:20:58 +00:00
|
|
|
|
|
|
|
# Items
|
|
|
|
versions_for_items = [
|
2014-07-07 03:25:04 +00:00
|
|
|
None,
|
|
|
|
session.query(tables.Version).filter_by(identifier='emerald').one(),
|
|
|
|
]
|
2011-04-09 15:20:58 +00:00
|
|
|
|
|
|
|
for item in session.query(tables.Item).all():
|
2014-07-07 03:25:04 +00:00
|
|
|
accessor = media.ItemMedia(media_root, item)
|
2011-04-09 15:20:58 +00:00
|
|
|
assert hit(filenames, accessor.berry_image) or not item.berry
|
|
|
|
for rotation in (0, 90, 180, 270):
|
|
|
|
assert hit(filenames, accessor.underground, rotation=rotation) or (
|
|
|
|
not item.appears_underground or rotation)
|
|
|
|
for version in versions_for_items:
|
|
|
|
success = hit(filenames, accessor.sprite, version=version)
|
|
|
|
if version is None:
|
|
|
|
assert success
|
|
|
|
|
|
|
|
for color in 'red green blue pale prism'.split():
|
|
|
|
for big in (True, False):
|
2014-07-07 03:25:04 +00:00
|
|
|
accessor = media.UndergroundSphereMedia(media_root, color=color, big=big)
|
2011-04-09 15:20:58 +00:00
|
|
|
assert hit(filenames, accessor.underground)
|
|
|
|
|
|
|
|
for rock_type in 'i ii o o-big s t z'.split():
|
2014-07-07 03:25:04 +00:00
|
|
|
accessor = media.UndergroundRockMedia(media_root, rock_type)
|
2011-04-09 15:20:58 +00:00
|
|
|
for rotation in (0, 90, 180, 270):
|
|
|
|
success = hit(filenames, accessor.underground, rotation=rotation)
|
|
|
|
assert success or rotation
|
|
|
|
|
|
|
|
# Pokemon!
|
|
|
|
accessors = []
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
accessors.append(media.UnknownPokemonMedia(media_root))
|
|
|
|
accessors.append(media.EggMedia(media_root))
|
2011-04-30 00:21:37 +00:00
|
|
|
manaphy = session.query(tables.PokemonSpecies).filter_by(identifier=u'manaphy').one()
|
2014-07-07 03:25:04 +00:00
|
|
|
accessors.append(media.EggMedia(media_root, manaphy))
|
|
|
|
accessors.append(media.SubstituteMedia(media_root))
|
2011-04-09 15:20:58 +00:00
|
|
|
|
2011-04-30 00:21:37 +00:00
|
|
|
for form in session.query(tables.PokemonForm).all():
|
2014-07-07 03:25:04 +00:00
|
|
|
accessors.append(media.PokemonFormMedia(media_root, form))
|
2011-04-09 15:20:58 +00:00
|
|
|
|
2011-04-30 00:21:37 +00:00
|
|
|
for pokemon in session.query(tables.PokemonSpecies).all():
|
2014-07-07 03:25:04 +00:00
|
|
|
accessors.append(media.PokemonSpeciesMedia(media_root, pokemon))
|
2011-04-09 15:20:58 +00:00
|
|
|
|
|
|
|
for accessor in accessors:
|
2011-04-30 00:21:37 +00:00
|
|
|
assert hit(filenames, accessor.footprint) or not accessor.is_proper
|
|
|
|
assert hit(filenames, accessor.trozei) or not accessor.is_proper or (
|
|
|
|
accessor.introduced_in > 3)
|
|
|
|
assert hit(filenames, accessor.cry) or not accessor.is_proper
|
|
|
|
assert hit(filenames, accessor.cropped_sprite) or not accessor.is_proper
|
2011-04-09 15:20:58 +00:00
|
|
|
for female in (True, False):
|
2011-04-30 00:21:37 +00:00
|
|
|
assert hit(filenames, accessor.icon, female=female) or not accessor.is_proper
|
2011-04-09 15:20:58 +00:00
|
|
|
assert hit(filenames, accessor.sugimori, female=female) or (
|
2011-04-30 00:21:37 +00:00
|
|
|
not accessor.is_proper or int(accessor.species_id) >= 647)
|
2011-04-09 15:20:58 +00:00
|
|
|
for shiny in (True, False):
|
|
|
|
for frame in (1, 2):
|
|
|
|
for direction in 'up down left right'.split():
|
|
|
|
assert hit(filenames, accessor.overworld,
|
|
|
|
direction=direction,
|
|
|
|
shiny=shiny,
|
|
|
|
female=female,
|
|
|
|
frame=frame,
|
2011-04-30 00:21:37 +00:00
|
|
|
) or not accessor.is_proper or (
|
|
|
|
accessor.introduced_in > 4)
|
2011-04-09 15:20:58 +00:00
|
|
|
for version in versions:
|
|
|
|
for animated in (True, False):
|
|
|
|
for back in (True, False):
|
|
|
|
for color in (None, 'gray', 'gbc'):
|
|
|
|
success = hit(filenames,
|
|
|
|
accessor.sprite,
|
|
|
|
version,
|
|
|
|
animated=animated,
|
|
|
|
back=back,
|
|
|
|
color=color,
|
|
|
|
shiny=shiny,
|
|
|
|
female=female,
|
|
|
|
frame=frame,
|
|
|
|
)
|
|
|
|
if (version == black and not animated
|
|
|
|
and not back and not color and not
|
|
|
|
shiny and not female and
|
|
|
|
frame == 1):
|
|
|
|
# All pokemon are in Black
|
2011-04-30 00:21:37 +00:00
|
|
|
assert success or not accessor.is_proper
|
|
|
|
if (str(accessor.species_id) == '1'
|
2011-04-09 15:20:58 +00:00
|
|
|
and not animated and not color and
|
|
|
|
frame == 1):
|
|
|
|
# Bulbasaur is in all versions
|
|
|
|
assert success
|
|
|
|
|
|
|
|
# Remove exceptions
|
2014-07-07 03:25:04 +00:00
|
|
|
exceptions = [os.path.join(media_root, dirname) for dirname in
|
2011-04-09 15:20:58 +00:00
|
|
|
'chrome fonts ribbons'.split()]
|
2014-07-07 03:25:04 +00:00
|
|
|
exceptions.append(os.path.join(media_root, 'items', 'hm-'))
|
2011-04-09 15:20:58 +00:00
|
|
|
exceptions = tuple(exceptions)
|
|
|
|
|
2011-05-02 07:20:28 +00:00
|
|
|
unaccessed_filenames = set(filenames)
|
|
|
|
for filename in filenames:
|
2011-04-09 15:20:58 +00:00
|
|
|
if filename.startswith(exceptions):
|
2011-05-02 07:20:28 +00:00
|
|
|
unaccessed_filenames.remove(filename)
|
2012-03-16 00:46:25 +00:00
|
|
|
if filename.endswith('-beta.png'):
|
|
|
|
unaccessed_filenames.remove(filename)
|
2011-04-09 15:20:58 +00:00
|
|
|
|
2011-05-02 07:20:28 +00:00
|
|
|
if unaccessed_filenames:
|
|
|
|
print 'Unaccessed files:'
|
|
|
|
for filename in unaccessed_filenames:
|
2011-04-09 15:20:58 +00:00
|
|
|
print filename
|
|
|
|
|
2011-05-02 07:20:28 +00:00
|
|
|
assert unaccessed_filenames == set()
|
2011-04-09 15:20:58 +00:00
|
|
|
|
2011-05-02 07:20:28 +00:00
|
|
|
return (not filenames)
|