[Python-checkins] r65987 - in sandbox/trunk/ttk-gsoc: Doc/library/ttk.rst src/2.x/test/runtests.py src/2.x/test/test_treeview.py src/2.x/ttk.py src/3.x/test/runtests.py src/3.x/test/test_treeview.py src/3.x/ttk.py

guilherme.polo python-checkins at python.org
Sat Aug 23 05:36:51 CEST 2008


Author: guilherme.polo
Date: Sat Aug 23 05:36:51 2008
New Revision: 65987

Log:
Method exists (Treeview) should always return either True or False now;
Some more tests added for treeview;
Updated runtests.py to show a message telling when GUI tests didn't execute.


Modified:
   sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst
   sandbox/trunk/ttk-gsoc/src/2.x/test/runtests.py
   sandbox/trunk/ttk-gsoc/src/2.x/test/test_treeview.py
   sandbox/trunk/ttk-gsoc/src/2.x/ttk.py
   sandbox/trunk/ttk-gsoc/src/3.x/test/runtests.py
   sandbox/trunk/ttk-gsoc/src/3.x/test/test_treeview.py
   sandbox/trunk/ttk-gsoc/src/3.x/ttk.py

Modified: sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst
==============================================================================
--- sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst	(original)
+++ sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst	Sat Aug 23 05:36:51 2008
@@ -909,7 +909,8 @@
 
    .. method:: exists(item)
 
-      Returns 1 if the specified *item* is present in the three, 0 otherwise.
+      Returns True if the specified *item* is present in the three,
+      False otherwise.
 
 
    .. method:: focus([item=None])

Modified: sandbox/trunk/ttk-gsoc/src/2.x/test/runtests.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/2.x/test/runtests.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/2.x/test/runtests.py	Sat Aug 23 05:36:51 2008
@@ -20,10 +20,12 @@
 
 def main(args):
     gui_tests = False
-    if 'DISPLAY' in os.environ or (len(args) > 1 and args[1] == "-g"):
+    if 'DISPLAY' in os.environ or (len(args) > 1 and "-g" in args):
         gui_tests = True
 
     run_tests(get_tests(gui_tests))
+    if not gui_tests:
+        print "\n** GUI tests didn't run **"
 
 if __name__ == "__main__":
     main(sys.argv)

Modified: sandbox/trunk/ttk-gsoc/src/2.x/test/test_treeview.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/2.x/test/test_treeview.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/2.x/test/test_treeview.py	Sat Aug 23 05:36:51 2008
@@ -112,6 +112,11 @@
         item_id = self.tv.insert('', 'end')
         item2 = self.tv.insert(item_id, 'end')
 
+        # calling detach without items is valid, although it does nothing
+        prev = self.tv.get_children()
+        self.tv.detach() # this should do nothing
+        self.failUnlessEqual(prev, self.tv.get_children())
+
         self.failUnlessEqual(self.tv.get_children(), (item_id, ))
         self.failUnlessEqual(self.tv.get_children(item_id), (item2, ))
 
@@ -145,6 +150,77 @@
         self.failUnlessEqual(self.tv.get_children(item_id), ())
 
 
+    def test_exists(self):
+        self.failUnless(self.tv.exists('something') is False)
+        self.failUnless(self.tv.exists('') is True)
+        self.failUnless(self.tv.exists({}) is False)
+
+        # the following will make a tk.call equivalent to
+        # tk.call(treeview, "exists") which should result in an error
+        # in the tcl interpreter since tk requires an item.
+        self.failUnlessRaises(Tkinter.TclError, self.tv.exists, None)
+
+
+    def test_focus(self):
+        # nothing is focused right now
+        self.failUnlessEqual(self.tv.focus(), '')
+
+        item1 = self.tv.insert('', 'end')
+        self.tv.focus(item1)
+        self.failUnlessEqual(self.tv.focus(), item1)
+
+        self.tv.delete(item1)
+        self.failUnlessEqual(self.tv.focus(), '')
+
+        # try focusing inexistant item
+        self.failUnlessRaises(Tkinter.TclError, self.tv.focus, 'hi')
+
+
+    def test_heading(self):
+        # check a dict is returned
+        self.failUnless(isinstance(self.tv.heading('#0'), dict))
+
+        # check a value is returned
+        self.tv.heading('#0', text='hi')
+        self.failUnlessEqual(self.tv.heading('#0', text=None), 'hi')
+
+        # invalid option
+        self.failUnlessRaises(Tkinter.TclError, self.tv.heading, '#0',
+            background=None)
+        # invalid value
+        self.failUnlessRaises(Tkinter.TclError, self.tv.heading, '#0',
+            anchor=1)
+
+    def test_heading_callback(self):
+        def callback():
+            success.append(True)
+
+        def simulate_heading_click(x, y):
+            # Generate proper events (trying to act like an X server).
+            self.tv.event_generate('<Enter>', x=0, y=0)
+            self.tv.event_generate('<Motion>', x=x, y=y)
+            self.tv.event_generate('<ButtonPress-1>', x=x, y=y)
+            self.tv.event_generate('<ButtonRelease-1>', x=x, y=y)
+            self.tv.update_idletasks()
+
+        self.tv.pack()
+        self.tv.wait_visibility()
+        self.tv.heading('#0', command=callback)
+        self.tv.column('#0', width=100)
+        self.tv.update()
+
+        success = [] # no success for now
+        # assuming that the coords (5, 5) fall into heading #0
+        simulate_heading_click(5, 5)
+        if not success:
+            self.fail("The command associated to the treeview heading wasn't "
+                "invoked.")
+
+        # XXX missing tests to check what happens when command is a string
+        # and some others
+
+
+
 def test_main():
     support.run(TreeviewTest)
 

