def test_grid_layout(self): """ Test the grid layout helper. """ from enable.layout.api import align, grid from enable.layout.layout_helpers import DefaultSpacing c3 = Component() c4 = Component() self.container.add(c3) self.container.add(c4) self.container.layout_constraints = [ grid([self.c1, self.c2], [c3, c4]), align("layout_width", self.c1, self.c2, c3, c4), align("layout_height", self.c1, self.c2, c3, c4), ] space = DefaultSpacing.ABUTMENT c2_pos = [ self.c1.position[0] + self.c1.bounds[0] + space, self.c1.position[1], ] self.assertTrue(self.c2.position == c2_pos)
def setUp(self): from enable.api import ConstraintsContainer self.container = ConstraintsContainer(bounds=[100.0, 100.0]) self.c1 = Component() self.c2 = Component() self.container.add(self.c1) self.container.add(self.c2)
def setUp(self): self.undo_manager = UndoManager() self.undo_manager.undo = MagicMock() self.undo_manager.redo = MagicMock() self.component = Component() self.tool = UndoTool(component=self.component, undo_manager=self.undo_manager) self.component.tools.append(self.tool)
class UndoToolTestCase(unittest.TestCase, EnableTestAssistant, UnittestTools): def setUp(self): self.undo_manager = UndoManager() self.undo_manager.undo = MagicMock() self.undo_manager.redo = MagicMock() self.component = Component() self.tool = UndoTool(component=self.component, undo_manager=self.undo_manager) self.component.tools.append(self.tool) def test_undo_key_press(self): key_event = self.create_key_press('z', control_down=True) self.component.dispatch(key_event, 'key_pressed') self.assertTrue(self.undo_manager.undo.called) self.assertFalse(self.undo_manager.redo.called) self.assertTrue(key_event.handled) def test_redo_key_press(self): key_event = self.create_key_press('z', control_down=True, shift_down=True) self.component.dispatch(key_event, 'key_pressed') self.assertTrue(key_event.handled) self.assertFalse(self.undo_manager.undo.called) self.assertTrue(self.undo_manager.redo.called) def test_other_key_press(self): key_event = self.create_key_press('z') self.component.dispatch(key_event, 'key_pressed') self.assertFalse(self.undo_manager.undo.called) self.assertFalse(self.undo_manager.redo.called) self.assertFalse(key_event.handled) def test_undo_key_press_non_default(self): self.tool.undo_keys = [KeySpec('Left', 'control')] key_event = self.create_key_press('Left', control_down=True) self.component.dispatch(key_event, 'key_pressed') self.assertTrue(self.undo_manager.undo.called) self.assertFalse(self.undo_manager.redo.called) self.assertTrue(key_event.handled) def test_redo_key_press_non_default(self): self.tool.redo_keys = [KeySpec('Right', 'control')] key_event = self.create_key_press('Right', control_down=True) self.component.dispatch(key_event, 'key_pressed') self.assertTrue(key_event.handled) self.assertFalse(self.undo_manager.undo.called) self.assertTrue(self.undo_manager.redo.called)
def setUp(self): GuiTestAssistant.setUp(self) self.component = Component(position=[LOWER_BOUND, LOWER_BOUND], bounds=[SIZE, SIZE]) # add hover tool with hover zone in lower-left corner of component self.tool = HoverTool(component=self.component, area_type="LL") self.component.tools.append(self.tool)
def test_mouse_move_while_down(self): test_assistant = EnableTestAssistant() component = Component(bounds=[100, 200]) event = test_assistant.mouse_move(component, 10, 20, left_down=True) self.assertEqual(event.x, 10) self.assertEqual(event.y, 20) self.assertIs(event.left_down, True)
def setUp(self): self.command_stack = CommandStack() self.command_stack.push = MagicMock() self.component = Component(position=[50, 50], bounds=[100, 100]) self.container = Container() self.container.add(self.component) self.tool = ResizeCommandTool(component=self.component, command_stack=self.command_stack) self.component.tools.append(self.tool)
def setUp(self): super(HoverToolTestCase, self).setUp() self.component = Component( position=[LOWER_BOUND, LOWER_BOUND], bounds=[SIZE, SIZE], ) # add hover tool with hover zone in lower-left corner of component self.tool = HoverTool(component=self.component, area_type='LL') self.component.tools.append(self.tool)
def test_component_bounds_updated(self, mock_method): """ Make sure trait listener for changing component bounds gets set up. """ class TestWindow(AbstractWindow): # needed to avoid a NotImplementedError, not under test def _redraw(self): pass def _get_control_size(self): # this happens in the wild return None thing = Component() TestWindow( parent=None, component=thing, ) thing.bounds = [13.0, 13.0] self.assertTrue(mock_method.called)
def test_mouse_move(): test_assistant = EnableTestAssistant() component = Component(bounds=[100, 200]) event = test_assistant.mouse_move(component, 10, 20) nose.tools.assert_equal(event.x, 10) nose.tools.assert_equal(event.y, 20) assert isinstance(event.window, _MockWindow) assert not event.alt_down assert not event.control_down assert not event.shift_down nose.tools.assert_equal(event.window.get_pointer_position(), (10, 20))
def test_merge_wrong_component(self): command = self.command command.mergeable = True other_component = Component() other_command = MoveCommand( component=other_component, data=(0, 0), previous_position=(50, 50)) with self.assertTraitDoesNotChange(command, 'data'): merged = command.merge(other_command) self.assertFalse(merged) self.assertEqual(command.data, (25, 25))
def test_mouse_move(self): test_assistant = EnableTestAssistant() component = Component(bounds=[100, 200]) event = test_assistant.mouse_move(component, 10, 20) self.assertEqual(event.x, 10) self.assertEqual(event.y, 20) self.assertIsInstance(event.window, _MockWindow) self.assertFalse(event.alt_down) self.assertFalse(event.control_down) self.assertFalse(event.shift_down) self.assertEqual(event.window.get_pointer_position(), (10, 20))
def test_merge_wrong_component(self): command = self.command command.mergeable = True other_component = Component() other_command = ResizeCommand(component=other_component, data=(0, 0, 200, 200), previous_rectangle=(50, 50, 100, 100)) with self.assertTraitDoesNotChange(command, 'data'): merged = command.merge(other_command) self.assertFalse(merged) self.assertEqual(command.data, (25, 25, 150, 150))
def test_cleanup(self): class TestWindow(AbstractWindow): def _redraw(self): pass def _get_control_size(self): return (10, 10) thing = Component() window = TestWindow( parent=None, component=thing, ) window.cleanup() self.assertIsNone(window.component)
def test_mouse_move_real_window(): from enable.api import Window test_assistant = EnableTestAssistant() component = Component(bounds=[100, 200]) window = Window(None, component=component) event = test_assistant.mouse_move(component, 10, 20, window) nose.tools.assert_equal(event.x, 10) nose.tools.assert_equal(event.y, 20) nose.tools.assert_equal(event.window, window) assert not event.alt_down assert not event.control_down assert not event.shift_down
def test_mouse_move_real_window(self): from enable.api import Window test_assistant = EnableTestAssistant() component = Component(bounds=[100, 200]) window = Window(None, component=component) event = test_assistant.mouse_move(component, 10, 20, window) self.assertEqual(event.x, 10) self.assertEqual(event.y, 20) self.assertEqual(event.window, window) self.assertFalse(event.alt_down) self.assertFalse(event.control_down) self.assertFalse(event.shift_down)
def test_mouse_move_real_window_mocked_position(): from enable.api import Window test_assistant = EnableTestAssistant() component = Component(bounds=[100, 200]) with mock.patch.object(Window, 'get_pointer_position', return_value=None): window = Window(None, component=component) event = test_assistant.mouse_move(component, 10, 20, window) nose.tools.assert_equal(event.x, 10) nose.tools.assert_equal(event.y, 20) nose.tools.assert_equal(event.window, window) assert not event.alt_down assert not event.control_down assert not event.shift_down nose.tools.assert_equal(event.window.get_pointer_position(), (10, 20))
def test_mouse_move_real_window_mocked_position(self): from enable.api import Window test_assistant = EnableTestAssistant() component = Component(bounds=[100, 200]) patch = mock.patch.object(Window, "get_pointer_position", return_value=None) with patch: window = Window(None, component=component) event = test_assistant.mouse_move(component, 10, 20, window) self.assertEqual(event.x, 10) self.assertEqual(event.y, 20) self.assertEqual(event.window, window) self.assertFalse(event.alt_down) self.assertFalse(event.control_down) self.assertFalse(event.shift_down) self.assertEqual(event.window.get_pointer_position(), (10, 20))
def test_share_layout(self): """ Test sharing layouts with a child container. """ from enable.api import ConstraintsContainer from enable.layout.api import hbox, align self.child_container = ConstraintsContainer(bounds=[50, 50]) c3 = Component() self.child_container.add(c3) self.container.add(self.child_container) self.container.layout_constraints = [ hbox(self.c1, self.c2, c3), align("layout_width", self.c1, self.c2, c3), ] self.assertTrue(self.c1.bounds[0] == self.c2.bounds[0] != c3.bounds[0]) self.child_container.share_layout = True self.container.relayout() self.assertTrue(self.c1.bounds[0] == self.c2.bounds[0] == c3.bounds[0])
def setUp(self): self.component = Component(position=[50, 50], bounds=[100, 100], padding=10) self.tool = ResizeTool(component=self.component)
def test_mouse_dclick(self): test_assistant = EnableTestAssistant() component = Component(bounds=[100, 200]) component.normal_left_dclick = mock.Mock() test_assistant.mouse_dclick(component, x=0, y=0) component.normal_left_dclick.assert_called_once()
def setUp(self): self.component = Component(position=[50, 50], bounds=[100, 100]) self.tool = ButtonTool(component=self.component) self.component.tools.append(self.tool)
def setUp(self): self.component = Component() self.command = ComponentCommand(component=self.component)
def setUp(self): self.component = Component(position=[50, 50], bounds=[100, 100]) self.component.request_redraw = MagicMock() self.command = ResizeCommand(self.component, (25, 25, 150, 150), (50, 50, 100, 100))