[Python-checkins] r65938 - in sandbox/trunk/ttk-gsoc/src: 2.x/test_ttk.py 3.x/test_ttk.py

guilherme.polo python-checkins at python.org
Thu Aug 21 19:37:50 CEST 2008


Author: guilherme.polo
Date: Thu Aug 21 19:37:50 2008
New Revision: 65938

Log:
Some more tests added for internal functions

Modified:
   sandbox/trunk/ttk-gsoc/src/2.x/test_ttk.py
   sandbox/trunk/ttk-gsoc/src/3.x/test_ttk.py

Modified: sandbox/trunk/ttk-gsoc/src/2.x/test_ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/2.x/test_ttk.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/2.x/test_ttk.py	Thu Aug 21 19:37:50 2008
@@ -126,14 +126,21 @@
         # IndexError since it tries to access the index 0 of an empty tuple
         self.failUnlessRaises(IndexError, ttk._format_elemcreate, 'image')
         
+        # don't format returned values as a tcl script
+        # minimum acceptable for image type
         self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test'),
             ("test ", ()))
+        # specifiyng a state spec
         self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test',
             ('', 'a')), ("test {} a", ()))
+        # state spec with multiple states
         self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test',
             ('a', 'b', 'c')), ("test {a b} c", ()))
+        # state spec and options
         self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test',
-            ('a', 'b'), a='x'), ("test a b", ("-a", "x")))
+            ('a', 'b'), a='x', b='y'), ("test a b", ("-a", "x", "-b", "y")))
+        # format returned values as a tcl script
+        # state spec with multiple states and an option with a multivalue
         self.failUnlessEqual(ttk._format_elemcreate('image', True, 'test',
             ('a', 'b', 'c', 'd'), x=[2, 3]), ("{test {a b c} d}", "-x {2 3}"))
 
@@ -143,12 +150,18 @@
         # an empty tuple
         self.failUnlessRaises(ValueError, ttk._format_elemcreate, 'vsapi')
 
+        # don't format returned values as a tcl script
+        # minimum acceptable for vsapi
         self.failUnlessEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b'),
             ("a b ", ()))
+        # now with a state spec with multiple states
         self.failUnlessEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b',
             ('a', 'b', 'c')), ("a b {a b} c", ()))
+        # state spec and option
         self.failUnlessEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b',
             ('a', 'b'), opt='x'), ("a b a b", ("-opt", "x")))
+        # format returned values as a tcl script
+        # state spec with a multivalue and an option
         self.failUnlessEqual(ttk._format_elemcreate('vsapi', True, 'a', 'b',
             ('a', 'b', [1, 2]), opt='x'), ("{a b {a b} {1 2}}", "-opt x"))
 
@@ -209,8 +222,46 @@
 
 
     def test_script_from_settings(self):
-        # XXX ToDo
-        pass
+        # empty options
+        self.failIf(ttk._script_from_settings({'name':
+            {'configure': None, 'map': None, 'element create': None}}))
+
+        # empty layout
+        self.failUnlessEqual(
+            ttk._script_from_settings({'name': {'layout': None}}),
+            "ttk::style layout name {\nnull\n}")
+
+        configdict = {u'αβγ': True, u'á': False}
+        self.failUnless(
+            ttk._script_from_settings({'name': {'configure': configdict}}))
+
+        mapdict = {u'üñíćódè': [(u'á', u'vãl')]}
+        self.failUnless(
+            ttk._script_from_settings({'name': {'map': mapdict}}))
+
+        # invalid image element
+        self.failUnlessRaises(IndexError,
+            ttk._script_from_settings, {'name': {'element create': ['image']}})
+
+        # minimal valid image
+        self.failUnless(ttk._script_from_settings({'name':
+            {'element create': ['image', 'name']}}))
+
+        image = {'thing': {'element create':
+            ['image', 'name', ('state1', 'state2', 'val')]}}
+        self.failUnlessEqual(ttk._script_from_settings(image),
+            "ttk::style element create thing image {name {state1 state2} val} ")
+
+        image['thing']['element create'].append({'opt': 30})
+        self.failUnlessEqual(ttk._script_from_settings(image),
+            "ttk::style element create thing image {name {state1 state2} val} "
+            "-opt 30")
+
+        image['thing']['element create'][-1]['opt'] = [MockTclObj(3),
+            MockTclObj('2m')]
+        self.failUnlessEqual(ttk._script_from_settings(image),
+            "ttk::style element create thing image {name {state1 state2} val} "
+            "-opt {3 2m}")
 
 
     def test_dict_from_tcltuple(self):
