From 62d781a53e7f51ce26c2a9b38ea892e8d2523599 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sun, 10 Dec 2017 12:00:17 -0800 Subject: [PATCH] TicTacToe tests: Extend tests to end of game draw condition & quit. --- .../zulip_bots/bots/tictactoe/test_tictactoe.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py b/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py index aba3765..c8f6b03 100644 --- a/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py +++ b/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py @@ -1,5 +1,7 @@ from zulip_bots.test_lib import StubBotTestCase +from mock import patch + class TestTictactoeBot(StubBotTestCase): bot_name = 'tictactoe' @@ -39,8 +41,10 @@ class TestTictactoeBot(StubBotTestCase): "My turn:\n[ x o x ]\n[ x o _ ]\n[ o _ _ ]\n" "Your turn! Enter a coordinate or type help."), after_3_2 = ("[ x o x ]\n[ x o _ ]\n[ o x _ ]\n" - "My turn:\n[ x o x ]\n[ x o o ]\n[ o x _ ]\n" + "My turn:\n[ x o x ]\n[ x o _ ]\n[ o x o ]\n" "Your turn! Enter a coordinate or type help."), + after_2_3_draw = ("[ x o x ]\n[ x o x ]\n[ o x o ]\n" + "It's a draw! Neither of us was able to win.") ) conversation = [ @@ -80,8 +84,12 @@ class TestTictactoeBot(StubBotTestCase): ("1,1", msg['after_1_1']), ("2, 1", msg['after_2_1']), ("(1,3)", msg['after_1_3']), - ("quit", msg['successful_quit']), - # Can't test 'after_3_2' as it's random! + ("3,2", msg['after_3_2']), + ("2,3", msg['after_2_3_draw']), + # Game already over; can't quit FIXME improve response? + ("quit", msg['didnt_understand']), ] - self.verify_dialog(conversation) + with patch('zulip_bots.bots.tictactoe.tictactoe.random.choice') as choice: + choice.return_value = [2, 2] + self.verify_dialog(conversation)