def test_too_many_evs_total(self): doc = load_test_doc("_template") val = 510//6 doc["evs"] = {"hp": val, "atk": val, "def": val, "spA": val, "spD": val, "spe": val} doc["evs"]["hp"] += 1 with self.assertRaisesRegex(ValueError, r"Sum of EV must not be larger than 510, but is 511"): pokecat.populate_pokeset(doc)
def test_skip_ev_check_total(self): doc = load_test_doc("_template") val = 510//6 doc["evs"] = {"hp": val, "atk": val, "def": val, "spA": val, "spD": val, "spe": val} doc["evs"]["hp"] += 1 with self.assertWarnsRegex(UserWarning, r"Sum of EV must not be larger than 510, but is 511"): pokecat.populate_pokeset(doc, skip_ev_check=True)
def test_wasted_evs(self): doc = load_test_doc("_template") val = 16 doc["evs"] = {"hp": val, "atk": val, "def": val, "spA": val, "spD": val, "spe": val} doc["evs"]["hp"] = 15 with self.assertWarnsRegex(UserWarning, r"EV for hp is 15, which is not a multiple of 4 \(wasted points\)"): pokecat.populate_pokeset(doc)
def test_missing_ev(self): doc = load_test_doc("_template") val = 16 # no atk doc["evs"] = {"hp": val, "def": val, "spA": val, "spD": val, "spe": val} with self.assertRaisesRegex(ValueError, r"evs must contain the following keys: hp, atk, def, spA, spD, spe"): pokecat.populate_pokeset(doc)
def test_too_many_evs_single(self): doc = load_test_doc("_template") val = 510 doc["evs"] = {"atk": val, "def": val, "spA": val, "spD": val, "spe": val} doc["evs"]["hp"] = 253 with self.assertRaisesRegex(ValueError, r"All EVs must be <= 252."): pokecat.populate_pokeset(doc)
def test_insignificant_spelling_mistake_in_combination(self): doc = load_test_doc("_template") doc["moves"] = ["Pound"] doc["item"] = "Black Belt" doc["combinations"] = [["Pound", "Blackbelt"]] # should get recognized with warnings.catch_warnings(record=True) as w: pokecat.populate_pokeset(doc) self.assertEqual(len(w), 0)
def test_invalid_level(self): doc = load_test_doc("_template") doc["level"] = 101 with self.assertRaisesRegex(ValueError, r"level must be a number between 1 and 100"): pokecat.populate_pokeset(doc) doc["level"] = 0 with self.assertRaisesRegex(ValueError, r"level must be a number between 1 and 100"): pokecat.populate_pokeset(doc)
def test_optional_fields_overwrite(self): # test if supplied optional fields don't get overwritten. # just test with rarity doc = load_test_doc("_template") result = pokecat.populate_pokeset(doc) self.assertEqual(result["rarity"], 1.0) doc["rarity"] = 4.2 result = pokecat.populate_pokeset(doc) self.assertEqual(result["rarity"], 4.2)
def test_shared_object_bug(self): doc1 = load_test_doc("_template") doc1["species"] = "Arceus" doc1["item"] = "Earth Plate" doc2 = load_test_doc("_template") doc2["species"] = "Arceus" doc2["item"] = "Splash Plate" result = pokecat.populate_pokeset(doc1) backup = deepcopy(result) pokecat.populate_pokeset(doc2) # should not affect the first result self.assertEqual(backup, result, "result of a populate call was changed after another one")
def analyze_pokeset(pokeset): notes = [] identifier = (pokeset.get("species"), pokeset.get("setname")) if "ingamename" in pokeset: fixed_ingamename = pokeset["ingamename"].encode("ascii", "replace").decode() for char in ILLEGAL_CHARS: fixed_ingamename = fixed_ingamename.replace(char, "?") if pokeset["ingamename"] != fixed_ingamename: notes.append( Note( Severity.NOTE, "Changed ingamename to {} as a temporary fix to avoid encoding issues" .format(fixed_ingamename), identifier)) pokeset["ingamename"] = fixed_ingamename with warnings.catch_warnings(record=True) as w: try: pokeset = pokecat.populate_pokeset(pokeset, skip_ev_check=True) except ValueError as ex: notes.append(Note( Severity.ERROR, str(ex), # TODO identifier)) else: for warning in w: warning_message = str(warning.message) notes.append( Note(Severity.WARNING, warning_message, identifier)) return notes, pokeset return notes, None
def test_wormadam(self): doc = load_test_doc("_template") doc["species"] = "Wormadam" doc["form"] = "Trash" result = pokecat.populate_pokeset(doc) self.assertEqual(result["species"]["types"], ["Bug", "Steel"]) self.assertEqual(result["displayname"], "Wormadam Trash")
def test_nature_by_effect(self): doc = load_test_doc("_template") doc["nature"] = "+spA -spe" result = pokecat.populate_pokeset(doc) self.assertEqual(result["nature"]["increased"], "spA") self.assertEqual(result["nature"]["decreased"], "spe") self.assertEqual(result["nature"]["name"], "Quiet")
def test_misspelled_ball(self): doc = load_test_doc("_template") doc["ball"] = "Poke" # missing accent with self.assertWarnsRegex(UserWarning, r"Didn't recognize ball Poke, but assumed Poké Ball."): result = pokecat.populate_pokeset(doc) # gets populated as an array self.assertEqual([b["name"] for b in result["ball"]], ["Poké Ball"])
def test_misspelled_item(self): doc = load_test_doc("_template") doc["item"] = "Citrus Berry" # some spelling mistake with self.assertWarnsRegex(UserWarning, r"Didn't recognize item Citrus Berry, but assumed Sitrus Berry."): result = pokecat.populate_pokeset(doc) # gets populated as an array self.assertEqual([i["name"] for i in result["item"]], ["Sitrus Berry"])
def test_misspelled_ability(self): doc = load_test_doc("_template") doc["ability"] = "Presure" # some spelling mistake with self.assertWarnsRegex(UserWarning, r"Didn't recognize ability Presure, but assumed Pressure."): result = pokecat.populate_pokeset(doc) # gets populated as an array self.assertEqual([a["name"] for a in result["ability"]], ["Pressure"])
def test_judgment(self): doc = load_test_doc("_template") doc["item"] = "Flame Plate" doc["moves"] = ["Judgment"] resultset = pokecat.populate_pokeset(doc) result = pokecat.instantiate_pokeset(resultset) self.assertEqual(result["moves"][0]["type"], "Fire")
def test_default_shiny_ingamename(self): doc = load_test_doc("_template") doc["species"] = "Typhlosion" doc["shiny"] = True if "ingamename" in doc: del doc["ingamename"] result = pokecat.populate_pokeset(doc) self.assertEquals(result["ingamename"], "TYPHLOSI-S")
def test_custom_displayname(self): doc = load_test_doc("_template") doc["species"] = "Wormadam" doc["form"] = 2 doc["displayname"] = "custom" result = pokecat.populate_pokeset(doc) self.assertEquals(result["displayname"], "custom")
def test_displayname_magic1(self): doc = load_test_doc("_template") doc["species"] = "Arceus" doc["item"] = "Flame Plate" doc["shiny"] = True result = pokecat.populate_pokeset(doc) self.assertEquals(result["displayname"], "Arceus Fire (Shiny)")
def test_arceus(self): doc = load_test_doc("_template") doc["species"] = "Arceus" doc["item"] = "Earth Plate" doc["ability"] = "Multitype" result = pokecat.populate_pokeset(doc) self.assertEqual(result["species"]["types"], ["Ground"]) self.assertEqual(result["displayname"], "Arceus Ground")
def test_natural_gift(self): doc = load_test_doc("_template") doc["item"] = "Colbur Berry" doc["moves"] = ["Natural Gift"] resultset = pokecat.populate_pokeset(doc) result = pokecat.instantiate_pokeset(resultset) self.assertEqual(result["moves"][0]["type"], "Dark") self.assertEqual(result["moves"][0]["power"], 60)
def test_move_separations(self): doc = load_test_doc("_template") doc["moves"] = [["Pound", "Aqua Jet"], ["Surf", "Rock Smash"]] doc["separations"] = [["Pound", "Surf"]] pokeset = pokecat.populate_pokeset(doc) result = pokecat.instantiate_pokeset(pokeset) for _ in range(100): if result["moves"][0]["name"] == "Pound": self.assertEqual(result["moves"][1]["name"], "Rock Smash")
def test_move_in_different_slots_separations(self): doc = load_test_doc("_template") doc["moves"] = [["Pound", "Aqua Jet"], ["Surf", "Aqua Jet"]] doc["separations"] = [["Aqua Jet", "Aqua Jet"], ["Pound", "Surf"]] pokeset = pokecat.populate_pokeset(doc) for _ in range(100): result = pokecat.instantiate_pokeset(pokeset) if result["moves"][0]["name"] == "Aqua Jet": self.assertEqual(result["moves"][1]["name"], "Surf") elif result["moves"][1]["name"] == "Aqua Jet": self.assertEqual(result["moves"][0]["name"], "Pound") else: self.assertTrue(False)
def analyze_pokeset(pokeset): notes = [] identifier = (pokeset.get("species"), pokeset.get("setname")) if "ingamename" in pokeset: fixed_ingamename = pokeset["ingamename"].encode("ascii", "replace").decode() for char in ILLEGAL_CHARS: fixed_ingamename = fixed_ingamename.replace(char, "?") temp = "" for i, char in enumerate(pokeset["ingamename"]): if char in ALLOWED_CHARACTERS: temp += char elif char in NAME_REPLACEMENTS: temp += NAME_REPLACEMENTS[char] else: temp += fixed_ingamename[i] fixed_ingamename = temp if pokeset["ingamename"] != fixed_ingamename: notes.append(Note( Severity.NOTE, "Changed ingamename to {} to avoid encoding issues".format(fixed_ingamename), identifier )) pokeset["ingamename"] = fixed_ingamename with warnings.catch_warnings(record=True) as w: try: pokeset = pokecat.populate_pokeset(pokeset, skip_ev_check=True) except Exception as ex: notes.append(Note( Severity.ERROR, str(ex), # TODO identifier )) else: for warning in w: warning_message = str(warning.message) notes.append(Note( Severity.WARNING, warning_message, identifier )) return notes, pokeset return notes, None
temp = "" for i, char in enumerate(pokeset["ingamename"]): if char in allowed_characters: temp += char elif char in name_replacements: temp += name_replacements[char] else: temp += fixed_ingamename[i] fixed_ingamename = temp if pokeset["ingamename"] != fixed_ingamename: print( "CHANGED INGAMENAME TO {} AS A TEMPORARY FIX TO AVOID ENCODING ISSUES" .format(fixed_ingamename)) pokeset["ingamename"] = fixed_ingamename try: pokeset = pokecat.populate_pokeset( pokeset, skip_ev_check=True) except ValueError as ex: print("{}> ERROR: {}".format( identifier, str(ex).encode("ascii", "replace").decode())) else: for warning in w: print("{}> WARNING: {}".format( identifier, str(warning.message).encode( "ascii", "replace").decode())) genders_this_species = genders_per_species[ pokeset["species"]["id"]] genders_this_species |= set(pokeset["gender"]) if None in genders_this_species and len( genders_this_species) > 1:
import time import logging import pokecat import yaml import crashchecker import monitor from pbrEngine import PBREngine from pbrEngine.states import EngineStates from pbrEngine import Colosseums with open("testpkmn.yaml", encoding="utf-8") as f: yaml_data = yaml.load_all(f) data = [ pokecat.instantiate_pokeset(pokecat.populate_pokeset(single_set)) for single_set in yaml_data ] # reduce by shinies #data = [d for d in data if not d["shiny"]] # TODO remove this again, it's debugging stuff # only keep certain moves # moves = ["Explosion", "Self-Destruct", "Whirlwind", "Roar", # "Perish Song", "Destiny Bond", "Encore", "Metronome", "Me First", # "Transform", "Counter"] # data = [d for d in data if any(set(moves) & set([m["name"] # for m in d["moves"]]))] # TODO this is stupid # remove all unicode, because windows console crashes otherwise # should only affect nidorans, but better be safe
def test_invalid_species_number(self): doc = load_test_doc("_template") doc["species"] = 494 # Victini, not gen 4 with self.assertRaisesRegex(ValueError, r"Invalid species number: 494"): pokecat.populate_pokeset(doc)
def test_species_name(self): doc = load_test_doc("_template") doc["species"] = "Mew" result = pokecat.populate_pokeset(doc) self.assertEqual(result["species"]["id"], 151)
def test_species_number(self): doc = load_test_doc("_template") doc["species"] = 151 result = pokecat.populate_pokeset(doc) self.assertEqual(result["species"]["name"], "Mew")
def test_empty_setname(self): doc = load_test_doc("_template") doc["setname"] = "" with self.assertRaisesRegex(ValueError, r"setname must be a non-empty string"): pokecat.populate_pokeset(doc)