Modified: sandbox/trunk/ttk-gsoc/src/2.x/ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/2.x/ttk.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/2.x/ttk.py	Sat Aug 23 05:36:51 2008
@@ -1193,9 +1193,9 @@
 
 
     def exists(self, item):
-        """Returns 1 if the specified item is present in the three,
-        0 otherwise."""
-        return self.tk.call(self._w, "exists", item)
+        """Returns True if the specified item is present in the three,
+        False otherwise."""
+        return bool(self.tk.call(self._w, "exists", item))
 
 
     def focus(self, item=None):

Modified: sandbox/trunk/ttk-gsoc/src/3.x/test/runtests.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/3.x/test/runtests.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/3.x/test/runtests.py	Sat Aug 23 05:36:51 2008
@@ -20,10 +20,12 @@
 
 def main(args):
     gui_tests = False
-    if 'DISPLAY' in os.environ or (len(args) > 1 and args[1] == "-g"):
+    if 'DISPLAY' in os.environ or (len(args) > 1 and "-g" in args):
         gui_tests = True
 
     run_tests(get_tests(gui_tests))
+    if not gui_tests:
+        print("\n** GUI tests didn't run **")
 
 if __name__ == "__main__":
     main(sys.argv)

Modified: sandbox/trunk/ttk-gsoc/src/3.x/test/test_treeview.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/3.x/test/test_treeview.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/3.x/test/test_treeview.py	Sat Aug 23 05:36:51 2008
@@ -112,6 +112,11 @@
         item_id = self.tv.insert('', 'end')
         item2 = self.tv.insert(item_id, 'end')
 
+        # calling detach without items is valid, although it does nothing
+        prev = self.tv.get_children()
+        self.tv.detach() # this should do nothing
+        self.failUnlessEqual(prev, self.tv.get_children())
+
         self.failUnlessEqual(self.tv.get_children(), (item_id, ))
         self.failUnlessEqual(self.tv.get_children(item_id), (item2, ))
 
@@ -145,6 +150,77 @@
         self.failUnlessEqual(self.tv.get_children(item_id), ())
 
 
+    def test_exists(self):
+        self.failUnless(self.tv.exists('something') is False)
+        self.failUnless(self.tv.exists('') is True)
+        self.failUnless(self.tv.exists({}) is False)
+
+        # the following will make a tk.call equivalent to
+        # tk.call(treeview, "exists") which should result in an error
+        # in the tcl interpreter since tk requires an item.
+        self.failUnlessRaises(tkinter.TclError, self.tv.exists, None)
+
+
+    def test_focus(self):
+        # nothing is focused right now
+        self.failUnlessEqual(self.tv.focus(), '')
+
+        item1 = self.tv.insert('', 'end')
+        self.tv.focus(item1)
+        self.failUnlessEqual(self.tv.focus(), item1)
+
+        self.tv.delete(item1)
+        self.failUnlessEqual(self.tv.focus(), '')
+
+        # try focusing inexistant item
+        self.failUnlessRaises(tkinter.TclError, self.tv.focus, 'hi')
+
+
+    def test_heading(self):
+        # check a dict is returned
+        self.failUnless(isinstance(self.tv.heading('#0'), dict))
+
+        # check a value is returned
+        self.tv.heading('#0', text='hi')
+        self.failUnlessEqual(self.tv.heading('#0', text=None), 'hi')
+
+        # invalid option
+        self.failUnlessRaises(tkinter.TclError, self.tv.heading, '#0',
+            background=None)
+        # invalid value
+        self.failUnlessRaises(tkinter.TclError, self.tv.heading, '#0',
+            anchor=1)
+
+    def test_heading_callback(self):
+        def callback():
+            success.append(True)
+
+        def simulate_heading_click(x, y):
+            # Generate proper events (trying to act like an X server).
+            self.tv.event_generate('<Enter>', x=0, y=0)
+            self.tv.event_generate('<Motion>', x=x, y=y)
+            self.tv.event_generate('<ButtonPress-1>', x=x, y=y)
+            self.tv.event_generate('<ButtonRelease-1>', x=x, y=y)
+            self.tv.update_idletasks()
+
+        self.tv.pack()
+        self.tv.wait_visibility()
+        self.tv.heading('#0', command=callback)
+        self.tv.column('#0', width=100)
+        self.tv.update()
+
+        success = [] # no success for now
+        # assuming that the coords (5, 5) fall into heading #0
+        simulate_heading_click(5, 5)
+        if not success:
+            self.fail("The command associated to the treeview heading wasn't "
+                "invoked.")
+
+        # XXX missing tests to check what happens when command is a string
+        # and some others
+
+
+
 def test_main():
     support.run(TreeviewTest)
 

Modified: sandbox/trunk/ttk-gsoc/src/3.x/ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/3.x/ttk.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/3.x/ttk.py	Sat Aug 23 05:36:51 2008
@@ -1193,9 +1193,9 @@
 
 
     def exists(self, item):
-        """Returns 1 if the specified item is present in the three,
-        0 otherwise."""
-        return self.tk.call(self._w, "exists", item)
+        """Returns True if the specified item is present in the three,
+        False otherwise."""
+        return bool(self.tk.call(self._w, "exists", item))
 
 
     def focus(self, item=None):


More information about the Python-checkins mailing list