def test_repaint(self): painter = MagicMock() window = MagicMock() temp = DUT.drawEmptyPlayground, DUT.getField, DUT.drawToken DUT.drawEmptyPlayground = MagicMock() # DUT.getField = MagicMock() DUT.init(window) DUT.setField(1, 0, 'x', DUT.Spielfeld) DUT.setField(1, 2, 'o', DUT.Spielfeld) DUT.drawToken = MagicMock() DUT.repaint(width=28, height=46, painter=painter, window=window) # print(DUT.drawToken.mock_calls) DUT.drawEmptyPlayground.assert_called_with(28, 46, painter) painter.setPen.assert_called_with(window.thickBlackPen) calls = list() calls = [ call(' ', 4.5, 7.5, 8.1, 13.5, painter, window), call(' ', 4.5, 22.5, 8.1, 13.5, painter, window), call(' ', 4.5, 37.5, 8.1, 13.5, painter, window), call('x', 13.5, 7.5, 8.1, 13.5, painter, window), call(' ', 13.5, 22.5, 8.1, 13.5, painter, window), call('o', 13.5, 37.5, 8.1, 13.5, painter, window), call(' ', 22.5, 7.5, 8.1, 13.5, painter, window), call(' ', 22.5, 22.5, 8.1, 13.5, painter, window), call(' ', 22.5, 37.5, 8.1, 13.5, painter, window) ] DUT.drawToken.assert_has_calls(calls, any_order=True) DUT.drawEmptyPlayground, DUT.getField, DUT.drawToken = temp
def test_setField(self): field = DUT.createEmptyPlayground() DUT.setField(0, 1, 'o', field) DUT.setField(2, 2, 'x', field) self.assertEqual(field, [' ', ' ', ' ', 'o', ' ', ' ', ' ', ' ', 'x'])
def test_GetField(self): field = DUT.createEmptyPlayground() DUT.setField(0, 0, 'x', field) DUT.setField(1, 2, 'o', field) self.assertEqual(DUT.getField(0, 0, field), 'x') self.assertEqual(DUT.getField(1, 1, field), ' ') self.assertEqual(DUT.getField(1, 2, field), 'o')
def test_SetField_Occupied(self): field = DUT.createEmptyPlayground() result1 = DUT.setField(0, 0, 'x', field) result2 = DUT.setField(0, 0, 'x', field) result3 = DUT.setField(0, 0, 'o', field) self.assertTrue(result1) self.assertFalse(result2) self.assertFalse(result3)
def test_SetField_UnknownToken(self): field = DUT.createEmptyPlayground() with self.assertRaises(ValueError) as context: DUT.setField(0, 0, ' ', field) with self.assertRaises(ValueError) as context: DUT.setField(0, 0, '', field) with self.assertRaises(ValueError) as context: DUT.setField(0, 0, 'ox', field) with self.assertRaises(ValueError) as context: DUT.setField(0, 0, 'x0', field)
def test_SetField_OutOfField(self): field = DUT.createEmptyPlayground() with self.assertRaises(IndexError) as context: DUT.setField(0, 10, 'o', field) with self.assertRaises(IndexError) as context: DUT.setField(2, -5, 'o', field) with self.assertRaises(IndexError) as context: DUT.setField(3, 0, 'o', field)
def setMany(self, tokens, field): for j in range(3): for i in range(3): token = tokens[i][j] if token in "xo": DUT.setField(j, i, token, field)