mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Test update() too
This commit is contained in:
parent
271f045519
commit
b944d830b7
2 changed files with 81 additions and 36 deletions
|
@ -283,7 +283,7 @@ class SaveFilePokemon(object):
|
||||||
save(result, 'date met',
|
save(result, 'date met',
|
||||||
transform=lambda x: x.isoformat())
|
transform=lambda x: x.isoformat())
|
||||||
save(result, 'pokerus data', self.pokerus)
|
save(result, 'pokerus data', self.pokerus)
|
||||||
save(result, 'nicknamed', self.is_nicknamed)
|
result['nicknamed'] = self.is_nicknamed
|
||||||
save(result, 'gender', condition=lambda g: g != 'genderless')
|
save(result, 'gender', condition=lambda g: g != 'genderless')
|
||||||
for name in 'sinnoh ribbons', 'sinnoh contest ribbons', 'hoenn ribbons':
|
for name in 'sinnoh ribbons', 'sinnoh contest ribbons', 'hoenn ribbons':
|
||||||
save(result, name, transform=lambda ribbons:
|
save(result, name, transform=lambda ribbons:
|
||||||
|
@ -334,7 +334,7 @@ class SaveFilePokemon(object):
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def update(self, dct, **kwargs):
|
def update(self, dct=None, **kwargs):
|
||||||
"""Updates the pokemon from a YAML/JSON-compatible dict
|
"""Updates the pokemon from a YAML/JSON-compatible dict
|
||||||
|
|
||||||
Dicts that don't specify all the data are allowed. They update the
|
Dicts that don't specify all the data are allowed. They update the
|
||||||
|
@ -349,6 +349,8 @@ class SaveFilePokemon(object):
|
||||||
"""
|
"""
|
||||||
st = self.structure
|
st = self.structure
|
||||||
session = self.session
|
session = self.session
|
||||||
|
if dct is None:
|
||||||
|
dct = {}
|
||||||
dct.update(kwargs)
|
dct.update(kwargs)
|
||||||
if 'ability' in dct:
|
if 'ability' in dct:
|
||||||
st.ability_id = dct['ability']['id']
|
st.ability_id = dct['ability']['id']
|
||||||
|
@ -365,8 +367,7 @@ class SaveFilePokemon(object):
|
||||||
if reset_form:
|
if reset_form:
|
||||||
del self.form
|
del self.form
|
||||||
if not self.is_nicknamed:
|
if not self.is_nicknamed:
|
||||||
self.nickname = self.species.name
|
del self.nickname
|
||||||
self.is_nicknamed = False
|
|
||||||
if self.species.gender_rate == -1:
|
if self.species.gender_rate == -1:
|
||||||
self.gender = 'genderless'
|
self.gender = 'genderless'
|
||||||
elif self.gender == 'genderless':
|
elif self.gender == 'genderless':
|
||||||
|
@ -405,7 +406,6 @@ class SaveFilePokemon(object):
|
||||||
original_trainer_gender='gender',
|
original_trainer_gender='gender',
|
||||||
)
|
)
|
||||||
load_name('original_trainer_name', trainer, 'name', 'name trash')
|
load_name('original_trainer_name', trainer, 'name', 'name trash')
|
||||||
was_nicknamed = self.is_nicknamed
|
|
||||||
load_values(dct,
|
load_values(dct,
|
||||||
exp='exp',
|
exp='exp',
|
||||||
happiness='happiness',
|
happiness='happiness',
|
||||||
|
@ -421,8 +421,10 @@ class SaveFilePokemon(object):
|
||||||
personality='personality',
|
personality='personality',
|
||||||
)
|
)
|
||||||
load_name('nickname', dct, 'nickname', 'nickname trash')
|
load_name('nickname', dct, 'nickname', 'nickname trash')
|
||||||
self.is_nicknamed = was_nicknamed
|
if 'nicknamed' in dct:
|
||||||
load_values(dct, is_nicknamed='nicknamed')
|
self.is_nicknamed = dct['nicknamed']
|
||||||
|
elif 'nickname' in dct:
|
||||||
|
self.is_nicknamed = self.nickname != self.species.name
|
||||||
for loc_type in 'egg', 'met':
|
for loc_type in 'egg', 'met':
|
||||||
loc_dict = dct.get('{0} location'.format(loc_type))
|
loc_dict = dct.get('{0} location'.format(loc_type))
|
||||||
if loc_dict:
|
if loc_dict:
|
||||||
|
@ -791,7 +793,7 @@ class SaveFilePokemon(object):
|
||||||
del self.blob
|
del self.blob
|
||||||
|
|
||||||
@nickname.deleter
|
@nickname.deleter
|
||||||
def nickname(self, value):
|
def nickname(self):
|
||||||
self.structure.nickname = ''
|
self.structure.nickname = ''
|
||||||
self.is_nicknamed = False
|
self.is_nicknamed = False
|
||||||
del self.blob
|
del self.blob
|
||||||
|
@ -876,7 +878,9 @@ class SaveFilePokemonGen4(SaveFilePokemon):
|
||||||
result['shiny leaves'] = self.shiny_leaves
|
result['shiny leaves'] = self.shiny_leaves
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def update(self, dct, **kwargs):
|
def update(self, dct=None, **kwargs):
|
||||||
|
if dct is None:
|
||||||
|
dct = {}
|
||||||
dct.update(kwargs)
|
dct.update(kwargs)
|
||||||
if 'shiny leaves' in dct:
|
if 'shiny leaves' in dct:
|
||||||
self.shiny_leaves = dct['shiny leaves']
|
self.shiny_leaves = dct['shiny leaves']
|
||||||
|
@ -921,7 +925,9 @@ class SaveFilePokemonGen5(SaveFilePokemon):
|
||||||
result['has hidden ability'] = self.hidden_ability
|
result['has hidden ability'] = self.hidden_ability
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def update(self, dct, **kwargs):
|
def update(self, dct=None, **kwargs):
|
||||||
|
if dct is None:
|
||||||
|
dct = {}
|
||||||
dct.update(kwargs)
|
dct.update(kwargs)
|
||||||
super(SaveFilePokemonGen5, self).update(dct)
|
super(SaveFilePokemonGen5, self).update(dct)
|
||||||
if 'nature' in dct:
|
if 'nature' in dct:
|
||||||
|
|
|
@ -7,6 +7,8 @@ import pytest
|
||||||
from pokedex import struct
|
from pokedex import struct
|
||||||
from pokedex.db import connect, tables, util
|
from pokedex.db import connect, tables, util
|
||||||
|
|
||||||
|
from pokedex.tests import positional_params
|
||||||
|
|
||||||
session = connect()
|
session = connect()
|
||||||
|
|
||||||
def check_with_roundtrip(gen, pkmn, expected):
|
def check_with_roundtrip(gen, pkmn, expected):
|
||||||
|
@ -35,6 +37,7 @@ def voltorb_and_dict():
|
||||||
'gender': 'male',
|
'gender': 'male',
|
||||||
'species': dict(id=100, name=u'Voltorb'),
|
'species': dict(id=100, name=u'Voltorb'),
|
||||||
'nickname': u'\0' * 11,
|
'nickname': u'\0' * 11,
|
||||||
|
'nicknamed': False,
|
||||||
'nickname trash': 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==',
|
'nickname trash': 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==',
|
||||||
'moves': [],
|
'moves': [],
|
||||||
}
|
}
|
||||||
|
@ -48,57 +51,92 @@ def test_species():
|
||||||
assert pkmn.form == voltorb_species.default_form
|
assert pkmn.form == voltorb_species.default_form
|
||||||
assert pkmn.export_dict() == expected
|
assert pkmn.export_dict() == expected
|
||||||
|
|
||||||
|
@positional_params([True], [False])
|
||||||
def test_nickname():
|
def test_moves(use_update):
|
||||||
pkmn, expected = voltorb_and_dict()
|
|
||||||
pkmn.nickname = pkmn.nickname
|
|
||||||
expected['nicknamed'] = True
|
|
||||||
check_with_roundtrip(5, pkmn, expected)
|
|
||||||
|
|
||||||
pkmn.is_nicknamed = False
|
|
||||||
del expected['nicknamed']
|
|
||||||
check_with_roundtrip(5, pkmn, expected)
|
|
||||||
|
|
||||||
def test_moves():
|
|
||||||
pkmn, expected = voltorb_and_dict()
|
pkmn, expected = voltorb_and_dict()
|
||||||
new_moves = (util.get(session, tables.Move, 'sonicboom'), )
|
new_moves = (util.get(session, tables.Move, 'sonicboom'), )
|
||||||
expected['moves'] = [dict(id=49, name=u'SonicBoom', pp=0)]
|
expected['moves'] = [dict(id=49, name=u'SonicBoom', pp=0)]
|
||||||
pkmn.moves = new_moves
|
if use_update:
|
||||||
|
pkmn.update(moves=expected['moves'])
|
||||||
|
else:
|
||||||
|
pkmn.moves = new_moves
|
||||||
assert pkmn.moves == new_moves
|
assert pkmn.moves == new_moves
|
||||||
check_with_roundtrip(5, pkmn, expected)
|
check_with_roundtrip(5, pkmn, expected)
|
||||||
|
|
||||||
new_moves += (util.get(session, tables.Move, 'explosion'),)
|
new_moves += (util.get(session, tables.Move, 'explosion'),)
|
||||||
expected['moves'].append(dict(id=153, name=u'Explosion', pp=0))
|
expected['moves'].append(dict(id=153, name=u'Explosion', pp=0))
|
||||||
pkmn.moves = new_moves
|
if use_update:
|
||||||
|
pkmn.update(moves=expected['moves'])
|
||||||
|
else:
|
||||||
|
pkmn.moves = new_moves
|
||||||
assert pkmn.moves == new_moves
|
assert pkmn.moves == new_moves
|
||||||
check_with_roundtrip(5, pkmn, expected)
|
check_with_roundtrip(5, pkmn, expected)
|
||||||
|
|
||||||
new_pp = (20,)
|
new_pp = (20,)
|
||||||
expected['moves'][0]['pp'] = 20
|
expected['moves'][0]['pp'] = 20
|
||||||
pkmn.move_pp = new_pp
|
if use_update:
|
||||||
|
pkmn.update(moves=expected['moves'])
|
||||||
|
else:
|
||||||
|
pkmn.move_pp = new_pp
|
||||||
assert pkmn.move_pp == (20, 0, 0, 0)
|
assert pkmn.move_pp == (20, 0, 0, 0)
|
||||||
check_with_roundtrip(5, pkmn, expected)
|
check_with_roundtrip(5, pkmn, expected)
|
||||||
|
|
||||||
def test_personality():
|
@positional_params([True], [False])
|
||||||
|
def test_personality(use_update):
|
||||||
pkmn, expected = voltorb_and_dict()
|
pkmn, expected = voltorb_and_dict()
|
||||||
assert pkmn.is_shiny == True
|
assert pkmn.is_shiny == True
|
||||||
pkmn.personality = 12345
|
if use_update:
|
||||||
|
pkmn.update(personality=12345)
|
||||||
|
else:
|
||||||
|
pkmn.personality = 12345
|
||||||
assert pkmn.is_shiny == False
|
assert pkmn.is_shiny == False
|
||||||
expected['personality'] = 12345
|
expected['personality'] = 12345
|
||||||
check_with_roundtrip(5, pkmn, expected)
|
check_with_roundtrip(5, pkmn, expected)
|
||||||
|
|
||||||
def test_pokeball():
|
@positional_params([True], [False])
|
||||||
|
def test_pokeball(use_update):
|
||||||
pkmn, expected = voltorb_and_dict()
|
pkmn, expected = voltorb_and_dict()
|
||||||
masterball = util.get(session, tables.Item, 'master-ball')
|
masterball = util.get(session, tables.Item, 'master-ball')
|
||||||
pkmn.pokeball = masterball
|
|
||||||
assert pkmn.pokeball == masterball
|
|
||||||
expected['pokeball'] = dict(id_dppt=1, name='Master Ball')
|
expected['pokeball'] = dict(id_dppt=1, name='Master Ball')
|
||||||
|
if use_update:
|
||||||
|
pkmn.update(pokeball=expected['pokeball'])
|
||||||
|
else:
|
||||||
|
pkmn.pokeball = masterball
|
||||||
|
assert pkmn.pokeball == masterball
|
||||||
check_with_roundtrip(5, pkmn, expected)
|
check_with_roundtrip(5, pkmn, expected)
|
||||||
|
|
||||||
def test_experience():
|
@positional_params([True], [False])
|
||||||
|
def test_nickname(use_update):
|
||||||
|
pkmn, expected = voltorb_and_dict()
|
||||||
|
if use_update:
|
||||||
|
pkmn.update(nickname=unicode(pkmn.nickname))
|
||||||
|
else:
|
||||||
|
pkmn.nickname = pkmn.nickname
|
||||||
|
expected['nicknamed'] = True
|
||||||
|
check_with_roundtrip(5, pkmn, expected)
|
||||||
|
|
||||||
|
if use_update:
|
||||||
|
pkmn.update(nicknamed=False)
|
||||||
|
else:
|
||||||
|
pkmn.is_nicknamed = False
|
||||||
|
expected['nicknamed'] = False
|
||||||
|
check_with_roundtrip(5, pkmn, expected)
|
||||||
|
|
||||||
|
if use_update:
|
||||||
|
pkmn.update(nicknamed=True)
|
||||||
|
else:
|
||||||
|
pkmn.is_nicknamed = True
|
||||||
|
expected['nicknamed'] = True
|
||||||
|
check_with_roundtrip(5, pkmn, expected)
|
||||||
|
|
||||||
|
@positional_params([True], [False])
|
||||||
|
def test_experience(use_update):
|
||||||
pkmn, expected = voltorb_and_dict()
|
pkmn, expected = voltorb_and_dict()
|
||||||
exp = 2340
|
exp = 2340
|
||||||
pkmn.exp = exp
|
if use_update:
|
||||||
|
pkmn.update(exp=exp)
|
||||||
|
else:
|
||||||
|
pkmn.exp = exp
|
||||||
assert pkmn.exp == exp
|
assert pkmn.exp == exp
|
||||||
assert pkmn.experience_rung.experience < pkmn.exp
|
assert pkmn.experience_rung.experience < pkmn.exp
|
||||||
assert pkmn.next_experience_rung.experience > pkmn.exp
|
assert pkmn.next_experience_rung.experience > pkmn.exp
|
||||||
|
@ -115,7 +153,8 @@ def test_experience():
|
||||||
expected['exp'] = exp
|
expected['exp'] = exp
|
||||||
check_with_roundtrip(5, pkmn, expected)
|
check_with_roundtrip(5, pkmn, expected)
|
||||||
|
|
||||||
def test_ability():
|
@positional_params([True], [False])
|
||||||
|
def test_ability(use_update):
|
||||||
pkmn, expected = voltorb_and_dict()
|
pkmn, expected = voltorb_and_dict()
|
||||||
ability = util.get(session, tables.Ability, 'drizzle')
|
ability = util.get(session, tables.Ability, 'drizzle')
|
||||||
pkmn.ability = ability
|
pkmn.ability = ability
|
||||||
|
@ -123,9 +162,8 @@ def test_ability():
|
||||||
expected['ability'] = dict(id=2, name='Drizzle')
|
expected['ability'] = dict(id=2, name='Drizzle')
|
||||||
check_with_roundtrip(5, pkmn, expected)
|
check_with_roundtrip(5, pkmn, expected)
|
||||||
|
|
||||||
def test_squitle_blob():
|
def test_squirtle_blob():
|
||||||
# Japanese Dream World Squirtle, coutresy of
|
# Japanese Dream World Squirtle from http://projectpokemon.org/events
|
||||||
# http://projectpokemon.org/events/
|
|
||||||
blob = base64.b64decode('J2ZqBgAAICQHAAAAkOaKyTACAABGLAABAAAAAAAAAAAAAAAAA'
|
blob = base64.b64decode('J2ZqBgAAICQHAAAAkOaKyTACAABGLAABAAAAAAAAAAAAAAAAA'
|
||||||
'AAAACEAJwCRAG4AIx4eKAAAAAD171MHAAAAAAAAAQAAAAAAvDDLMKww4TD//wAAAAAAAA'
|
'AAAACEAJwCRAG4AIx4eKAAAAAD171MHAAAAAAAAAQAAAAAAvDDLMKww4TD//wAAAAAAAA'
|
||||||
'AAAAD//wAVAAAAAAAAAAAw/zD/T/9S/0f///8AAAAAAAAACgoOAABLAAAZCgAAAA==')
|
'AAAAD//wAVAAAAAAAAAAAw/zD/T/9S/0f///8AAAAAAAAACgoOAABLAAAZCgAAAA==')
|
||||||
|
@ -149,6 +187,7 @@ def test_squitle_blob():
|
||||||
{'id': 110, 'name': u'Withdraw', 'pp': 40}],
|
{'id': 110, 'name': u'Withdraw', 'pp': 40}],
|
||||||
'nickname': u'ゼニガメ',
|
'nickname': u'ゼニガメ',
|
||||||
'nickname trash': 'vDDLMKww4TD//wAAAAAAAAAAAAD//w==',
|
'nickname trash': 'vDDLMKww4TD//wAAAAAAAAAAAAD//w==',
|
||||||
|
'nicknamed': False,
|
||||||
'oiginal trainer': {'gender': 'male',
|
'oiginal trainer': {'gender': 'male',
|
||||||
'id': 59024,
|
'id': 59024,
|
||||||
'name': u'PPorg',
|
'name': u'PPorg',
|
||||||
|
|
Loading…
Reference in a new issue