test_menu.py 2.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
import unittest
from unittests import wtc
import wx
import os

pngFile = os.path.join(os.path.dirname(__file__), 'pointy.png')

#---------------------------------------------------------------------------

class menu_Tests(wtc.WidgetTestCase):

    def makeMenu(self):
        m = wx.Menu()
        for label in "one two three four".split():
            m.Append(-1, label)
        return m

    def makeMenuWithSubmenu(self):
        m = self.makeMenu()
        m.AppendSeparator()
        m2 = self.makeMenu()
        m.Append(-1, 'submenu', m2)
        return m


    def test_menu1(self):
        m = self.makeMenu()
        items = m.GetMenuItems()
        self.assertTrue(len(items) == 4)
        self.assertTrue(isinstance(items[0], wx.MenuItem))

    def test_menu2(self):
        m = self.makeMenuWithSubmenu()
        items = m.GetMenuItems()
        self.assertTrue(len(items) == 6)

    def test_menu3(self):
        m = self.makeMenuWithSubmenu()
        items = []
        for i in m.GetMenuItems():
            self.assertTrue(isinstance(i, wx.MenuItem))
            items.append(i)
        self.assertTrue(len(items) == 6)


    def test_menuBar1(self):
        mb = wx.MenuBar()
        for label in "one two three four".split():
            m = self.makeMenu()
            mb.Append(m, label)
        self.frame.SetMenuBar(mb)

    def test_menuBar2(self):
        mb = wx.MenuBar()
        for label in "one two three four".split():
            m = self.makeMenu()
            mb.Append(m, label)
        menus = mb.GetMenus()
        self.assertTrue(len(menus) == 4)
        menu, label = menus[0]
        self.assertTrue(isinstance(menu, wx.Menu))
        self.assertTrue(label == 'one')


    def test_menuBar3(self):
        mb = wx.MenuBar()
        for label in "one two three four".split():
            m = self.makeMenu()
            mb.Append(m, label)
        menu = m
        item = menu.FindItemByPosition(0)

        i, m = mb.FindItem(item.GetId())
        self.assertTrue(i is item)
        self.assertTrue(m is menu)
        i = mb.FindItemById(item.GetId())
        self.assertTrue(i is item)

        i, m = menu.FindItem(item.GetId())
        self.assertTrue(i is item)
        self.assertTrue(m is menu)
        i = menu.FindItemById(item.GetId())
        self.assertTrue(i is item)


#---------------------------------------------------------------------------


if __name__ == '__main__':
    unittest.main()