-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmoke_test.py
More file actions
1409 lines (1171 loc) · 54.4 KB
/
smoke_test.py
File metadata and controls
1409 lines (1171 loc) · 54.4 KB
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
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Smoke test: pull real data from CDN and exercise ALL SDK methods.
Coverage goal: 100% of public methods, all filter parameters,
all output modes (model, dict, dataframe), and key edge cases.
"""
import logging
import sys
import time
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s")
logger = logging.getLogger("smoke_test")
from mtgjson_sdk import MtgjsonSDK
PASS = 0
FAIL = 0
SKIP = 0
def check(label: str, condition: bool, detail: str = ""):
global PASS, FAIL
status = "PASS" if condition else "FAIL"
if condition:
PASS += 1
else:
FAIL += 1
suffix = f" -- {detail}" if detail else ""
print(f" [{status}] {label}{suffix}")
def skip(label: str, reason: str = ""):
global SKIP
SKIP += 1
suffix = f" -- {reason}" if reason else ""
print(f" [SKIP] {label}{suffix}")
def section(name: str):
print(f"\n{'=' * 60}")
print(f" {name}")
print(f"{'=' * 60}")
def main():
t0 = time.time()
# ══════════════════════════════════════════════════════════
# CLIENT LIFECYCLE
# ══════════════════════════════════════════════════════════
section("Client Lifecycle")
# __repr__
sdk = MtgjsonSDK()
r = repr(sdk)
check("__repr__", "MtgjsonSDK" in r, f"repr={r}")
# context manager
with MtgjsonSDK() as ctx_sdk:
check("__enter__ returns SDK", isinstance(ctx_sdk, MtgjsonSDK))
check("__exit__ (no error)", True, "context manager closed cleanly")
# meta property
meta = sdk.meta
check(
"meta loads",
isinstance(meta, dict) and "data" in meta,
f"keys={list(meta.keys())}",
)
if "data" in meta:
version = meta["data"].get("version", "?")
date = meta["data"].get("date", "?")
check("meta has version", bool(version), f"v={version}, date={date}")
# views property (starts empty, grows as we query)
views_before = sdk.views
check("views property (initial)", isinstance(views_before, list))
# refresh() — in offline-like conditions, cache is fresh after meta load
refresh_result = sdk.refresh()
check("refresh()", isinstance(refresh_result, bool), f"stale={refresh_result}")
# ══════════════════════════════════════════════════════════
# CARDS — CardQuery (8 methods, ~20 filter params)
# ══════════════════════════════════════════════════════════
section("Cards: get_by_name / get_by_uuid")
bolt = sdk.cards.get_by_name("Lightning Bolt")
check("get_by_name Lightning Bolt", len(bolt) > 0, f"found {len(bolt)} printings")
# get_by_name with set_code filter
bolt_lea = sdk.cards.get_by_name("Lightning Bolt", set_code="LEA")
check("get_by_name set_code=LEA", len(bolt_lea) >= 0, f"found {len(bolt_lea)}")
# get_by_name as_dict
bolt_dicts = sdk.cards.get_by_name("Lightning Bolt", as_dict=True)
check(
"get_by_name as_dict", len(bolt_dicts) > 0 and isinstance(bolt_dicts[0], dict)
)
# get_by_name as_dataframe
bolt_df = sdk.cards.get_by_name("Lightning Bolt", as_dataframe=True)
check(
"get_by_name as_dataframe",
hasattr(bolt_df, "shape"),
f"type={type(bolt_df).__name__}",
)
uuid = None
if bolt:
uuid = bolt[0].uuid
# get_by_uuid — model
card = sdk.cards.get_by_uuid(uuid)
check("get_by_uuid (model)", card is not None and card.name == "Lightning Bolt")
# get_by_uuid — as_dict
card_dict = sdk.cards.get_by_uuid(uuid, as_dict=True)
check(
"get_by_uuid as_dict",
isinstance(card_dict, dict) and card_dict.get("name") == "Lightning Bolt",
)
# get_by_uuid — as_dataframe
card_df = sdk.cards.get_by_uuid(uuid, as_dataframe=True)
check("get_by_uuid as_dataframe", hasattr(card_df, "shape"))
# get_by_uuid — nonexistent
missing = sdk.cards.get_by_uuid("00000000-0000-0000-0000-000000000000")
check("get_by_uuid nonexistent returns None", missing is None)
# ── Cards: get_by_uuids (bulk lookup) ──
section("Cards: bulk lookups (get_by_uuids)")
if bolt and len(bolt) >= 2:
bulk_uuids = [b.uuid for b in bolt[:5]]
bulk_cards = sdk.cards.get_by_uuids(bulk_uuids)
check(
"get_by_uuids (models)",
len(bulk_cards) == len(bulk_uuids),
f"requested {len(bulk_uuids)}, got {len(bulk_cards)}",
)
bulk_dicts = sdk.cards.get_by_uuids(bulk_uuids, as_dict=True)
check(
"get_by_uuids as_dict",
len(bulk_dicts) > 0 and isinstance(bulk_dicts[0], dict),
)
bulk_df = sdk.cards.get_by_uuids(bulk_uuids, as_dataframe=True)
check("get_by_uuids as_dataframe", hasattr(bulk_df, "shape"))
# empty list
bulk_empty = sdk.cards.get_by_uuids([])
check("get_by_uuids empty list", bulk_empty == [])
# nonexistent uuids
bulk_none = sdk.cards.get_by_uuids(["00000000-0000-0000-0000-000000000000"])
check("get_by_uuids nonexistent", len(bulk_none) == 0)
# ── Cards: search (all filter params) ──
section("Cards: search filters")
# name LIKE
s = sdk.cards.search(name="Lightning%", limit=10)
check("search name LIKE", len(s) > 0, f"found {len(s)}")
# exact name
s = sdk.cards.search(name="Lightning Bolt", limit=5)
check("search name exact", len(s) > 0)
# colors
s = sdk.cards.search(colors=["R"], mana_value=1.0, limit=5)
check("search colors=R mv=1", len(s) > 0, f"found {len(s)}")
# color_identity
s = sdk.cards.search(color_identity=["W", "U"], limit=5)
check("search color_identity=[W,U]", len(s) > 0, f"found {len(s)}")
# types
s = sdk.cards.search(types="Creature", limit=5)
check("search types=Creature", len(s) > 0, f"found {len(s)}")
# rarity
s = sdk.cards.search(rarity="mythic", limit=5)
check("search rarity=mythic", len(s) > 0, f"found {len(s)}")
# text
s = sdk.cards.search(text="draw a card", limit=5)
check("search text='draw a card'", len(s) > 0, f"found {len(s)}")
# power / toughness
s = sdk.cards.search(power="4", toughness="4", limit=5)
check("search power=4 toughness=4", len(s) > 0, f"found {len(s)}")
# mana_value exact
s = sdk.cards.search(mana_value=3.0, limit=5)
check("search mana_value=3", len(s) > 0, f"found {len(s)}")
# mana_value_lte
s = sdk.cards.search(mana_value_lte=1.0, limit=5)
check("search mana_value_lte=1", len(s) > 0, f"found {len(s)}")
# mana_value_gte
s = sdk.cards.search(mana_value_gte=10.0, limit=5)
check("search mana_value_gte=10", len(s) > 0, f"found {len(s)}")
# artist
s = sdk.cards.search(artist="Christopher Moeller", limit=5)
check("search artist", len(s) > 0, f"found {len(s)}")
# keyword
s = sdk.cards.search(keyword="Flying", limit=5)
check("search keyword=Flying", len(s) > 0, f"found {len(s)}")
# layout
s = sdk.cards.search(layout="split", limit=5)
check("search layout=split", len(s) > 0, f"found {len(s)}")
# is_promo
s = sdk.cards.search(is_promo=True, limit=5)
check("search is_promo=True", len(s) > 0, f"found {len(s)}")
s_np = sdk.cards.search(is_promo=False, limit=5)
check("search is_promo=False", len(s_np) > 0, f"found {len(s_np)}")
# availability
s = sdk.cards.search(availability="mtgo", limit=5)
check("search availability=mtgo", len(s) > 0, f"found {len(s)}")
s = sdk.cards.search(availability="paper", limit=5)
check("search availability=paper", len(s) > 0, f"found {len(s)}")
# language
s = sdk.cards.search(language="Japanese", limit=5)
check("search language=Japanese", isinstance(s, list), f"found {len(s)}")
# set_code
s = sdk.cards.search(set_code="MH3", limit=5)
check("search set_code=MH3", len(s) > 0, f"found {len(s)}")
# set_type (requires JOIN with sets)
s = sdk.cards.search(set_type="expansion", limit=5)
check("search set_type=expansion", len(s) > 0, f"found {len(s)}")
# legal_in + mana_value_lte
s = sdk.cards.search(legal_in="modern", mana_value_lte=2.0, limit=5)
check("search legal_in=modern + mana_value_lte", len(s) > 0, f"found {len(s)}")
# combined filters
s = sdk.cards.search(colors=["R"], rarity="rare", mana_value_lte=3.0, limit=5)
check("search combined (colors+rarity+mv)", len(s) > 0, f"found {len(s)}")
# offset (pagination)
page1 = sdk.cards.search(name="Lightning%", limit=3, offset=0)
page2 = sdk.cards.search(name="Lightning%", limit=3, offset=3)
check(
"search offset (pagination)",
len(page1) > 0 and len(page2) > 0,
"two pages fetched",
)
if page1 and page2:
check("search pages differ", page1[0].uuid != page2[0].uuid, "different cards")
# text_regex
s = sdk.cards.search(text_regex="deals \\d+ damage", limit=5)
check("search text_regex", len(s) > 0, f"found {len(s)}")
# localized_name (foreign language search)
s = sdk.cards.search(localized_name="Blitzschlag", limit=5)
check(
"search localized_name (German)",
len(s) > 0,
f"found {len(s)}, name={s[0].name if s else '?'}",
)
# localized_name LIKE
s = sdk.cards.search(localized_name="%Foudre%", limit=5)
check("search localized_name LIKE", isinstance(s, list), f"found {len(s)}")
# search as_dict
s = sdk.cards.search(name="Lightning%", limit=3, as_dict=True)
check("search as_dict", len(s) > 0 and isinstance(s[0], dict))
# search as_dataframe
s = sdk.cards.search(name="Lightning%", limit=3, as_dataframe=True)
check("search as_dataframe", hasattr(s, "shape"))
# ── Cards: other methods ──
section("Cards: random, count, printings, atomic, find_by_scryfall_id")
rand = sdk.cards.random(3)
check("random(3)", len(rand) == 3, f"names: {[c.name for c in rand]}")
rand_dict = sdk.cards.random(2, as_dict=True)
check("random as_dict", len(rand_dict) == 2 and isinstance(rand_dict[0], dict))
rand_df = sdk.cards.random(2, as_dataframe=True)
check("random as_dataframe", hasattr(rand_df, "shape"))
count = sdk.cards.count()
check("count()", count > 1000, f"total cards: {count}")
# count with filters
count_r = sdk.cards.count(rarity="mythic")
check(
"count(rarity=mythic)",
count_r > 0 and count_r < count,
f"mythic cards: {count_r}",
)
printings = sdk.cards.get_printings("Counterspell")
check(
"get_printings Counterspell",
len(printings) > 5,
f"found {len(printings)} printings",
)
printings_dict = sdk.cards.get_printings("Counterspell", as_dict=True)
check(
"get_printings as_dict",
len(printings_dict) > 0 and isinstance(printings_dict[0], dict),
)
printings_df = sdk.cards.get_printings("Counterspell", as_dataframe=True)
check("get_printings as_dataframe", hasattr(printings_df, "shape"))
# get_atomic — exact name
atomic = sdk.cards.get_atomic("Lightning Bolt")
check("get_atomic Lightning Bolt", len(atomic) > 0)
atomic_dict = sdk.cards.get_atomic("Lightning Bolt", as_dict=True)
check(
"get_atomic as_dict", len(atomic_dict) > 0 and isinstance(atomic_dict[0], dict)
)
# get_atomic — face name fallback for split cards
atomic_fire = sdk.cards.get_atomic("Fire")
check(
"get_atomic face name 'Fire'",
len(atomic_fire) > 0,
f"layout={atomic_fire[0].layout if atomic_fire else '?'}",
)
# find_by_scryfall_id (may not match since uuid != scryfallId)
if uuid:
scry_cards = sdk.cards.find_by_scryfall_id(uuid)
check("find_by_scryfall_id runs", isinstance(scry_cards, list), "no error")
scry_dict = sdk.cards.find_by_scryfall_id(uuid, as_dict=True)
check("find_by_scryfall_id as_dict", isinstance(scry_dict, list))
scry_df = sdk.cards.find_by_scryfall_id(uuid, as_dataframe=True)
check("find_by_scryfall_id as_dataframe", hasattr(scry_df, "shape"))
# ══════════════════════════════════════════════════════════
# TOKENS — TokenQuery (5 methods, ~8 filter params)
# ══════════════════════════════════════════════════════════
section("Tokens")
token_count = sdk.tokens.count()
check("token count()", token_count > 0, f"total tokens: {token_count}")
# count with filters
# (setCode is a common column, should work)
token_count_mh3 = sdk.tokens.count(setCode="MH3")
check(
"token count(setCode=MH3)",
isinstance(token_count_mh3, int),
f"MH3 tokens: {token_count_mh3}",
)
# search by name LIKE
token_search = sdk.tokens.search(name="%Soldier%", limit=5)
check("token search name LIKE", len(token_search) > 0, f"found {len(token_search)}")
# search by set_code — find a set that actually has tokens
# First discover a set code from existing token data
token_set_row = sdk.sql("SELECT DISTINCT setCode FROM tokens LIMIT 1")
token_set_code = token_set_row[0]["setCode"] if token_set_row else "MH3"
token_search_set = sdk.tokens.search(set_code=token_set_code, limit=5)
check(
"token search set_code",
len(token_search_set) > 0,
f"set={token_set_code}, found {len(token_search_set)}",
)
# search by types
token_search_type = sdk.tokens.search(types="Creature", limit=5)
check(
"token search types=Creature",
len(token_search_type) > 0,
f"found {len(token_search_type)}",
)
# search by artist
token_search_artist = sdk.tokens.search(
artist="", limit=5
) # empty string = no filter
check("token search with artist param", isinstance(token_search_artist, list))
# search by colors
token_search_colors = sdk.tokens.search(colors=["W"], limit=5)
check(
"token search colors=[W]",
len(token_search_colors) > 0,
f"found {len(token_search_colors)}",
)
# search with offset
tp1 = sdk.tokens.search(name="%Soldier%", limit=2, offset=0)
tp2 = sdk.tokens.search(name="%Soldier%", limit=2, offset=2)
check("token search offset", isinstance(tp1, list) and isinstance(tp2, list))
# search as_dict
token_dict = sdk.tokens.search(name="%Soldier%", limit=3, as_dict=True)
check(
"token search as_dict", len(token_dict) > 0 and isinstance(token_dict[0], dict)
)
# search as_dataframe
token_df = sdk.tokens.search(name="%Soldier%", limit=3, as_dataframe=True)
check("token search as_dataframe", hasattr(token_df, "shape"))
# get_by_uuid
if token_search:
token = sdk.tokens.get_by_uuid(token_search[0].uuid)
check(
"token get_by_uuid (model)",
token is not None,
f"name={token.name if token else '?'}",
)
token_d = sdk.tokens.get_by_uuid(token_search[0].uuid, as_dict=True)
check("token get_by_uuid as_dict", isinstance(token_d, dict))
token_f = sdk.tokens.get_by_uuid(token_search[0].uuid, as_dataframe=True)
check("token get_by_uuid as_dataframe", hasattr(token_f, "shape"))
# nonexistent
missing_token = sdk.tokens.get_by_uuid("00000000-0000-0000-0000-000000000000")
check("token get_by_uuid nonexistent", missing_token is None)
# get_by_name
token_soldiers = sdk.tokens.get_by_name("Soldier")
check(
"token get_by_name Soldier",
len(token_soldiers) > 0,
f"found {len(token_soldiers)}",
)
token_soldiers_dict = sdk.tokens.get_by_name("Soldier", as_dict=True)
check(
"token get_by_name as_dict",
len(token_soldiers_dict) > 0 and isinstance(token_soldiers_dict[0], dict),
)
token_soldiers_df = sdk.tokens.get_by_name("Soldier", as_dataframe=True)
check("token get_by_name as_dataframe", hasattr(token_soldiers_df, "shape"))
# get_by_name with set_code — use a set that has tokens
token_soldiers_set = sdk.tokens.get_by_name("Soldier", set_code=token_set_code)
check(
"token get_by_name set_code",
isinstance(token_soldiers_set, list),
f"set={token_set_code}, found {len(token_soldiers_set)}",
)
# for_set — use known token set
tokens_for = sdk.tokens.for_set(token_set_code)
check(
"token for_set",
len(tokens_for) > 0,
f"set={token_set_code}, found {len(tokens_for)}",
)
tokens_for_dict = sdk.tokens.for_set(token_set_code, as_dict=True)
check(
"token for_set as_dict",
isinstance(tokens_for_dict, list) and len(tokens_for_dict) > 0,
)
tokens_for_df = sdk.tokens.for_set(token_set_code, as_dataframe=True)
check("token for_set as_dataframe", hasattr(tokens_for_df, "shape"))
# get_by_uuids (bulk token lookup)
if token_search and len(token_search) >= 2:
token_uuids = [t.uuid for t in token_search[:3]]
bulk_tokens = sdk.tokens.get_by_uuids(token_uuids)
check(
"token get_by_uuids",
len(bulk_tokens) == len(token_uuids),
f"requested {len(token_uuids)}, got {len(bulk_tokens)}",
)
bulk_tokens_d = sdk.tokens.get_by_uuids(token_uuids, as_dict=True)
check("token get_by_uuids as_dict", isinstance(bulk_tokens_d[0], dict))
check("token get_by_uuids empty", sdk.tokens.get_by_uuids([]) == [])
# ══════════════════════════════════════════════════════════
# SETS — SetQuery (4 methods, ~7 filter params)
# ══════════════════════════════════════════════════════════
section("Sets")
# get
mh3 = sdk.sets.get("MH3")
check("get set MH3", mh3 is not None, f"name={mh3.name if mh3 else '?'}")
mh3_dict = sdk.sets.get("MH3", as_dict=True)
check("get set as_dict", isinstance(mh3_dict, dict))
mh3_df = sdk.sets.get("MH3", as_dataframe=True)
check("get set as_dataframe", hasattr(mh3_df, "shape"))
# get nonexistent
missing_set = sdk.sets.get("ZZZZZ")
check("get set nonexistent", missing_set is None)
# list — no filter
all_sets = sdk.sets.list(limit=10)
check("list sets (no filter)", len(all_sets) > 0, f"found {len(all_sets)}")
# list — set_type
expansions = sdk.sets.list(set_type="expansion", limit=10)
check("list expansions", len(expansions) > 0, f"found {len(expansions)}")
# list — name filter
horizon_list = sdk.sets.list(name="%Horizons%", limit=10)
check("list name filter", len(horizon_list) > 0, f"found {len(horizon_list)}")
# list — offset
sets_p1 = sdk.sets.list(limit=3, offset=0)
sets_p2 = sdk.sets.list(limit=3, offset=3)
check("list offset (pagination)", len(sets_p1) > 0 and len(sets_p2) > 0)
if sets_p1 and sets_p2:
check("list pages differ", sets_p1[0].code != sets_p2[0].code)
# list — as_dict
sets_d = sdk.sets.list(limit=3, as_dict=True)
check("list as_dict", isinstance(sets_d[0], dict))
# list — as_dataframe
sets_df = sdk.sets.list(limit=3, as_dataframe=True)
check("list as_dataframe", hasattr(sets_df, "shape"))
# search — name
set_search = sdk.sets.search(name="Horizons")
check("search 'Horizons'", len(set_search) > 0, f"found {len(set_search)}")
# search — set_type
set_search_type = sdk.sets.search(set_type="masters", limit=10)
check(
"search set_type=masters",
len(set_search_type) > 0,
f"found {len(set_search_type)}",
)
# search — block
set_search_block = sdk.sets.search(block="Innistrad")
check(
"search block=Innistrad",
isinstance(set_search_block, list),
f"found {len(set_search_block)}",
)
# search — release_year
set_search_year = sdk.sets.search(release_year=2024, limit=10)
check(
"search release_year=2024",
len(set_search_year) > 0,
f"found {len(set_search_year)}",
)
# search — as_dict
set_search_dict = sdk.sets.search(name="Horizons", as_dict=True)
check(
"search as_dict",
len(set_search_dict) > 0 and isinstance(set_search_dict[0], dict),
)
# search — as_dataframe
set_search_df = sdk.sets.search(name="Horizons", as_dataframe=True)
check("search as_dataframe", hasattr(set_search_df, "shape"))
# count
set_count = sdk.sets.count()
check("set count", set_count > 100, f"total sets: {set_count}")
# ══════════════════════════════════════════════════════════
# IDENTIFIERS — IdentifierQuery (18 methods)
# ══════════════════════════════════════════════════════════
section("Identifiers")
if uuid:
ids = sdk.identifiers.get_identifiers(uuid)
check(
"get_identifiers",
ids is not None,
f"keys={list(ids.keys()) if ids else '?'}",
)
# Exercise ALL named find_by_* methods using real IDs from Lightning Bolt
if ids:
# Scryfall ID
if ids.get("scryfallId"):
by_scry = sdk.identifiers.find_by_scryfall_id(ids["scryfallId"])
check("find_by_scryfall_id", len(by_scry) > 0, f"found {len(by_scry)}")
by_scry_dict = sdk.identifiers.find_by_scryfall_id(
ids["scryfallId"], as_dict=True
)
check("find_by_scryfall_id as_dict", isinstance(by_scry_dict, list))
else:
skip("find_by_scryfall_id", "no scryfallId in data")
# Scryfall Oracle ID
if ids.get("scryfallOracleId"):
by_oracle = sdk.identifiers.find_by_scryfall_oracle_id(
ids["scryfallOracleId"]
)
check(
"find_by_scryfall_oracle_id",
len(by_oracle) > 0,
f"found {len(by_oracle)}",
)
else:
skip("find_by_scryfall_oracle_id", "no scryfallOracleId")
# Scryfall Illustration ID
if ids.get("scryfallIllustrationId"):
by_illus = sdk.identifiers.find_by_scryfall_illustration_id(
ids["scryfallIllustrationId"]
)
check(
"find_by_scryfall_illustration_id",
len(by_illus) > 0,
f"found {len(by_illus)}",
)
else:
skip("find_by_scryfall_illustration_id", "no scryfallIllustrationId")
# TCGPlayer Product ID
if ids.get("tcgplayerProductId"):
by_tcg = sdk.identifiers.find_by_tcgplayer_id(
str(ids["tcgplayerProductId"])
)
check("find_by_tcgplayer_id", len(by_tcg) > 0, f"found {len(by_tcg)}")
else:
skip("find_by_tcgplayer_id", "no tcgplayerProductId")
# TCGPlayer Etched ID
if ids.get("tcgplayerEtchedProductId"):
by_tcg_e = sdk.identifiers.find_by_tcgplayer_etched_id(
str(ids["tcgplayerEtchedProductId"])
)
check("find_by_tcgplayer_etched_id", len(by_tcg_e) > 0)
else:
skip("find_by_tcgplayer_etched_id", "no tcgplayerEtchedProductId")
# MTGO ID
if ids.get("mtgoId"):
by_mtgo = sdk.identifiers.find_by_mtgo_id(str(ids["mtgoId"]))
check("find_by_mtgo_id", len(by_mtgo) > 0)
else:
skip("find_by_mtgo_id", "no mtgoId")
# MTGO Foil ID
if ids.get("mtgoFoilId"):
by_mtgo_f = sdk.identifiers.find_by_mtgo_foil_id(str(ids["mtgoFoilId"]))
check("find_by_mtgo_foil_id", len(by_mtgo_f) > 0)
else:
skip("find_by_mtgo_foil_id", "no mtgoFoilId")
# MTG Arena ID
if ids.get("mtgArenaId"):
by_arena = sdk.identifiers.find_by_mtg_arena_id(str(ids["mtgArenaId"]))
check("find_by_mtg_arena_id", len(by_arena) > 0)
else:
skip("find_by_mtg_arena_id", "no mtgArenaId")
# Multiverse ID
if ids.get("multiverseId"):
by_multi = sdk.identifiers.find_by_multiverse_id(
str(ids["multiverseId"])
)
check("find_by_multiverse_id", len(by_multi) > 0)
else:
skip("find_by_multiverse_id", "no multiverseId")
# MCM ID
if ids.get("mcmId"):
by_mcm = sdk.identifiers.find_by_mcm_id(str(ids["mcmId"]))
check("find_by_mcm_id", len(by_mcm) > 0)
else:
skip("find_by_mcm_id", "no mcmId")
# MCM Meta ID
if ids.get("mcmMetaId"):
by_mcm_m = sdk.identifiers.find_by_mcm_meta_id(str(ids["mcmMetaId"]))
check("find_by_mcm_meta_id", len(by_mcm_m) > 0)
else:
skip("find_by_mcm_meta_id", "no mcmMetaId")
# Card Kingdom ID
if ids.get("cardKingdomId"):
by_ck = sdk.identifiers.find_by_card_kingdom_id(
str(ids["cardKingdomId"])
)
check("find_by_card_kingdom_id", len(by_ck) > 0)
else:
skip("find_by_card_kingdom_id", "no cardKingdomId")
# Card Kingdom Foil ID
if ids.get("cardKingdomFoilId"):
by_ck_f = sdk.identifiers.find_by_card_kingdom_foil_id(
str(ids["cardKingdomFoilId"])
)
check("find_by_card_kingdom_foil_id", len(by_ck_f) > 0)
else:
skip("find_by_card_kingdom_foil_id", "no cardKingdomFoilId")
# Card Kingdom Etched ID
if ids.get("cardKingdomEtchedId"):
by_ck_e = sdk.identifiers.find_by_card_kingdom_etched_id(
str(ids["cardKingdomEtchedId"])
)
check("find_by_card_kingdom_etched_id", len(by_ck_e) > 0)
else:
skip("find_by_card_kingdom_etched_id", "no cardKingdomEtchedId")
# Cardsphere ID
if ids.get("cardsphereId"):
by_cs = sdk.identifiers.find_by_cardsphere_id(str(ids["cardsphereId"]))
check("find_by_cardsphere_id", len(by_cs) > 0)
else:
skip("find_by_cardsphere_id", "no cardsphereId")
# Cardsphere Foil ID
if ids.get("cardsphereFoilId"):
by_cs_f = sdk.identifiers.find_by_cardsphere_foil_id(
str(ids["cardsphereFoilId"])
)
check("find_by_cardsphere_foil_id", len(by_cs_f) > 0)
else:
skip("find_by_cardsphere_foil_id", "no cardsphereFoilId")
# Generic find_by with valid column
if ids.get("scryfallId"):
by_gen = sdk.identifiers.find_by("scryfallId", ids["scryfallId"])
check("find_by generic (scryfallId)", len(by_gen) > 0)
# Generic find_by as_dict
if ids.get("scryfallId"):
by_gen_d = sdk.identifiers.find_by(
"scryfallId", ids["scryfallId"], as_dict=True
)
check("find_by generic as_dict", isinstance(by_gen_d, list))
# Second card for identifier coverage — find one with more IDs populated
# Use a recent card likely to have Arena, Multiverse, Cardsphere, etc.
section("Identifiers (secondary card for fuller coverage)")
alt_cards = sdk.cards.search(name="Llanowar Elves", set_code="M19", limit=1)
if alt_cards:
alt_uuid = alt_cards[0].uuid
alt_ids = sdk.identifiers.get_identifiers(alt_uuid)
if alt_ids:
for id_col, method_name in [
("mtgArenaId", "find_by_mtg_arena_id"),
("multiverseId", "find_by_multiverse_id"),
("mcmMetaId", "find_by_mcm_meta_id"),
("cardsphereId", "find_by_cardsphere_id"),
("cardsphereFoilId", "find_by_cardsphere_foil_id"),
("cardKingdomEtchedId", "find_by_card_kingdom_etched_id"),
("tcgplayerEtchedProductId", "find_by_tcgplayer_etched_id"),
("mtgoFoilId", "find_by_mtgo_foil_id"),
]:
val = alt_ids.get(id_col)
if val:
method = getattr(sdk.identifiers, method_name)
result = method(str(val))
check(
f"{method_name} (alt card)", len(result) > 0, f"{id_col}={val}"
)
else:
skip(f"{method_name} (alt card)", f"no {id_col}")
else:
skip("alt card identifiers", "no identifiers found")
else:
skip("alt card identifiers", "Llanowar Elves M19 not found")
# find_by — invalid column raises ValueError
try:
sdk.identifiers.find_by("invalidColumn", "123")
check("find_by invalid column raises", False)
except ValueError:
check("find_by invalid column raises", True)
# ══════════════════════════════════════════════════════════
# LEGALITIES — LegalityQuery (7 methods)
# ══════════════════════════════════════════════════════════
section("Legalities")
if uuid:
# formats_for_card
formats = sdk.legalities.formats_for_card(uuid)
check(
"formats_for_card",
len(formats) > 0,
f"formats: {list(formats.keys())[:5]}...",
)
# is_legal
is_legal = sdk.legalities.is_legal(uuid, "modern")
check("is_legal modern", is_legal is True)
is_legal_fake = sdk.legalities.is_legal(uuid, "nonexistent_format")
check("is_legal nonexistent format", is_legal_fake is False)
# legal_in — model
modern_cards = sdk.legalities.legal_in("modern", limit=5)
check("legal_in modern", len(modern_cards) > 0, f"found {len(modern_cards)}")
# legal_in — as_dict
modern_dict = sdk.legalities.legal_in("modern", limit=3, as_dict=True)
check("legal_in as_dict", len(modern_dict) > 0 and isinstance(modern_dict[0], dict))
# legal_in — as_dataframe
modern_df = sdk.legalities.legal_in("modern", limit=3, as_dataframe=True)
check("legal_in as_dataframe", hasattr(modern_df, "shape"))
# legal_in — with offset
legal_p1 = sdk.legalities.legal_in("modern", limit=3, offset=0)
legal_p2 = sdk.legalities.legal_in("modern", limit=3, offset=3)
check("legal_in offset", len(legal_p1) > 0 and len(legal_p2) > 0)
# banned_in
banned = sdk.legalities.banned_in("modern", limit=5)
check("banned_in modern", isinstance(banned, list), f"found {len(banned)}")
# restricted_in
restricted = sdk.legalities.restricted_in("vintage", limit=5)
check(
"restricted_in vintage",
isinstance(restricted, list),
f"found {len(restricted)}",
)
# suspended_in (may have 0 results if no cards are currently suspended)
suspended = sdk.legalities.suspended_in("historic", limit=5)
check(
"suspended_in historic", isinstance(suspended, list), f"found {len(suspended)}"
)
# not_legal_in
not_legal = sdk.legalities.not_legal_in("standard", limit=5)
check(
"not_legal_in standard", isinstance(not_legal, list), f"found {len(not_legal)}"
)
# ══════════════════════════════════════════════════════════
# PRICES — PriceQuery (5 methods)
# Downloads AllPricesToday.json.gz (~large file)
# ══════════════════════════════════════════════════════════
section("Prices")
try:
# get — raw nested structure
if uuid:
price_raw = sdk.prices.get(uuid)
check(
"prices.get",
isinstance(price_raw, (dict, type(None))),
f"type={type(price_raw).__name__}",
)
# today
today_prices = sdk.prices.today(uuid)
check(
"prices.today",
isinstance(today_prices, list),
f"found {len(today_prices)} rows",
)
if today_prices:
# today — with provider filter
providers = {r.get("provider") for r in today_prices}
if providers:
first_prov = next(iter(providers))
today_filt = sdk.prices.today(uuid, provider=first_prov)
check(
"prices.today provider filter",
len(today_filt) > 0,
f"provider={first_prov}",
)
# today — with finish filter
finishes = {r.get("finish") for r in today_prices}
if finishes:
first_fin = next(iter(finishes))
today_fin = sdk.prices.today(uuid, finish=first_fin)
check(
"prices.today finish filter",
len(today_fin) > 0,
f"finish={first_fin}",
)
# today — with price_type filter
price_types = {r.get("price_type") for r in today_prices}
if price_types:
first_pt = next(iter(price_types))
today_pt = sdk.prices.today(uuid, price_type=first_pt)
check(
"prices.today price_type filter",
len(today_pt) > 0,
f"price_type={first_pt}",
)
# today — as_dataframe
today_df = sdk.prices.today(uuid, as_dataframe=True)
check("prices.today as_dataframe", hasattr(today_df, "shape"))
# history
history = sdk.prices.history(uuid)
check(
"prices.history",
isinstance(history, list),
f"found {len(history)} rows",
)
if history:
# history — with date range
dates = sorted({r.get("date", "") for r in history if r.get("date")})
if len(dates) >= 2:
hist_range = sdk.prices.history(
uuid, date_from=dates[0], date_to=dates[-1]
)
check("prices.history date range", len(hist_range) > 0)
else:
skip("prices.history date range", "only 1 date")
# history — with provider filter
hist_prov = sdk.prices.history(
uuid, provider=history[0].get("provider", "tcgplayer")
)
check("prices.history provider filter", isinstance(hist_prov, list))
# history — as_dataframe
hist_df = sdk.prices.history(uuid, as_dataframe=True)
check("prices.history as_dataframe", hasattr(hist_df, "shape"))
# price_trend
trend = sdk.prices.price_trend(uuid)
check(
"prices.price_trend",
isinstance(trend, (dict, type(None))),
f"trend={trend}" if trend else "no trend data",
)
if trend:
check(
"price_trend has keys",
all(k in trend for k in ("min_price", "max_price", "avg_price")),
)
# price_trend with provider/finish
trend2 = sdk.prices.price_trend(
uuid, provider="tcgplayer", finish="normal"
)
check(
"price_trend with filters", isinstance(trend2, (dict, type(None)))
)
# cheapest_printing
cheapest = sdk.prices.cheapest_printing("Lightning Bolt")
check(
"prices.cheapest_printing",
isinstance(cheapest, (dict, type(None))),
f"cheapest={cheapest}" if cheapest else "no price data",
)
if cheapest:
check(
"cheapest has price", "price" in cheapest and cheapest["price"] > 0
)
# cheapest with different provider
cheapest2 = sdk.prices.cheapest_printing(
"Lightning Bolt", provider="cardkingdom"
)
check(
"cheapest_printing alt provider",
isinstance(cheapest2, (dict, type(None))),
)
else:
skip("prices tests", "no uuid from Lightning Bolt")
except Exception as e:
check("prices module available", False, f"error: {e}")