Exemple #1
0
    def test_add(self):
        # Given
        rb = gui.Radiobuttons()
        checkbox1 = gui.Checkbox()
        checkbox2 = gui.Checkbox()

        # When
        rb.append(checkbox1)
        rb.append(checkbox2)

        # Then
        assert len(rb) == 2
        assert rb[0] is checkbox1
        assert rb[1] is checkbox2
Exemple #2
0
    def test_only_one_selected(self):
        # Given
        rb = gui.Radiobuttons()
        rb.append(gui.Checkbox(Rectangle(100, 100, 50, 50), False))
        rb.append(gui.Checkbox(Rectangle(100, 200, 50, 50), False))
        rb.append(gui.Checkbox(Rectangle(100, 300, 50, 50), False))
        userinput = UserInput()
        guistate = gui.GuiState()

        # When select checkbox 0
        userinput.mouse.feed_pos(Vec2D(110, 110))
        userinput.mouse.feed_down(Mouse.LEFT)
        rb.tick(userinput, guistate)

        # Then
        assert rb[0].is_selected()
        assert not rb[1].is_selected()
        assert not rb[2].is_selected()
        assert rb.get_selected() is rb[0]
        assert rb.get_selected_index() == 0

        # And when select checkbox 2
        userinput.mouse.feed_pos(Vec2D(110, 310))
        userinput.mouse.feed_down(Mouse.LEFT)
        rb.tick(userinput, guistate)

        # Then
        assert not rb[0].is_selected()
        assert not rb[1].is_selected()
        assert rb[2].is_selected()
        assert rb.get_selected() is rb[2]
        assert rb.get_selected_index() == 2

        # And when select checkbox 1
        userinput.mouse.feed_pos(Vec2D(110, 210))
        userinput.mouse.feed_down(Mouse.LEFT)
        rb.tick(userinput, guistate)

        # Then
        assert not rb[0].is_selected()
        assert rb[1].is_selected()
        assert not rb[2].is_selected()
        assert rb.get_selected() is rb[1]
        assert rb.get_selected_index() == 1
Exemple #3
0
    def test_clicked_when_mousepress_inside(self):
        # Given
        checkbox = gui.Checkbox(Rectangle(100, 100, 50, 50), False)
        userinput = UserInput()
        guistate = gui.GuiState()
        assert not checkbox.is_selected()

        # When
        userinput.mouse.feed_pos(Vec2D(110, 110))
        userinput.mouse.feed_down(Mouse.LEFT)
        checkbox.tick(userinput, guistate)

        # Then
        assert checkbox.went_down()
        assert checkbox.is_selected()

        # And when
        checkbox.tick(userinput, guistate)

        # Then
        assert not checkbox.is_selected()
Exemple #4
0
    def test_init_selected(self):
        checkbox = gui.Checkbox()
        assert not checkbox.is_selected()

        checkbox = gui.Checkbox(selected=True)
        assert checkbox.is_selected()
Exemple #5
0
 def test_init(self):
     checkbox = gui.Checkbox()