Skip to content

Commit

Permalink
Added unit test for archidekt.parse_decklist
Browse files Browse the repository at this point in the history
  • Loading branch information
DiddiZ committed Oct 17, 2022
1 parent 0e32590 commit bba4771
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mtgproxies/decklists/archidekt/archidekt.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def parse_decklist(archidekt_id: str) -> tuple[Decklist, bool, list]:
card_name = item["card"]["oracleCard"]["name"]
set_id = item["card"]["edition"]["editioncode"]
collector_number = item["card"]["collectorNumber"]
if item["categories"][0] not in in_deck: # Cards are guaranteed to have atleast one dominant category
if len(item["categories"]) > 0 and item["categories"][0] not in in_deck:
continue

# Validate card name
Expand Down
18 changes: 18 additions & 0 deletions tests/decklist_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

import pytest


def test_parsing():
from mtgproxies.decklists import parse_decklist
Expand All @@ -12,3 +14,19 @@ def test_parsing():
with open("examples/decklist.txt", "r", encoding="utf-8") as f:
# Ignore differences in linebreaks
assert (format(decklist, "arena") + os.linesep).replace("\r\n", "\n") == f.read().replace("\r\n", "\n")


@pytest.mark.parametrize(
"archidekt_id,expected_first_card",
[
("1212142", "Basilisk Collar"),
("42", "Merieke Ri Berit"),
],
)
def test_archidekt(archidekt_id: str, expected_first_card: str):
from mtgproxies.decklists.archidekt import parse_decklist

decklist, ok, _ = parse_decklist(archidekt_id)

assert ok
assert decklist.cards[0]["name"] == expected_first_card

0 comments on commit bba4771

Please sign in to comment.