def test_deck_json_dumps(): discardDeck = Deck(None, [Card(1, "3", "Red"), Card(2, "4", "Blue")]) cards = [Card(3, "5", "Yellow"), Card(4, "6", "Green")] deck = Deck(discardDeck, cards) string = json.dumps(deck.reprJSON(), cls=ComplexEncoder) expected = """{"discardDeck": {"discardDeck": null, "cards": [{"id": 1, "value": "3", "color": "Red"}, {"id": 2, "value": "4", "color": "Blue"}]}, "cards": [{"id": 3, "value": "5", "color": "Yellow"}, {"id": 4, "value": "6", "color": "Green"}]}""" assert string == expected
def test_deck_json_dump_load(): discardDeck = Deck(None, [Card(1, "3", "Red"), Card(2, "4", "Blue")]) cards = [Card(3, "5", "Yellow"), Card(4, "6", "Green")] deck = Deck(discardDeck, cards) string = json.dumps(deck.reprJSON(), cls=ComplexEncoder) deck2 = Deck() deck2.loadJSON(string) assert deck.cards == deck2.cards
def test_deck_reprJSON(): discardDeck = Deck(None, [Card(1, "3", "Red"), Card(2, "4", "Blue")]) cards = [Card(3, "5", "Yellow"), Card(4, "6", "Green")] deck = Deck(discardDeck, cards) assert deck.reprJSON() == dict(discardDeck=deck.discardDeck, cards=deck.cards)
discard = Deck() deck = Deck(discard=discard, cards=cards) deck.shuffle() discard.cards = deck.draw(1) # Discard the top card of the deck # Create 3 players player1 = Player("Player 1", deck) player2 = Player("Player 2", deck) player3 = Player("Player 3", deck) players = [player1, player2, player3] for _ in range(7): for player in players: player.draw(1) print(json.dumps(deck.reprJSON(), cls=ComplexEncoder)) print("\n\nNew Dict:") testjson = """ {"discardDeck": {"discardDeck": null, "cards": [{"id": 101, "value": "wild", "color": "wild"}]}, "cards": [{"id": 54, "value": "2", "color": "Yellow"}, {"id": 28, "value": "2", "color": "Green"}, {"id": 15, "value": "8", "color": "Red"}, {"id": 77, "value": "1", "color": "Blue"}, {"id": 99, "value": "reverse", "color": "Blue"}]} """ deck.loadJSON(testjson) print(json.dumps(deck.reprJSON(), cls=ComplexEncoder)) """ while True: for player in players: print("-------------------------------") print(f"{player.name}: {player.hand}") print(f"Discard Pile: {deck.getDiscard()}") action = "" while action not in ["play", "draw"]: