-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpokecat_test.py
725 lines (625 loc) · 29.7 KB
/
pokecat_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
import json
import os
import unittest
import warnings
from copy import deepcopy
import yaml
import pokecat
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
def load_test_docs(name):
path = os.path.join(ROOT_DIR, "testdocuments", "{}.yaml".format(name))
with open(path, encoding="utf-8") as f:
return list(yaml.load_all(f))
def load_test_doc(name):
path = os.path.join(ROOT_DIR, "testdocuments", "{}.yaml".format(name))
with open(path, encoding="utf-8") as f:
return yaml.load(f)
def load_test_doc_json(name):
path = os.path.join(ROOT_DIR, "testdocuments", "{}.json".format(name))
with open(path, encoding="utf-8") as f:
return json.load(f)
class PokecatTester(unittest.TestCase):
def test_load(self):
# just make sure loading the testdocs even works
doc = load_test_doc("dummy")
self.assertEqual(doc, {"a": 1, "b": "a", "c": None})
def test_warning_lowercase_keys(self):
doc = load_test_doc("_template")
doc["Species"] = doc["species"]
del doc["species"]
with self.assertWarnsRegex(UserWarning, r"Key should be all lowercase: Species"):
pokecat.populate_pokeset(doc)
def test_fields_missing(self):
doc = load_test_doc("_template")
del doc["evs"]
with self.assertRaisesRegex(ValueError, r"pokeset is missing obligatory fields: evs"):
pokecat.populate_pokeset(doc)
def test_unknown_fields(self):
doc = load_test_doc("_template")
doc["foobar"] = 1
with self.assertRaisesRegex(ValueError, r"pokeset has unrecognized fields: foobar"):
pokecat.populate_pokeset(doc)
def test_too_long_ingamename(self):
doc = load_test_doc("_template")
doc["ingamename"] = "BULBASAURRRR"
with self.assertRaisesRegex(ValueError, r"ingamename must be between 1 and 10 characters long: BULBASAURRRR"):
pokecat.populate_pokeset(doc)
def test_default_ingamename(self):
doc = load_test_doc("_template")
doc["species"] = "Typhlosion"
if "ingamename" in doc: del doc["ingamename"]
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["ingamename"], "TYPHLOSION")
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.assertEqual(result["ingamename"], "TYPHLOSI-S")
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)
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_species_number(self):
doc = load_test_doc("_template")
doc["species"] = 151
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["species"]["name"], "Mew")
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_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_misspelled_species_name(self):
doc = load_test_doc("_template")
doc["species"] = "Groundon" # common spelling mistake
with self.assertWarnsRegex(UserWarning, r"Didn't recognize species Groundon, but assumed Groudon."):
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["species"]["name"], "Groudon")
def test_invalid_species_name(self):
doc = load_test_doc("_template")
doc["species"] = "BEST"
with self.assertRaisesRegex(ValueError, r"Unrecognized species: BEST"):
pokecat.populate_pokeset(doc)
def test_ability(self):
doc = load_test_doc("_template")
doc["ability"] = "Pressure"
result = pokecat.populate_pokeset(doc)
# gets populated as an array
self.assertEqual([a["name"] for a in result["ability"]], ["Pressure"])
def test_ability_list(self):
doc = load_test_doc("_template")
doc["ability"] = ["Pressure", "Static"]
result = pokecat.populate_pokeset(doc)
self.assertEqual([a["name"] for a in result["ability"]], ["Pressure", "Static"])
def test_duplicate_ability_list(self):
doc = load_test_doc("_template")
doc["ability"] = ["Pressure", "Pressure"]
with self.assertRaisesRegex(ValueError, r"All abilities supplied must be unique: Pressure, Pressure"):
pokecat.populate_pokeset(doc)
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_invalid_ability(self):
doc = load_test_doc("_template")
doc["ability"] = "Invincibility" # doesn't exist
with self.assertRaisesRegex(ValueError, "Unrecognized ability: Invincibility"):
pokecat.populate_pokeset(doc)
def test_no_ability(self):
doc = load_test_doc("_template")
doc["ability"] = None
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["ability"], [{"id": 0, "description": "", "name": None}])
def test_item(self):
doc = load_test_doc("_template")
doc["item"] = "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_item_list(self):
doc = load_test_doc("_template")
doc["item"] = ["Sitrus Berry", "Elixir"]
result = pokecat.populate_pokeset(doc)
self.assertEqual([i["name"] for i in result["item"]], ["Sitrus Berry", "Elixir"])
def test_duplicate_item_list(self):
doc = load_test_doc("_template")
doc["item"] = ["Sitrus Berry", "Sitrus Berry"]
with self.assertRaisesRegex(ValueError, r"All items supplied must be unique: Sitrus Berry, Sitrus Berry"):
pokecat.populate_pokeset(doc)
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_invalid_item(self):
doc = load_test_doc("_template")
doc["item"] = "Ice Cream" # doesn't exist, how sad
with self.assertRaisesRegex(ValueError, "Unrecognized item: Ice Cream"):
pokecat.populate_pokeset(doc)
def test_no_item(self):
doc = load_test_doc("_template")
doc["item"] = None
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["item"], [{"id": 0, "description": "", "name": None}])
def test_no_item_in_list(self):
doc = load_test_doc("_template")
doc["item"] = [None, "Sitrus Berry"]
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["item"], [{"id": 0, "description": "", "name": None}, {"id": 158, "description": "", "name": "Sitrus Berry"}])
def test_ball(self):
doc = load_test_doc("_template")
doc["ball"] = "Master"
result = pokecat.populate_pokeset(doc)
# gets populated as an array
self.assertEqual([b["name"] for b in result["ball"]], ["Master Ball"])
def test_ball_list(self):
doc = load_test_doc("_template")
doc["ball"] = ["Master", "Ultra"]
result = pokecat.populate_pokeset(doc)
self.assertEqual([b["name"] for b in result["ball"]], ["Master Ball", "Ultra Ball"])
def test_duplicate_ball_list(self):
doc = load_test_doc("_template")
doc["ball"] = ["Master", "Master"]
with self.assertRaisesRegex(ValueError, r"All balls supplied must be unique: Master Ball, Master Ball"):
pokecat.populate_pokeset(doc)
def test_misspelled_ball(self):
doc = load_test_doc("_template")
doc["ball"] = "Mastor" # misspelled
with self.assertWarnsRegex(UserWarning, r"Didn't recognize ball Mastor, but assumed Master Ball."):
result = pokecat.populate_pokeset(doc)
# gets populated as an array
self.assertEqual([b["name"] for b in result["ball"]], ["Master Ball"])
def test_misspell_ignore_accents(self):
doc = load_test_doc("_template")
doc["ball"] = "Poke" # missing accent, should be still okay
with warnings.catch_warnings(record=True) as w:
result = pokecat.populate_pokeset(doc)
self.assertEqual(len(w), 0)
# gets populated as an array
self.assertEqual([b["name"] for b in result["ball"]], ["Poké Ball"])
def test_invalid_ball(self):
doc = load_test_doc("_template")
doc["ball"] = "Iron" # Iron Ball isn't a Pokéball
with self.assertRaisesRegex(ValueError, "Unrecognized ball: Iron"):
pokecat.populate_pokeset(doc)
def test_gender(self):
doc = load_test_doc("_template")
doc["gender"] = "m"
result = pokecat.populate_pokeset(doc)
# gets populated as an array
self.assertEqual(result["gender"], ["m"])
def test_gender_list(self):
doc = load_test_doc("_template")
doc["gender"] = ["m", "f"]
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["gender"], ["m", "f"])
def test_duplicate_gender_list(self):
doc = load_test_doc("_template")
doc["gender"] = ["m", "m"]
with self.assertRaisesRegex(ValueError, r"All genders supplied must be unique: m, m"):
pokecat.populate_pokeset(doc)
def test_invalid_gender(self):
doc = load_test_doc("_template")
doc["gender"] = "w"
with self.assertRaisesRegex(ValueError, r"gender can only be 'm', 'f' or not set \(null\), but not w"):
pokecat.populate_pokeset(doc)
def test_mixed_genders(self):
doc = load_test_doc("_template")
doc["gender"] = ["m", None]
with self.assertRaisesRegex(ValueError, r"non-gender cannot be mixed with m/f"):
pokecat.populate_pokeset(doc)
def test_level(self):
doc = load_test_doc("_template")
doc["level"] = 100
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["level"], 100)
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_nature(self):
doc = load_test_doc("_template")
doc["nature"] = "Timid"
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["nature"]["name"], "Timid")
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_nature(self):
doc = load_test_doc("_template")
doc["nature"] = "Quiot" # spelling mistake
with self.assertWarnsRegex(UserWarning, r"Didn't recognize nature Quiot, but assumed Quiet."):
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["nature"]["name"], "Quiet")
def test_invalid_nature(self):
doc = load_test_doc("_template")
doc["nature"] = "Brutal" # doesn't exist
with self.assertRaisesRegex(ValueError, r"Unrecognized nature: Brutal"):
pokecat.populate_pokeset(doc)
def test_ivs_short(self):
doc = load_test_doc("_template")
val = 16
doc["ivs"] = val
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["ivs"], {"hp": val, "atk": val, "def": val, "spA": val, "spD": val, "spe": val})
def test_evs_short(self):
doc = load_test_doc("_template")
val = 16
doc["evs"] = val
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["evs"], {"hp": val, "atk": val, "def": val, "spA": val, "spD": val, "spe": val})
def test_ivs(self):
doc = load_test_doc("_template")
val = 16
doc["ivs"] = {"hp": val, "atk": val, "def": val, "spA": val, "spD": val, "spe": val}
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["ivs"], {"hp": val, "atk": val, "def": val, "spA": val, "spD": val, "spe": val})
def test_evs(self):
doc = load_test_doc("_template")
val = 16
doc["evs"] = {"hp": val, "atk": val, "def": val, "spA": val, "spD": val, "spe": val}
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["evs"], {"hp": val, "atk": val, "def": val, "spA": val, "spD": val, "spe": val})
def test_missing_iv(self):
doc = load_test_doc("_template")
val = 16
# no hp
doc["ivs"] = {"atk": val, "def": val, "spA": val, "spD": val, "spe": val}
with self.assertRaisesRegex(ValueError, r"ivs must contain the following keys: hp, atk, def, spA, spD, spe"):
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_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_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
# TODO warning is currently disabled globally, as it is annoying and doesn't help with anything
# 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_rarity(self):
doc = load_test_doc("_template")
doc["rarity"] = 0.5
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["rarity"], 0.5)
def test_negative_rarity(self):
doc = load_test_doc("_template")
doc["rarity"] = -0.1
with self.assertRaisesRegex(ValueError, r"rarity must be a number greater or equal to 0.0"):
pokecat.populate_pokeset(doc)
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_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_insignificant_spelling_mistake(self):
doc = load_test_doc("_template")
doc["item"] = "Blackbelt" # actually "Black Belt"
with warnings.catch_warnings(record=True) as w:
pokecat.populate_pokeset(doc)
self.assertEqual(len(w), 0)
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_nidoran(self):
doc = load_test_doc("_template")
doc["species"] = "nidoran-m"
with self.assertWarnsRegex(UserWarning, r""):
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["species"]["id"], 32) # nidoran-m
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_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_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 test_move_combinations(self):
doc = load_test_doc("_template")
doc["moves"] = [["Pound", "Aqua Jet"], ["Surf", "Rock Smash"]]
doc["combinations"] = [["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"], "Surf")
def test_move_in_multiple_slots_combinations(self):
doc = load_test_doc("_template")
doc["moves"] = [["Pound", "Aqua Jet"], ["Surf", "Aqua Jet"]]
doc["combinations"] = [["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"], "Aqua Jet")
elif result["moves"][0]["name"] == "Pound":
self.assertEqual(result["moves"][1]["name"], "Surf")
else:
self.assertTrue(False)
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 test_skip_ev_check_single(self):
doc = load_test_doc("_template")
doc["evs"] = {"atk": 0, "def": 0, "spA": 0, "spD": 0, "spe": 0}
doc["evs"]["hp"] = 253
with self.assertWarnsRegex(UserWarning, r"All EVs must be <= 252."):
pokecat.populate_pokeset(doc, skip_ev_check=True)
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_displayname_magic1(self):
doc = load_test_doc("_template")
doc["species"] = "Arceus"
doc["item"] = "Flame Plate"
doc["shiny"] = True
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["displayname"], "Arceus Fire (Shiny)")
def test_displayname_magic2(self):
doc = load_test_doc("_template")
doc["species"] = "Wormadam"
doc["form"] = 2
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["displayname"], "Wormadam Trash")
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.assertEqual(result["displayname"], "custom")
def test_formname(self):
doc = load_test_doc("_template")
doc["species"] = "Unown"
doc["form"] = "C"
result = pokecat.populate_pokeset(doc)
self.assertEqual(result["form"], 2)
def test_invalid_happiness(self):
doc = load_test_doc("_template")
doc["species"] = "Unown"
doc["happiness"] = [1, 2]
with self.assertRaisesRegex(ValueError, r"happiness must be a number."):
pokecat.populate_pokeset(doc)
def test_hidden_and_biddable(self):
doc = load_test_doc("_template")
doc["hidden"] = True
doc["biddable"] = True
with self.assertWarnsRegex(UserWarning, r"Set is biddable, but also hidden, which doesn't make sense."):
pokecat.populate_pokeset(doc)
def test_public_shiny(self):
doc = load_test_doc("_template")
doc["hidden"] = False
doc["shiny"] = True
with self.assertWarnsRegex(UserWarning, r"Set is shiny, but not hidden, which means it is publicly visible. Is this intended?"):
pokecat.populate_pokeset(doc)
doc["biddable"] = True
doc["shiny"] = True
with self.assertWarnsRegex(UserWarning, r"Set is shiny, but also biddable, which means it can be used in token matches. Is this intended?"):
pokecat.populate_pokeset(doc)
def test_default_hidden_shiny(self):
doc = load_test_doc("_template")
doc["shiny"] = True
result = pokecat.populate_pokeset(doc)
self.assertTrue(result["hidden"])
def test_default_not_hidden(self):
doc = load_test_doc("_template")
result = pokecat.populate_pokeset(doc)
self.assertFalse(result["hidden"])
def test_null_forms(self):
doc = load_test_doc("_template")
doc["tags"] = None
with self.assertRaisesRegex(ValueError, r"tags must be a list of strings"):
pokecat.populate_pokeset(doc)
def test_forms_not_string(self):
doc = load_test_doc("_template")
doc["tags"] = [42]
with self.assertRaisesRegex(ValueError, r"tags must be a list of strings"):
pokecat.populate_pokeset(doc)
# todo test forms, displaynames with forms, moves, special cases, combinations and separations.
# and whatever isn't tested yet as well
def test_gen1_vs_gen4(self):
gen1_200 = pokecat.gen1data.get_item("HM05")
gen4_200 = pokecat.gen4data.get_item("Chilan Berry")
self.assertEqual(gen1_200["id"], 200)
self.assertEqual(gen4_200["id"], 200)
def test_gen1_elixer_item_spelling(self):
elixir = pokecat.gen1data.find_item("Elixir")
match = next(iter(elixir.values()))
self.assertEqual(match["name"], "ELIXER")
def test_get_gen1_move(self):
gen1_100 = pokecat.gen1data.get_move("TELEPORT")
gen4_100 = pokecat.gen4data.get_move("Teleport")
self.assertEqual(gen1_100["id"], 100)
self.assertEqual(gen4_100["id"], 100)
def test_empty_otions(self):
fields = ["ability", "item", "ball", "gender"]
for field in fields:
doc = load_test_doc("_template")
doc[field] = []
plural = "abilities" if field == "ability" else field + "s"
with self.assertRaisesRegex(ValueError, r"List of possible {} cannot be empty".format(plural)):
pokecat.populate_pokeset(doc)
doc = load_test_doc("_template")
doc["moves"] = [[]]
with self.assertRaisesRegex(ValueError, r"List of possible moves in slot 1 cannot be empty"):
pokecat.populate_pokeset(doc)
def test_invalid_number_of_moves(self):
doc = load_test_doc("_template")
doc["moves"] = []
with self.assertRaisesRegex(ValueError, r"Pokémon must have between 1 and 4 moves, but has 0"):
pokecat.populate_pokeset(doc)
doc["moves"] = ["1", "2", "3", "4", "5"]
with self.assertRaisesRegex(ValueError, r"Pokémon must have between 1 and 4 moves, but has 5"):
pokecat.populate_pokeset(doc)
def test_duplicate_moves(self):
doc = load_test_doc("_template")
doc["moves"] = ["Tackle", "Tackle"]
with self.assertWarnsRegex(UserWarning, r"Move Tackle is guaranteed to occupy multiple slots \(possible stallmate due to PP-bug\)"):
pokecat.populate_pokeset(doc)
def test_invalid_suppression(self):
doc = load_test_doc("_template")
doc["suppressions"] = ["invalid"]
with self.assertRaisesRegex(ValueError, r"invalid is not a recognized suppression"):
pokecat.populate_pokeset(doc)
def test_suppressions_recognized(self):
from pokecat import Suppressions
for suppression in Suppressions:
doc = load_test_doc("_template")
doc["suppressions"] = [suppression.value]
pokecat.populate_pokeset(doc)
# should just raise no errors
def test_too_many_evs_single_suppressed(self):
doc = load_test_doc("_template")
val = 32
doc["evs"] = {"atk": val, "def": val, "spA": val, "spD": val, "spe": val}
doc["evs"]["hp"] = 256
doc["suppressions"] = ["invalid-evs"]
with warnings.catch_warnings(record=True) as w:
pokecat.populate_pokeset(doc)
self.assertEqual(len(w), 0)
def test_too_many_evs_total_suppressed(self):
doc = load_test_doc("_template")
val = 128
doc["evs"] = {"hp": val, "atk": val, "def": val, "spA": val, "spD": val, "spe": val}
doc["suppressions"] = ["invalid-evs"]
with warnings.catch_warnings(record=True) as w:
pokecat.populate_pokeset(doc)
for x in w:
print(x)
self.assertEqual(len(w), 0)
def test_wasted_evs_suppressed(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
doc["suppressions"] = ["wasted-evs"]
with warnings.catch_warnings(record=True) as w:
pokecat.populate_pokeset(doc)
self.assertEqual(len(w), 0)
def test_duplicate_moves_suppressed(self):
doc = load_test_doc("_template")
doc["moves"] = ["Tackle", "Tackle"]
doc["suppressions"] = ["duplicate-moves"]
with warnings.catch_warnings(record=True) as w:
pokecat.populate_pokeset(doc)
self.assertEqual(len(w), 0)
def test_public_shiny_suppressed(self):
doc = load_test_doc("_template")
doc["suppressions"] = ["public-shiny"]
doc["shiny"] = True
doc["hidden"] = False
with warnings.catch_warnings(record=True) as w:
pokecat.populate_pokeset(doc)
self.assertEqual(len(w), 0)
doc["biddable"] = True
with warnings.catch_warnings(record=True) as w:
pokecat.populate_pokeset(doc)
self.assertEqual(len(w), 0)
if __name__ == "__main__":
unittest.main()