def test_parse_right(self): """ Reading RIGHT calls Robot.turn_right() """ robot = Mock(Robot) parser = Parser(robot) parser.read("RIGHT") robot.turn_right.assert_called_once()
def test_parse_left(self): """ Reading LEFT calls Robot.turn_left() """ robot = Mock(Robot) parser = Parser(robot) parser.read("LEFT") robot.turn_left.assert_called_once()
def test_parse_report(self): """ Reading RIGHT calls Robot.turn_right() """ robot = Mock(Robot) robot.report.return_value = "Some Text" parser = Parser(robot) response = parser.read("REPORT") robot.report.assert_called_once() self.assertEqual("Some Text", response)
def test_parse_place(self): """ Reading PLACE calls Robot.place() """ robot = Mock(Robot) parser = Parser(robot) parser.read("PLACE 3,4,NORTH") robot.place.assert_called_with(3, 4, Aim.NORTH) parser.read("PLACE 1,7,SOUTH") robot.place.assert_called_with(1, 7, Aim.SOUTH) parser.read("PLACE 61,9,EAST") robot.place.assert_called_with(61, 9, Aim.EAST) parser.read("PLACE 66,77,SOUTH") robot.place.assert_called_with(66, 77, Aim.SOUTH)
def main(config): """ Run the program using file as input. Output is to written standard out. :param config: Configuration dict. Must contain a key of 'file' that points to an open file handle. """ runner = FileToFileRunner(config.file, sys.stdout, Parser(Robot(Board(5, 5)))) runner.run() config.file.close()
def test_parse_bad_place(self): """ Reading bad PLACE calls does not call anything. """ robot = Mock(Robot) parser = Parser(robot) parser.read("PLACE -3,4,SW") parser.read("PLACE12,2,EAST") parser.read("PLACE 4,4,EAST") parser.read("PLACE7 ,9,NORTHY") parser.read("PLACE ") parser.read("PLACE X,Y,NORTH") parser.read("PLACE -1,0,NORTH") robot.place.assert_not_called()