I’ve researched mock and I figure that’s the way to go. But I’m very unfamiliar with it and don’t really know how to implement it. I want to create a unit test to test the method works. The only real problem I have is to mock user inputs
I’ve looked up mock but haven’t found a solution which fits in with multiple inputs.
def player_move(self, player0):
"""Function for when the player moves"""
round_score = 0
while self.playing:
print(f"n--- {player0.get_name()}'s turn ---")
choice = input("Roll or Hold?n--> ")
if choice.lower() == "roll":
roll = player0.roll_dice()
if roll == 1:
print(f"{player0.get_name()} rolled a {roll} and loses " +
"all points for this turn!")
round_score = 0
break
else:
round_score += roll
print(f"{player0.get_name()} rolled a {roll} and now has" +
f" {player0.get_score() + round_score} points!n")
if player0.get_score() + round_score >= 20:
player0.add_score(round_score)
break
elif choice.lower() == "hold":
player0.add_score(round_score)
print(f"{player0.get_name()} has secured " +
f"{player0.get_score()} points!")
round_score = 0
break
elif choice.lower() == "changename":
new_name = input("Enter new name:n--> ")
player0.name = new_name
elif choice.lower() == "quit":
print("Quitting the match")
self.playing = False
return self.playing
elif choice.lower() == "cheat":
player0.add_score(20)
break
1