@@ -253,8 +304,49 @@
 
 
     def test_list_from_layouttuple(self):
-        # XXX ToDo
-        pass
+        # empty layout tuple
+        self.failIf(ttk._list_from_layouttuple(()))
+
+        # shortest layout tuple
+        self.failUnlessEqual(ttk._list_from_layouttuple(('name', )),
+            [('name', {})])
+
+        # not so interesting ltuple
+        sample_ltuple = ('name', '-option', 'value')
+        self.failUnlessEqual(ttk._list_from_layouttuple(sample_ltuple),
+            [('name', {'option': 'value'})])
+
+        # empty children
+        self.failUnlessEqual(ttk._list_from_layouttuple(
+            ('something', '-children', ())),
+            [('something', {'children': []})]
+        )
+
+        # more interesting ltuple
+        ltuple = (
+            'name', '-option', 'niceone', '-children', (
+                ('otherone', '-children', (
+                    ('child', )), '-otheropt', 'othervalue'
+                )
+            )
+        )
+        self.failUnlessEqual(ttk._list_from_layouttuple(ltuple),
+            [('name', {'option': 'niceone', 'children':
+                [('otherone', {'otheropt': 'othervalue', 'children':
+                    [('child', {})]
+                })]
+            })]
+        )
+
+        # bad tuples
+        self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
+            ('name', 'no_minus'))
+        self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
+            ('name', 'no_minus', 'value'))
+        self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
+            ('something', '-children')) # no children
+        self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
+            ('something', '-children', 'value')) # invalid children
 
 
     def test_val_or_dict(self):

Modified: sandbox/trunk/ttk-gsoc/src/3.x/test_ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/3.x/test_ttk.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/3.x/test_ttk.py	Thu Aug 21 19:37:50 2008
@@ -10,7 +10,7 @@
         self.val = val
 
     def __str__(self):
-        return self.val
+        return str(self.val)
 
 
 class MockStateSpec(object):
@@ -74,13 +74,13 @@
         self.failUnlessEqual(amount_opts, len(opts) - 1)
 
         # ignore every option
-        self.failIf(ttk._format_optdict(opts, ignore=opts.keys()))
+        self.failIf(ttk._format_optdict(opts, ignore=list(opts.keys())))
 
 
     def test_format_mapdict(self):
         opts = {'a': [('b', 'c', 'val'), ('d', 'otherval'), ('', 'single')]}
         result = ttk._format_mapdict(opts)
-        self.failUnlessEqual(len(result), len(opts.keys()) * 2)
+        self.failUnlessEqual(len(result), len(list(opts.keys())) * 2)
         self.failUnlessEqual(result, ('-a', '{b c} val d otherval {} single'))
         self.failUnlessEqual(ttk._format_mapdict(opts, script=True),
             ('-a', '{{b c} val d otherval {} single}'))
@@ -126,14 +126,21 @@
         # IndexError since it tries to access the index 0 of an empty tuple
         self.failUnlessRaises(IndexError, ttk._format_elemcreate, 'image')
         
+        # don't format returned values as a tcl script
+        # minimum acceptable for image type
         self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test'),
             ("test ", ()))
+        # specifiyng a state spec
         self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test',
             ('', 'a')), ("test {} a", ()))
+        # state spec with multiple states
         self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test',
             ('a', 'b', 'c')), ("test {a b} c", ()))
+        # state spec and options
         self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test',
-            ('a', 'b'), a='x'), ("test a b", ("-a", "x")))
+            ('a', 'b'), a='x', b='y'), ("test a b", ("-a", "x", "-b", "y")))
+        # format returned values as a tcl script
+        # state spec with multiple states and an option with a multivalue
         self.failUnlessEqual(ttk._format_elemcreate('image', True, 'test',
             ('a', 'b', 'c', 'd'), x=[2, 3]), ("{test {a b c} d}", "-x {2 3}"))
 
@@ -143,12 +150,18 @@
         # an empty tuple
         self.failUnlessRaises(ValueError, ttk._format_elemcreate, 'vsapi')
 
