June 2019
Beginner to intermediate
770 pages
19h 24m
English
The preceding mock objects were used to test how a Deck class was built. Having 52 identical sentinels makes it difficult to confirm that a Deck deals properly. We'll define a different mock to test the deal feature.
Here's a second test case to ensure that the Deck class deals properly:
class TestDeckDeal(unittest.TestCase): def setUp(self) -> None: self.mock_deck = [ getattr(unittest.mock.sentinel, str(x)) for x in range(52) ] self.mock_card = unittest.mock.Mock( side_effect=self.mock_deck) self.mock_rng = unittest.mock.Mock( wraps=random.Random()) self.mock_rng.shuffle = unittest.mock.Mock() def test_Deck3_should_deal(self) -> None: d = Deck3(size=1, random=self.mock_rng, card_factory=self.mock_card) dealt ...
Read now
Unlock full access