ROX base platform is now Python 2.3, so run unit tests against that by default
[rox-lib.git] / tests / python / testmenu.py
blob86368718a88b6e8a73a72b22e542b1c6042555c0
1 #!/usr/bin/env python2.3
2 import unittest
3 import os, sys, shutil
4 from os.path import dirname, abspath, join
5 rox_lib = dirname(dirname(dirname(abspath(sys.argv[0]))))
6 sys.path.insert(0, join(rox_lib, 'python'))
8 os.environ['CHOICESPATH'] = '/tmp/choices:/tmp/choices2'
9 os.environ['XDG_CONFIG_HOME'] = '/tmp/config'
11 import rox
12 from rox.Menu import Menu, set_save_name, SubMenu
13 from rox.Menu import Separator, Action, ToggleItem
14 from rox import basedir, choices, g
15 set_save_name('Foo')
17 class MyToggleItem(ToggleItem):
18 my_widget = None
20 def update(self, menu, widget):
21 self.my_menu = menu
22 self.my_widget = widget
23 ToggleItem.update(self, menu, widget)
25 class TestMenu(unittest.TestCase):
26 t1 = False
27 t2 = True
29 def setUp(self):
30 self.my_t1 = MyToggleItem('Toggle 1', 't1')
31 self.my_t2 = MyToggleItem('Toggle 2', 't2')
33 self.menu = Menu('main', [
34 SubMenu('File', [
35 Action('Save', 'save', '<Ctrl>S', g.STOCK_SAVE),
36 Action('Parent', 'up', '', g.STOCK_GO_UP),
37 Action('Close', 'close','', g.STOCK_CLOSE),
38 Separator(),
39 Action('New', 'new', '', g.STOCK_NEW)]),
40 Action('Help', 'help', 'F1', g.STOCK_HELP),
41 self.my_t1,
42 self.my_t2,
45 def tearDown(self):
46 self.menu.menu.destroy()
48 def testNothing(self):
49 pass
51 def testToggles(self):
52 self.menu.popup(self, None)
53 assert self.my_t1.my_widget != None
54 assert self.my_t2.my_widget != None
56 assert self.my_t2.my_widget != self.my_t1.my_widget
57 assert self.my_t1.my_menu == self.my_t2.my_menu == self.menu
59 suite = unittest.makeSuite(TestMenu)
60 if __name__ == '__main__':
61 sys.argv.append('-v')
62 unittest.main()