[Python-checkins] r66035 - in sandbox/trunk/ttk-gsoc/src: 2.x/test/test_functions.py 2.x/test/test_style.py 3.x/test/test_functions.py 3.x/test/test_style.py
guilherme.polo
python-checkins at python.org
Tue Aug 26 00:12:55 CEST 2008
Author: guilherme.polo
Date: Tue Aug 26 00:12:54 2008
New Revision: 66035
Log:
Added test_style;
Some more layout tests added in test_functions.
Added:
sandbox/trunk/ttk-gsoc/src/2.x/test/test_style.py
sandbox/trunk/ttk-gsoc/src/3.x/test/test_style.py
Modified:
sandbox/trunk/ttk-gsoc/src/2.x/test/test_functions.py
sandbox/trunk/ttk-gsoc/src/3.x/test/test_functions.py
Modified: sandbox/trunk/ttk-gsoc/src/2.x/test/test_functions.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/2.x/test/test_functions.py (original)
+++ sandbox/trunk/ttk-gsoc/src/2.x/test/test_functions.py Tue Aug 26 00:12:54 2008
@@ -221,6 +221,19 @@
self.failUnlessEqual(sample(i), sample_expected(i))
self.failUnlessEqual(sample(i, i), sample_expected(i, i))
+ # invalid layout format, different kind of exceptions will be
+ # raised by internal functions
+
+ # plain wrong format
+ self.failUnlessRaises(ValueError, ttk._format_layoutlist,
+ ['bad', 'format'])
+ # will try to use iteritems in the 'bad' string
+ self.failUnlessRaises(AttributeError, ttk._format_layoutlist,
+ [('name', 'bad')])
+ # bad children formatting
+ self.failUnlessRaises(ValueError, ttk._format_layoutlist,
+ [('name', {'children': {'a': None}})])
+
def test_script_from_settings(self):
# empty options
Added: sandbox/trunk/ttk-gsoc/src/2.x/test/test_style.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/ttk-gsoc/src/2.x/test/test_style.py Tue Aug 26 00:12:54 2008
@@ -0,0 +1,91 @@
+import unittest
+import Tkinter
+import ttk
+
+import support
+
+class StyleTest(unittest.TestCase):
+
+ style = ttk.Style()
+
+ def test_configure(self):
+ style = self.style
+ style.configure('TButton', background='yellow')
+ self.failUnlessEqual(style.configure('TButton', 'background'),
+ style.configure('TButton', '-background'))
+ self.failUnlessEqual(style.configure('TButton', 'background'),
+ 'yellow')
+ self.failUnless(isinstance(style.configure('TButton'), dict))
+
+
+ def test_map(self):
+ style = self.style
+ style.map('TButton', background=[('active', 'background', 'blue')])
+ self.failUnlessEqual(style.map('TButton', 'background'),
+ style.map('TButton', '-background'))
+ self.failUnlessEqual(style.map('TButton', 'background'),
+ [('active', 'background', 'blue')])
+ self.failUnless(isinstance(style.map('TButton'), dict))
+
+
+ def test_lookup(self):
+ style = self.style
+ style.configure('TButton', background='yellow')
+ style.map('TButton', background=[('active', 'background', 'blue')])
+
+ self.failUnlessEqual(style.lookup('TButton', 'background'),
+ style.lookup('TButton', '-background'))
+ self.failUnlessEqual(style.lookup('TButton', 'background'), 'yellow')
+ self.failUnlessEqual(style.lookup('TButton', 'background',
+ ['active', 'background']), 'blue')
+ self.failUnlessEqual(style.lookup('TButton', 'optionnotdefined',
+ default='iknewit'), 'iknewit')
+
+
+ def test_layout(self):
+ style = self.style
+ self.failUnlessRaises(Tkinter.TclError, style.layout, 'NotALayout')
+ tv_style = style.layout('Treeview')
+
+ # "erase" Treeview layout
+ style.layout('Treeview', '')
+ self.failUnlessEqual(style.layout('Treeview'),
+ [('null', {'sticky': 'nswe'})]
+ )
+
+ # restore layout
+ style.layout('Treeview', tv_style)
+ self.failUnlessEqual(style.layout('Treeview'), tv_style)
+
+ # should return a list
+ self.failUnless(isinstance(style.layout('TButton'), list))
+
+ # correct layout, but "option" doesn't exist as option
+ self.failUnlessRaises(Tkinter.TclError, style.layout, 'Treeview',
+ [('name', {'option': 'inexistant'})])
+
+
+ def test_theme_use(self):
+ self.failUnlessRaises(Tkinter.TclError, self.style.theme_use,
+ 'nonexistingname')
+
+ curr_theme = self.style.theme_use()
+ new_theme = None
+ for theme in self.style.theme_names():
+ if theme != curr_theme:
+ new_theme = theme
+ self.style.theme_use(theme)
+ break
+ else:
+ # just one theme available, can't go on with tests
+ return
+
+ self.failIf(curr_theme == new_theme)
+ self.failIf(new_theme != self.style.theme_use())
+
+
+def test_main():
+ support.run(StyleTest)
+
+if __name__ == "__main__":
+ test_main()
Modified: sandbox/trunk/ttk-gsoc/src/3.x/test/test_functions.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/3.x/test/test_functions.py (original)
+++ sandbox/trunk/ttk-gsoc/src/3.x/test/test_functions.py Tue Aug 26 00:12:54 2008
@@ -221,6 +221,19 @@
self.failUnlessEqual(sample(i), sample_expected(i))
self.failUnlessEqual(sample(i, i), sample_expected(i, i))
+ # invalid layout format, different kind of exceptions will be
+ # raised by internal functions
+
+ # plain wrong format
+ self.failUnlessRaises(ValueError, ttk._format_layoutlist,
+ ['bad', 'format'])
+ # will try to use iteritems in the 'bad' string
+ self.failUnlessRaises(AttributeError, ttk._format_layoutlist,
+ [('name', 'bad')])
+ # bad children formatting
+ self.failUnlessRaises(ValueError, ttk._format_layoutlist,
+ [('name', {'children': {'a': None}})])
+
def test_script_from_settings(self):
# empty options
Added: sandbox/trunk/ttk-gsoc/src/3.x/test/test_style.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/ttk-gsoc/src/3.x/test/test_style.py Tue Aug 26 00:12:54 2008
@@ -0,0 +1,91 @@
+import unittest
+import tkinter
+import ttk
+
+import support
+
+class StyleTest(unittest.TestCase):
+
+ style = ttk.Style()
+
+ def test_configure(self):
+ style = self.style
+ style.configure('TButton', background='yellow')
+ self.failUnlessEqual(style.configure('TButton', 'background'),
+ style.configure('TButton', '-background'))
+ self.failUnlessEqual(style.configure('TButton', 'background'),
+ 'yellow')
+ self.failUnless(isinstance(style.configure('TButton'), dict))
+
+
+ def test_map(self):
+ style = self.style
+ style.map('TButton', background=[('active', 'background', 'blue')])
+ self.failUnlessEqual(style.map('TButton', 'background'),
+ style.map('TButton', '-background'))
+ self.failUnlessEqual(style.map('TButton', 'background'),
+ [('active', 'background', 'blue')])
+ self.failUnless(isinstance(style.map('TButton'), dict))
+
+
+ def test_lookup(self):
+ style = self.style
+ style.configure('TButton', background='yellow')
+ style.map('TButton', background=[('active', 'background', 'blue')])
+
+ self.failUnlessEqual(style.lookup('TButton', 'background'),
+ style.lookup('TButton', '-background'))
+ self.failUnlessEqual(style.lookup('TButton', 'background'), 'yellow')
+ self.failUnlessEqual(style.lookup('TButton', 'background',
+ ['active', 'background']), 'blue')
+ self.failUnlessEqual(style.lookup('TButton', 'optionnotdefined',
+ default='iknewit'), 'iknewit')
+
+
+ def test_layout(self):
+ style = self.style
+ self.failUnlessRaises(tkinter.TclError, style.layout, 'NotALayout')
+ tv_style = style.layout('Treeview')
+
+ # "erase" Treeview layout
+ style.layout('Treeview', '')
+ self.failUnlessEqual(style.layout('Treeview'),
+ [('null', {'sticky': 'nswe'})]
+ )
+
+ # restore layout
+ style.layout('Treeview', tv_style)
+ self.failUnlessEqual(style.layout('Treeview'), tv_style)
+
+ # should return a list
+ self.failUnless(isinstance(style.layout('TButton'), list))
+
+ # correct layout, but "option" doesn't exist as option
+ self.failUnlessRaises(tkinter.TclError, style.layout, 'Treeview',
+ [('name', {'option': 'inexistant'})])
+
+
+ def test_theme_use(self):
+ self.failUnlessRaises(tkinter.TclError, self.style.theme_use,
+ 'nonexistingname')
+
+ curr_theme = self.style.theme_use()
+ new_theme = None
+ for theme in self.style.theme_names():
+ if theme != curr_theme:
+ new_theme = theme
+ self.style.theme_use(theme)
+ break
+ else:
+ # just one theme available, can't go on with tests
+ return
+
+ self.failIf(curr_theme == new_theme)
+ self.failIf(new_theme != self.style.theme_use())
+
+
+def test_main():
+ support.run(StyleTest)
+
+if __name__ == "__main__":
+ test_main()
More information about the Python-checkins
mailing list