+        # don't format returned values as a tcl script
+        # minimum acceptable for vsapi
         self.failUnlessEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b'),
             ("a b ", ()))
+        # now with a state spec with multiple states
         self.failUnlessEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b',
             ('a', 'b', 'c')), ("a b {a b} c", ()))
+        # state spec and option
         self.failUnlessEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b',
             ('a', 'b'), opt='x'), ("a b a b", ("-opt", "x")))
+        # format returned values as a tcl script
+        # state spec with a multivalue and an option
         self.failUnlessEqual(ttk._format_elemcreate('vsapi', True, 'a', 'b',
             ('a', 'b', [1, 2]), opt='x'), ("{a b {a b} {1 2}}", "-opt x"))
 
@@ -209,8 +222,46 @@
 
 
     def test_script_from_settings(self):
-        # XXX ToDo
-        pass
+        # empty options
+        self.failIf(ttk._script_from_settings({'name':
+            {'configure': None, 'map': None, 'element create': None}}))
+
+        # empty layout
+        self.failUnlessEqual(
+            ttk._script_from_settings({'name': {'layout': None}}),
+            "ttk::style layout name {\nnull\n}")
+
+        configdict = {'αβγ': True, 'á': False}
+        self.failUnless(
+            ttk._script_from_settings({'name': {'configure': configdict}}))
+
+        mapdict = {'üñíćódè': [('á', 'vãl')]}
+        self.failUnless(
+            ttk._script_from_settings({'name': {'map': mapdict}}))
+
+        # invalid image element
+        self.failUnlessRaises(IndexError,
+            ttk._script_from_settings, {'name': {'element create': ['image']}})
+
+        # minimal valid image
+        self.failUnless(ttk._script_from_settings({'name':
+            {'element create': ['image', 'name']}}))
+
+        image = {'thing': {'element create':
+            ['image', 'name', ('state1', 'state2', 'val')]}}
+        self.failUnlessEqual(ttk._script_from_settings(image),
+            "ttk::style element create thing image {name {state1 state2} val} ")
+
+        image['thing']['element create'].append({'opt': 30})
+        self.failUnlessEqual(ttk._script_from_settings(image),
+            "ttk::style element create thing image {name {state1 state2} val} "
+            "-opt 30")
+
+        image['thing']['element create'][-1]['opt'] = [MockTclObj(3),
+            MockTclObj('2m')]
+        self.failUnlessEqual(ttk._script_from_settings(image),
+            "ttk::style element create thing image {name {state1 state2} val} "
+            "-opt {3 2m}")
 
 
     def test_dict_from_tcltuple(self):
@@ -253,8 +304,49 @@
 
 
     def test_list_from_layouttuple(self):
-        # XXX ToDo
-        pass
+        # empty layout tuple
+        self.failIf(ttk._list_from_layouttuple(()))
+
+        # shortest layout tuple
+        self.failUnlessEqual(ttk._list_from_layouttuple(('name', )),
+            [('name', {})])
+
+        # not so interesting ltuple
+        sample_ltuple = ('name', '-option', 'value')
+        self.failUnlessEqual(ttk._list_from_layouttuple(sample_ltuple),
+            [('name', {'option': 'value'})])
+
+        # empty children
+        self.failUnlessEqual(ttk._list_from_layouttuple(
+            ('something', '-children', ())),
+            [('something', {'children': []})]
+        )
+
+        # more interesting ltuple
+        ltuple = (
+            'name', '-option', 'niceone', '-children', (
+                ('otherone', '-children', (
+                    ('child', )), '-otheropt', 'othervalue'
+                )
+            )
+        )
+        self.failUnlessEqual(ttk._list_from_layouttuple(ltuple),
+            [('name', {'option': 'niceone', 'children':
+                [('otherone', {'otheropt': 'othervalue', 'children':
+                    [('child', {})]
+                })]
+            })]
+        )
+
+        # bad tuples
+        self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
+            ('name', 'no_minus'))
+        self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
+            ('name', 'no_minus', 'value'))
+        self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
+            ('something', '-children')) # no children
+        self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
+            ('something', '-children', 'value')) # invalid children
 
 
     def test_val_or_dict(self):


More information about the Python-checkins mailing list