class TestUIButton(unittest.TestCase): def setUp(self): self.button = UIButton() self.button.size = Vector(20, 20) self.button.position = Vector(10, 10) def test_ui_button_clicked(self): '''Test if we can accurately click a button''' good_presses = [ (10, 10), (20, 20), (30, 10), (30, 30), (10, 30) ] for x, y in good_presses: mock = Mock() self.button.command = mock self.button.register_mouse_pressed(x, y, None, None) self.assertTrue(mock.called) def test_ui_button_not_pressed(self): '''Test if missing the button doesn't click''' bad_presses = [ (0, 0), (9, 10), (10, 9), (30, 31), (31, 30), (40, 40), ] for x, y in bad_presses: mock = Mock() self.button.command = mock self.button.register_mouse_pressed(x, y, None, None) self.assertFalse(mock.called, 'Location {}'.format((x, y)))
def setUp(self): self.button = UIButton() self.button.size = Vector(20, 20) self.button.position = Vector(10, 10)