aboutsummaryrefslogtreecommitdiff
path: root/tests/test_imagoIO.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_imagoIO.py')
-rw-r--r--tests/test_imagoIO.py164
1 files changed, 161 insertions, 3 deletions
diff --git a/tests/test_imagoIO.py b/tests/test_imagoIO.py
index c3c6fda..4f2d7bd 100644
--- a/tests/test_imagoIO.py
+++ b/tests/test_imagoIO.py
@@ -5,36 +5,194 @@ import unittest
import io
import sys
+from imago.data.enums import DecisionAlgorithms
from imago.engine.imagoIO import ImagoIO
+from imago.engine.parseHelpers import parseVertex
class TestImagoIO(unittest.TestCase):
"""Test ImagoIO component."""
@unittest.mock.patch('imago.engine.imagoIO.input', create=True)
-
def testSimpleCommands(self, mocked_input):
"""Test simple commands."""
+ self.maxDiff = None
+
mocked_input.side_effect = [
+ '\n',
'name\n',
'version\n',
'protocol_version\n',
+ 'clear_board\n',
+ '\n',
+ 'known_command\n',
+ 'known_command name\n',
+ 'known_command version\n',
+ 'known_command wrongcommand\n',
+ '\n',
+ 'boardsize\n',
+ 'boardsize 10\n',
+ '\n',
+ 'komi\n',
+ 'komi 5.5\n',
+ '\n',
+ 'play\n',
+ 'play 1\n',
+ 'play 1 2\n',
+ 'play b a1\n',
+ '\n',
+ 'undo\n',
+ 'undo\n',
+ '\n',
+ 'wrongcommand\n',
+ '\n',
'quit\n'
]
testout = io.StringIO()
- imagoIO = ImagoIO(outputStream=testout)
+ imagoIO = ImagoIO(
+ decisionAlgorithmId=DecisionAlgorithms.MONTECARLO,
+ outputStream=testout
+ )
imagoIO.start()
value = testout.getvalue()
self.assertEqual(
'= Imago\n\n' +
'= 0.0.0\n\n' +
- '= 2\n\n',
+ '= 2\n\n' +
+ '= \n\n' +
+ '? Wrong number of arguments\n' +
+ '? Usage: known_command COMMAND_NAME\n\n' +
+ '= true\n\n' +
+ '= true\n\n' +
+ '= false\n\n' +
+ '? Wrong number of arguments\n' +
+ '? Usage: boardsize <newSize>\n\n' +
+ '= \n\n' +
+ '? Wrong number of arguments\n' +
+ '? Usage: komi <newKomi>\n\n' +
+ '= \n\n' +
+ '? Wrong number of arguments\n' +
+ '? Usage: play <color> <vertex>\n\n' +
+ '? Wrong number of arguments\n' +
+ '? Usage: play <color> <vertex>\n\n' +
+ '? Invalid move: Unknown color [1].\n\n' +
+ '= \n\n' +
+ '= \n\n' +
+ '= \n\n' +
+ '? unknown command\n\n',
+ value
+ )
+
+ testout.close()
+
+
+ @unittest.mock.patch('imago.engine.imagoIO.input', create=True)
+ def testListsCommands(self, mocked_input):
+ """Test command for listing all commands."""
+
+ mocked_input.side_effect = [
+ 'list_commands\n',
+ 'quit\n'
+ ]
+
+ testout = io.StringIO()
+ imagoIO = ImagoIO(
+ decisionAlgorithmId=DecisionAlgorithms.MONTECARLO,
+ outputStream=testout
+ )
+
+ commandsString = "\n".join(list(map(
+ lambda cmd: "%s - %s" % (cmd.__name__, cmd.__doc__),
+ imagoIO.commands_set)))
+
+ imagoIO.start()
+ value = testout.getvalue()
+ self.assertEqual(
+ '= ' +
+ commandsString +
+ '\n\n\n',
value
)
testout.close()
+
+ @unittest.mock.patch('imago.engine.imagoIO.input', create=True)
+ def testFixedHandicap(self, mocked_input):
+ """Test command for setting fixed handicap stones."""
+
+ mocked_input.side_effect = [
+ 'fixed_handicap\n',
+ 'fixed_handicap 2\n',
+ 'quit\n'
+ ]
+
+ testout = io.StringIO()
+ imagoIO = ImagoIO(
+ decisionAlgorithmId=DecisionAlgorithms.MONTECARLO,
+ outputStream=testout
+ )
+
+ imagoIO.start()
+ value = testout.getvalue()
+ self.assertEqual(
+ '? Wrong number of arguments\n' +
+ '? Usage: fixed_handicap <count>\n\n' +
+ '= A1 A2\n\n',
+ value
+ )
+
+ testout.close()
+
+
+# @unittest.mock.patch('imago.engine.imagoIO.input', create=True)
+# def testGenmove(self, mocked_input):
+# """Test command for generating a move."""
+#
+# mocked_input.side_effect = [
+# 'genmove\n',
+# 'genmove w w\n',
+# 'genmove 2\n',
+# 'quit\n'
+# ]
+#
+# testout = io.StringIO()
+# imagoIO = ImagoIO(
+# decisionAlgorithmId=DecisionAlgorithms.MONTECARLO,
+# outputStream=testout
+# )
+#
+# imagoIO.start()
+# value = testout.getvalue()
+# self.assertEqual(
+# '? Wrong number of arguments\n' +
+# '? Usage: genmove <color>\n\n' +
+# '? Wrong number of arguments\n' +
+# '? Usage: genmove <color>\n\n' +
+# '? Error: Unknown color [2].\n\n',
+# value
+# )
+#
+# mocked_input.side_effect = [
+# 'genmove w\n',
+# 'quit\n']
+#
+# testout = io.StringIO()
+# imagoIO = ImagoIO(
+# decisionAlgorithmId=DecisionAlgorithms.MONTECARLO,
+# outputStream=testout
+# )
+# imagoIO.start()
+# value = testout.getvalue()
+# vertexValue = value.split(' ')[1].split('\n')[0]
+#
+# # Test parsing vertex does not raise an error
+# parseVertex(vertexValue, imagoIO.gameEngine.gameState.size)
+#
+# testout.close()
+
+
if __name__ == '__main__':
unittest.main()