Beispiel #1
0
    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])
Beispiel #2
0
    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])
Beispiel #3
0
    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])
Beispiel #4
0
    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, [])
Beispiel #5
0
    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])
Beispiel #6
0
    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)
Beispiel #7
0
    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)
Beispiel #8
0
 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)
Beispiel #9
0
    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, [])
Beispiel #10
0
    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])
Beispiel #11
0
    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])
Beispiel #12
0
 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])
Beispiel #13
0
    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])
Beispiel #14
0
 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)
Beispiel #15
0
    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)
Beispiel #16
0
 def test_create_widget_with_no_style(self):
     widget = toga.Widget(factory=toga_dummy.factory)
     self.assertTrue(isinstance(widget.style, Pack))
Beispiel #17
0
 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)
Beispiel #18
0
 def setUp(self):
     self.widget = toga.Widget()
     self.layout = toga.Layout(self.widget)
Beispiel #19
0
    def setUp(self):
        super().setUp()

        self.widget = toga.Widget(factory=toga_dummy.factory)
        self.layout = toga.Layout(self.widget)
Beispiel #20
0
 def setUp(self):
     self.factory = MagicMock(spec=toga_dummy.factory)
     self.widget = toga.Widget(factory=self.factory)
     self.layout = toga.Layout(self.widget)
Beispiel #21
0
 def setUp(self):
     super().setUp()
     self.children = [toga.Widget(factory=toga_dummy.factory)]
     self.box = toga.Box(children=self.children, factory=toga_dummy.factory)