Source

Fat x Fast / tests / widgets_tests.py

Full commit
from nose.tools import *
from FatxFast.gui import (menuwidget, boxwidget, 
    textwidget, buttonwidget, linkwidget, containerwidget)
import pygame

class TestWidgets(object):
    
    def setup(self):
        pygame.init()
        self.menuwidget = menuwidget.MenuWidget(**{"name":"testcontainer",
                                              "x":340,
                                              "y":75,
                                              "width":500,
                                              "height":600})
        
        self.textwidget = textwidget.TextWidget(**{
                                             "text": "test",
                                             "name": "text1",
                                             "size": 44,
                                             "y": "auto",
                                             "color":"grey88",
                                             "align": "center",
                                             "container": self.menuwidget
                                             })
        
        self.textwidget_nosize = textwidget.TextWidget(**{
                                             "text": "test",
                                             "name": "text2",
                                             "size": 44,
                                             "y": "auto",
                                             "color":"grey88",
                                             "align": "center",
                                             "width": 300,
                                             "height": 70,
                                             "container": self.menuwidget
                                             })
        
        self.linkwidget = linkwidget.LinkWidget(**{
                                             "text": "testlink",
                                             "name": "link1",
                                             "size": 44,
                                             "y": "auto",
                                             "color":"grey88",
                                             "align": "center",
                                             "container": self.menuwidget,
                                             "href": "pere"
                                             })
        
        self.linkwidget_nosize = linkwidget.LinkWidget(**{
                                             "text": "testlink",
                                             "name": "link2",
                                             "size": 44,
                                             "y": "auto",
                                             "color":"grey88",
                                             "align": "center",
                                             "container": self.menuwidget,
                                             "href": "pere"
                                             })
        
        """self.menuwidget.add_widget(self.textwidget_nosize.name,
                                    self.textwidget_nosize)
        self.menuwidget.add_widget(self.linkwidget_nosize.name,
                                    self.linkwidget_nosize)"""
        self.menuwidget.add_widget(self.textwidget.name, self.textwidget)
        self.menuwidget.add_widget(self.linkwidget.name, self.linkwidget)
        
    def test_container_get_widget(self):
        assert_equal(self.menuwidget.get_widget("link1"), self.linkwidget)
        
    def test_widget_set_text(self):
        old = self.linkwidget.text
        self.linkwidget.text = "aldosteroni"
        new = self.linkwidget.text
        assert_is_not(old, new)
        
    def test_line_amount_change(self):
        old = len(self.linkwidget.text.splitlines())
        self.linkwidget.text="a\na"
        new = len(self.linkwidget.text.splitlines())
        assert_is_not(old, new)
        
    def test_fix_y_pos(self):
        old = self.linkwidget.rect.y
        self.textwidget.text="""a
        a
        a"""
        new = self.linkwidget.rect.y
        assert_is_not(old, new)