class CommandLineInterface(): def __init__(self): self._coach = Coach(self) @property def coach(self): return self.coach def send(self, message): print(message) def receive(self): return input() def ask(self, message): return input(message) def run(self): self._coach.start(self.done) def done(self): pass def play(self, workout): while workout: message = "Great! Now lets, {0}".format(workout.output()) self.send(message) times = split_times(workout.duration) for seconds in times: time.sleep(seconds) self.send(random_message()) workout = workout.next_action
class TestUi(): def __init__(self): self.queue = [] self._coach = Coach(self) @property def coach(self): return self.coach def displays(self, text): self.queue.insert(0,("displays", text)) def enters(self, text): self.queue.insert(0,("enters", text)) def send(self, actual): assert len(self.queue) > 0 action, expected = self.queue.pop() assert action == "displays", expected assert actual == expected def receive(self): assert len(self.queue) > 0 action, text = self.queue.pop() assert action == "enters" return text def ask(self, actual): self.send(actual) return self.receive() def run(self): self._coach.start(self.done) def done(self): assert len(self.queue) == 0 def play(self, workout): pass