Skip to content

Commit

Permalink
When someone signs up with a universes beyond name, use within name
Browse files Browse the repository at this point in the history
  • Loading branch information
bakert committed Oct 8, 2023
1 parent d31884f commit c2399a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion magic/decklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def vivify(decklist: DecklistType) -> Deck:
for section in ['maindeck', 'sideboard']:
for name, n in decklist.get(section, {}).items():
try:
validated[section][oracle.valid_name(name)] = n
canonical_name = oracle.valid_name(name)
if validated[section].get(canonical_name):
raise InvalidDataException(f'More than one entry for {canonical_name} in {section}')
validated[section][canonical_name] = n
except InvalidDataException:
invalid_names.add(name)
if invalid_names:
Expand Down
14 changes: 14 additions & 0 deletions magic/decklist_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,3 +802,17 @@ def test_maindeck_not_sideboard() -> None:
d = decklist.parse(s)
assert sum(d['maindeck'].values()) == 60
assert sum(d['sideboard'].values()) == 0

def test_vivify_universes_beyond() -> None:
s = """
4 Negan, the Cold-Blooded
4 Malik, Grim Manipulator
52 Swamp
"""
s = textwrap.dedent(s)
d = decklist.parse(s)
v = decklist.vivify(d)

Check failure on line 814 in magic/decklist_test.py

View workflow job for this annotation

GitHub Actions / Pytest Results

decklist_test.test_vivify_universes_beyond

shared.pd_exception.InvalidDataException: Invalid cards: Malik, Grim Manipulator
Raw output
def test_vivify_universes_beyond() -> None:
        s = """
            4 Negan, the Cold-Blooded
            4 Malik, Grim Manipulator
            52 Swamp
        """
        s = textwrap.dedent(s)
        d = decklist.parse(s)
>       v = decklist.vivify(d)

d          = {'maindeck': {'Malik, Grim Manipulator': 4, 'Negan, the Cold-Blooded': 4, 'Swamp': 52}, 'sideboard': {}}
s          = '\n4 Negan, the Cold-Blooded\n4 Malik, Grim Manipulator\n52 Swamp\n'

magic/decklist_test.py:814: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

decklist = {'maindeck': {'Malik, Grim Manipulator': 4, 'Negan, the Cold-Blooded': 4, 'Swamp': 52}, 'sideboard': {}}

    def vivify(decklist: DecklistType) -> Deck:
        validated: DecklistType = {'maindeck': {}, 'sideboard': {}}
        invalid_names = set()
        for section in ['maindeck', 'sideboard']:
            for name, n in decklist.get(section, {}).items():
                try:
                    canonical_name = oracle.valid_name(name)
                    if validated[section].get(canonical_name):
                        raise InvalidDataException(f'More than one entry for {canonical_name} in {section}')
                    validated[section][canonical_name] = n
                except InvalidDataException:
                    invalid_names.add(name)
        if invalid_names:
>           raise InvalidDataException('Invalid cards: {invalid_names}'.format(invalid_names='; '.join(invalid_names)))
E           shared.pd_exception.InvalidDataException: Invalid cards: Malik, Grim Manipulator

canonical_name = 'Swamp'
decklist   = {'maindeck': {'Malik, Grim Manipulator': 4, 'Negan, the Cold-Blooded': 4, 'Swamp': 52}, 'sideboard': {}}
invalid_names = {'Malik, Grim Manipulator'}
n          = 52
name       = 'Swamp'
section    = 'sideboard'
validated  = {'maindeck': {'Malik, Grim Manipulator': 4, 'Swamp': 52}, 'sideboard': {}}

magic/decklist.py:117: InvalidDataException
assert v.maindeck[0].name == 'Malik, Grim Manipulator'
assert v.maindeck[0].n == 8
assert v.maindeck[1].name == 'Swamp'
assert v.maindeck[1].n == 52
2 changes: 1 addition & 1 deletion magic/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def init(force: bool = False) -> None:

def valid_name(name: str) -> str:
if name in CARDS_BY_NAME:
return name
return CARDS_BY_NAME[name].name
try:
front = name[0:name.index('/')].strip()
except ValueError:
Expand Down

0 comments on commit c2399a9

Please sign in to comment.