def test_betting(monkeypatch): """ Testing different things we can do with betting """ p = Player(money=100) # Basic bet p.placeBet(10) # Test placing a negative bet with pytest.raises(Exception): p.placeBet(-10) # Test betting more than we have with pytest.raises(Exception): p.placeBet(100) # Need to monkeypatch the input monkeypatch.setattr(builtins,"input",lambda _: "5") # This should call User input, which we just defined as returning 5 p.placeBet() # Get the bets bets = p.getBets() # We have had 2 bets so far assert len(bets) == 2 # Clear the bets p.clearBets() assert len(p.getBets()) == 0 # Create a machine user p = Player(money=100,strategy="bjStrategy_8deck_hitSoft17") # For now this should create an exception with pytest.raises(Exception): p.placeBet()
def test_betting(monkeypatch): """ Testing different things we can do with betting """ p = Player(money=100) # Basic bet p.placeBet(10) # Test placing a negative bet with pytest.raises(Exception): p.placeBet(-10) # Test betting more than we have with pytest.raises(Exception): p.placeBet(100) # Need to monkeypatch the input monkeypatch.setattr(builtins, "input", lambda _: "5") # This should call User input, which we just defined as returning 5 p.placeBet() # Get the bets bets = p.getBets() # We have had 2 bets so far assert len(bets) == 2 # Clear the bets p.clearBets() assert len(p.getBets()) == 0 # Create a machine user p = Player(money=100, strategy="bjStrategy_8deck_hitSoft17") # For now this should create an exception with pytest.raises(Exception): p.placeBet()
def test_placeAndClearBets(monkeypatch): """ Testing placing and clearing bets """ table = Table() player = Player(money=100,name="Steve") player2 = Player(money=100,name="Bob") table.addPlayer(player) table.addPlayer(player2) # Need to monkeypatch input #global count = 0 def placeBet(): global count if count == 0: count += 1 self.placeBet(10) else: self.placeBet(20) # Since we're basically changing the call variables # we need to copy the original method and call it separately player.placeBetOriginal = player.placeBet player2.placeBetOriginal = player2.placeBet monkeypatch.setattr(player,"placeBet",lambda : player.placeBetOriginal(10)) monkeypatch.setattr(player2,"placeBet",lambda : player2.placeBetOriginal(20)) # Place the bets table.placeBets() # Test that it worked assert len(player.getBets()) == 1 assert player.getBets()[0] == 10 assert len(player2.getBets()) == 1 assert player2.getBets()[0] == 20 # Now clear them table.clearBets() assert len(player.getBets()) == 0 assert len(player2.getBets()) == 0