def test_adding_children(self): self.assertEqual(self.widget.children, [], ' No children added, should return a empty list.') # Create 2 children to add to widget. child1 = toga.Widget(factory=toga_dummy.factory) child2 = toga.Widget(factory=toga_dummy.factory) self.widget._children = [] self.widget.add(child1, child2) self.assertEqual(self.widget.children, [child1, child2])
def test_inserting_child_into_list_containing_one_child(self): self.assertEqual( self.widget.children, [], 'No child was inserted, should return an empty list.') # Create 2 children to insert into widget. child1 = toga.Widget(factory=toga_dummy.factory) child2 = toga.Widget(factory=toga_dummy.factory) self.widget._children = [] self.widget.insert(0, child1) self.widget.insert(1, child2) self.assertEqual(self.widget.children, [child1, child2])
def test_removing_two_out_of_three_children(self): self.assertEqual(self.widget.children, [], 'No children added, should return am empty list.') # Create 3 children to add to widget, 2 of which will be removed. child1 = toga.Widget(factory=toga_dummy.factory) child2 = toga.Widget(factory=toga_dummy.factory) child3 = toga.Widget(factory=toga_dummy.factory) self.widget._children = [] self.widget.add(child1, child2, child3) self.assertEqual(self.widget.children, [child1, child2, child3]) self.widget.remove(child1, child3) self.assertEqual(self.widget.children, [child2])
def test_adding_child_with_existing_parent(self): # Create a second parent widget. widget2 = toga.Widget(factory=toga_dummy.factory) # Create a child widget to add to widget2 before adding to widget. child = toga.Widget(factory=toga_dummy.factory) widget2._children = [] widget2.add(child) self.assertEqual(widget2.children, [child]) self.widget._children = [] self.widget.add(child) self.assertEqual(self.widget.children, [child]) self.assertEqual(widget2.children, [])
def test_inserting_child_into_list_containing_three_children(self): self.assertEqual( self.widget.children, [], 'No child was inserted, should return an empty list.') # Create 3 children to add to widget. child1 = toga.Widget(factory=toga_dummy.factory) child2 = toga.Widget(factory=toga_dummy.factory) child3 = toga.Widget(factory=toga_dummy.factory) # Create a child to insert into widget. child4 = toga.Widget(factory=toga_dummy.factory) self.widget._children = [] self.widget.add(child1, child2, child3) self.widget.insert(2, child4) self.assertEqual(self.widget.children, [child1, child2, child4, child3])
def setUp(self): self.id = 'widget_id' self.style = CSS(padding=666) self.factory = MagicMock(spec=toga_dummy.factory) self.widget = toga.Widget(id=self.id, style=self.style, factory=self.factory) self.widget._impl = MagicMock(spec=toga_dummy.widgets.base.Widget)
def setUp(self): super().setUp() self.id = 'widget_id' self.style = Pack(padding=666) self.widget = toga.Widget(id=self.id, style=self.style, factory=toga_dummy.factory)
def test_cmdset_iter_in_order(self): test_widget = toga.Widget(factory=toga_dummy.factory) test_widget._impl = Mock() test_widget.app = Mock() cs = toga.CommandSet(factory=toga_dummy.factory, widget=test_widget) commands = list(COMMANDS_IN_ORDER) random.shuffle(commands) cs.add(*commands) test_widget.app.commands.add.assert_called_once_with(*commands) self.assertEqual(list(cs), COMMANDS_IN_SET)
def test_removing_child(self): self.assertEqual(self.widget.children, [], 'No child was added, should return an empty list.') # Create a child widget to add then remove from widget. child = toga.Widget(factory=toga_dummy.factory) self.widget._children = [] self.widget.add(child) self.assertEqual(self.widget.children, [child]) self.widget.remove(child) self.assertEqual(self.widget.children, [])
def test_adding_child(self): self.assertEqual(self.widget.children, [], 'No child was added, should return an empty list.') # Create a child widget to add to widget. child = toga.Widget(factory=toga_dummy.factory) with self.assertRaises(ValueError, msg='Widget cannot have children.'): self.widget.add(child) # Deliberately set widget._children = [] to allow it to have children. # Only for test purposes! self.widget._children = [] self.widget.add(child) self.assertEqual(self.widget.children, [child])
def test_inserting_child_into_empty_list(self): self.assertEqual( self.widget.children, [], 'No child was inserted, should return an empty list.') # Create a child widget to insert into widget. child = toga.Widget(factory=toga_dummy.factory) with self.assertRaises(ValueError, msg='Widget cannot have children.'): self.widget.insert(0, child) self.widget._children = [] self.widget.insert(0, child) self.assertEqual(self.widget.children, [child])
def test_cmdset_iter(self): test_widget = toga.Widget(factory=toga_dummy.factory) cs = toga.CommandSet(test_widget) grp = toga.Group('Test group', order=10) cmd = toga.Command(lambda x: print('Hello World'), label='test', tooltip='test command', shortcut='t', icon='icons/none.png', group=grp, section=1, order=1, factory=toga_dummy.factory) cs.add(cmd) self.assertEqual(list(cs), [cmd])
def test_adding_children(self): """ """ self.assertEqual(self.widget.children, [], 'No child was added, should return a empty list.') # Create a child widget to add to the our widget. child = toga.Widget(factory=self.factory) child._impl = MagicMock(spec=toga_dummy.widgets.base.Widget) with self.assertRaises(ValueError, msg='Widget cannot have children.'): self.widget.add(child) # Deliberately set widget._children = [] to allow it to have children. # Only for test purposes! self.widget._children = [] self.widget.add(child) self.assertEqual(self.widget.children, [child])
def test_cmdset_add(self): self.changed = False test_widget = toga.Widget(factory=toga_dummy.factory) cs = toga.CommandSet(test_widget, on_change=self._changed) grp = toga.Group('Test group', order=10) cmd = toga.Command(lambda x: print('Hello World'), label='test', tooltip='test command', shortcut='t', icon='icons/none.png', group=grp, section=1, order=1, factory=toga_dummy.factory) cs.add(cmd) self.assertTrue(self.changed)
def test_command_enabler(self): test_widget = toga.Widget(factory=toga_dummy.factory) grp = toga.Group('Test group', order=10) cmd = toga.Command( lambda x: print('Hello World'), label='test', tooltip='test command', shortcut='t', icon='icons/none.png', group=grp, section=1, order=1, factory=toga_dummy.factory, ) cmd._widgets.append(test_widget) cmd._widgets[0]._impl = Mock() cmd.enabled = False self.assertEqual(cmd._enabled, False) for widget in cmd._widgets: self.assertEqual(widget.enabled, False)
def test_create_widget_with_no_style(self): widget = toga.Widget(factory=toga_dummy.factory) self.assertTrue(isinstance(widget.style, Pack))
def test_cmdset_init(self): test_widget = toga.Widget(factory=toga_dummy.factory) cs = toga.CommandSet(test_widget) self.assertEqual(cs.widget, test_widget) self.assertEqual(cs._values, set()) self.assertEqual(cs.on_change, None)
def setUp(self): self.widget = toga.Widget() self.layout = toga.Layout(self.widget)
def setUp(self): super().setUp() self.widget = toga.Widget(factory=toga_dummy.factory) self.layout = toga.Layout(self.widget)
def setUp(self): self.factory = MagicMock(spec=toga_dummy.factory) self.widget = toga.Widget(factory=self.factory) self.layout = toga.Layout(self.widget)
def setUp(self): super().setUp() self.children = [toga.Widget(factory=toga_dummy.factory)] self.box = toga.Box(children=self.children, factory=toga_dummy.factory)