2 """Test the media accessors.
4 If run directly from the command line, also tests the accessors and the names
5 of all the media by getting just about everything in a naive brute-force way.
6 This, of course, takes a lot of time to run.
12 from nose
.tools
import *
13 from nose
.plugins
.skip
import SkipTest
17 from pokedex
.db
import tables
, connect
, media
20 basedir
= pkg_resources
.resource_filename('pokedex', 'data/media')
22 path_re
= re
.compile('^[-a-z0-9./]*$')
25 """Totodile's female sprite -- same as male"""
26 totodile
= session
.query(tables
.Pokemon
).filter_by(identifier
=u
'totodile').one()
27 accessor
= media
.PokemonMedia(totodile
)
28 assert accessor
.sprite() == accessor
.sprite(female
=True)
31 """Chimecho's Platinum female backsprite -- diffeent from male"""
32 chimecho
= session
.query(tables
.Pokemon
).filter_by(identifier
=u
'chimecho').one()
33 accessor
= media
.PokemonMedia(chimecho
)
34 male
= accessor
.sprite('platinum', back
=True, frame
=2)
35 female
= accessor
.sprite('platinum', back
=True, female
=True, frame
=2)
39 """Venonat's shiny Yellow sprite -- same as non-shiny"""
40 venonat
= session
.query(tables
.Pokemon
).filter_by(identifier
=u
'venonat').one()
41 accessor
= media
.PokemonMedia(venonat
)
42 assert accessor
.sprite('yellow') == accessor
.sprite('yellow', shiny
=True)
44 def test_arceus_icon():
45 """Arceus fire-form icon -- same as base icon"""
46 arceus
= session
.query(tables
.Pokemon
).filter_by(identifier
=u
'arceus').one()
47 accessor
= media
.PokemonMedia(arceus
)
48 fire_arceus
= [f
for f
in arceus
.forms
if f
.identifier
== 'fire'][0]
49 fire_accessor
= media
.PokemonFormMedia(fire_arceus
)
50 assert accessor
.icon() == fire_accessor
.icon()
53 def test_strict_castform():
54 """Castform rainy form overworld with strict -- unavailable"""
55 castform
= session
.query(tables
.Pokemon
).filter_by(identifier
=u
'castform').first()
56 rainy_castform
= [f
for f
in castform
.forms
if f
.identifier
== 'rainy'][0]
57 rainy_castform
= media
.PokemonFormMedia(rainy_castform
)
58 rainy_castform
.overworld('up', strict
=True)
61 def test_strict_exeggcute():
62 """Exeggcutes's female backsprite, with strict -- unavailable"""
63 exeggcute
= session
.query(tables
.Pokemon
).filter_by(identifier
=u
'exeggcute').one()
64 accessor
= media
.PokemonMedia(exeggcute
)
65 accessor
.sprite(female
=True, strict
=True)
69 def get_all_filenames():
70 print 'Reading all filenames...'
74 for dirpath
, dirnames
, filenames
in os
.walk(basedir
):
75 for filename
in filenames
:
76 path
= os
.path
.join(dirpath
, filename
)
77 assert path_re
.match(path
), path
78 all_filenames
.add(path
)
82 def hit(filenames
, method
, *args
, **kwargs
):
84 Run the given accessor method with args & kwargs; if found remove the
85 result path from filenames and return True, else return False.
88 medium
= method(*args
, **kwargs
)
89 #print 'Hit', medium.relative_path
95 print 'Error while processing', method
, args
, kwargs
98 filenames
.remove(medium
.path
)
103 def check_get_everything():
105 For every the accessor method, loop over the Cartesian products of all
106 possible values for its arguments.
107 Make sure we get every file in the repo, and that we get a file whenever
110 Well, there are exceptions of course.
113 versions
= list(session
.query(tables
.Version
).all())
114 versions
.append('red-green')
116 black
= session
.query(tables
.Version
).filter_by(identifier
=u
'black').one()
118 filenames
= get_all_filenames()
120 # Some small stuff first
122 for damage_class
in session
.query(tables
.MoveDamageClass
).all():
123 assert hit(filenames
, media
.DamageClassMedia(damage_class
).icon
)
125 for habitat
in session
.query(tables
.PokemonHabitat
).all():
126 assert hit(filenames
, media
.HabitatMedia(habitat
).icon
)
128 for shape
in session
.query(tables
.PokemonShape
).all():
129 assert hit(filenames
, media
.ShapeMedia(shape
).icon
)
131 for item_pocket
in session
.query(tables
.ItemPocket
).all():
132 assert hit(filenames
, media
.ItemPocketMedia(item_pocket
).icon
)
133 assert hit(filenames
, media
.ItemPocketMedia(item_pocket
).icon
, selected
=True)
135 for contest_type
in session
.query(tables
.ContestType
).all():
136 assert hit(filenames
, media
.ContestTypeMedia(contest_type
).icon
)
138 for elemental_type
in session
.query(tables
.Type
).all():
139 assert hit(filenames
, media
.TypeMedia(elemental_type
).icon
)
142 versions_for_items
= [
144 session
.query(tables
.Version
).filter_by(identifier
='emerald').one(),
147 for item
in session
.query(tables
.Item
).all():
148 accessor
= media
.ItemMedia(item
)
149 assert hit(filenames
, accessor
.berry_image
) or not item
.berry
150 for rotation
in (0, 90, 180, 270):
151 assert hit(filenames
, accessor
.underground
, rotation
=rotation
) or (
152 not item
.appears_underground
or rotation
)
153 for version
in versions_for_items
:
154 success
= hit(filenames
, accessor
.sprite
, version
=version
)
158 for color
in 'red green blue pale prism'.split():
159 for big
in (True, False):
160 accessor
= media
.UndergroundSphereMedia(color
=color
, big
=big
)
161 assert hit(filenames
, accessor
.underground
)
163 for rock_type
in 'i ii o o-big s t z'.split():
164 accessor
= media
.UndergroundRockMedia(rock_type
)
165 for rotation
in (0, 90, 180, 270):
166 success
= hit(filenames
, accessor
.underground
, rotation
=rotation
)
167 assert success
or rotation
172 accessors
.append(media
.UnknownPokemonMedia())
173 accessors
.append(media
.EggMedia())
174 manaphy
= session
.query(tables
.Pokemon
).filter_by(identifier
=u
'manaphy').one()
175 accessors
.append(media
.EggMedia(manaphy
))
176 accessors
.append(media
.SubstituteMedia())
178 print 'Loading pokemon'
180 for form
in session
.query(tables
.PokemonForm
).filter(tables
.PokemonForm
.identifier
!= '').all():
181 accessors
.append(media
.PokemonFormMedia(form
))
183 for pokemon
in session
.query(tables
.Pokemon
).all():
184 accessors
.append(media
.PokemonMedia(pokemon
))
186 for accessor
in accessors
:
187 assert hit(filenames
, accessor
.footprint
) or not accessor
.form
188 assert hit(filenames
, accessor
.trozei
) or not accessor
.form
or (
189 accessor
.form
.pokemon
.generation
.id > 3)
190 assert hit(filenames
, accessor
.cry
) or not accessor
.form
191 assert hit(filenames
, accessor
.cropped_sprite
) or not accessor
.form
192 for female
in (True, False):
193 assert hit(filenames
, accessor
.icon
, female
=female
) or not accessor
.form
194 assert hit(filenames
, accessor
.sugimori
, female
=female
) or (
195 not accessor
.form
or accessor
.form
.pokemon
.id >= 647)
196 for shiny
in (True, False):
198 for direction
in 'up down left right'.split():
199 assert hit(filenames
, accessor
.overworld
,
204 ) or not accessor
.form
or (
205 accessor
.form
.pokemon
.generation
.id > 4)
206 for version
in versions
:
207 for animated
in (True, False):
208 for back
in (True, False):
209 for color
in (None, 'gray', 'gbc'):
210 success
= hit(filenames
,
220 if (version
== black
and not animated
221 and not back
and not color
and not
222 shiny
and not female
and
224 # All pokemon are in Black
225 assert success
or not accessor
.form
226 if (str(accessor
.pokemon_id
) == '1'
227 and not animated
and not color
and
229 # Bulbasaur is in all versions
233 exceptions
= [os
.path
.join(basedir
, dirname
) for dirname
in
234 'chrome fonts ribbons'.split()]
235 exceptions
.append(os
.path
.join(basedir
, 'items', 'hm-'))
236 exceptions
= tuple(exceptions
)
238 for filename
in tuple(filenames
):
239 if filename
.startswith(exceptions
):
240 filenames
.remove(filename
)
244 print '-----------------'
245 print 'Unaccessed stuff:'
246 for filename
in sorted(filenames
):
248 print len(filenames
), 'unaccessed files :('
250 return (not filenames
)
252 if __name__
== '__main__':
253 result
= nose
.run(defaultTest
=__file__
)
254 result
= result
and check_get_everything()