Acey Ducey (Python): Add unit tests

The unit tests can be executed via:

    $ pip install pytest
    $ pytest .

Also a few more type annotations
This commit is contained in:
Martin Thoma
2022-03-09 07:32:30 +01:00
parent 386d421dc3
commit 619d9e5253
3 changed files with 65 additions and 14 deletions

View File

@@ -0,0 +1,19 @@
import io
from unittest import mock
from acey_ducey import play_game
@mock.patch("random.shuffle")
def test_play_game_lose(mock_random_shuffle, monkeypatch, capsys) -> None:
monkeypatch.setattr("sys.stdin", io.StringIO("100\n100"))
mock_random_shuffle = lambda n: n
play_game()
captured = capsys.readouterr()
assert captured.out == (
"You now have 100 dollars\n\n"
"Here are you next two cards\n King\n Ace\n\n"
"What is your bet? Queen\n"
"Sorry, you lose\n"
"Sorry, friend, but you blew your wad\n"
)