MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / test_main

Function test_main

tests/test_fourinarow.py:157–179  ·  view source on GitHub ↗
(capsys)

Source from the content-addressed store, hash-verified

155 ' +-------+\n' in captured.out
156
157def test_main(capsys):
158 # Test a game where X wins:
159 with pytest.raises(SystemExit):
160 sys.stdin = io.StringIO('1\n2\n1\n2\n1\n2\n1\n')
161 fourinarow.main()
162 captured = capsys.readouterr()
163 assert 'Player X has won!' in captured.out
164
165 # Test a game where O wins:
166 with pytest.raises(SystemExit):
167 sys.stdin = io.StringIO('1\n2\n1\n2\n1\n2\n3\n2\n')
168 fourinarow.main()
169 captured = capsys.readouterr()
170 assert 'Player O has won!' in captured.out
171
172 # Test a game that ends in a tie:
173 moves = ('123456' * 3) + ('712345' * 3) + ('67' * 3)
174 moves = '\n'.join(moves) + '\n'
175 with pytest.raises(SystemExit):
176 sys.stdin = io.StringIO(moves)
177 fourinarow.main()
178 captured = capsys.readouterr()
179 assert 'There is a tie!' in captured.out
180

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected