]> granicus.if.org Git - python/commitdiff
Issue #1730136: Fix comparison between a tk Font object and an object of a
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 24 Jul 2014 14:48:28 +0000 (17:48 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 24 Jul 2014 14:48:28 +0000 (17:48 +0300)
different type.

Lib/lib-tk/test/test_tkinter/test_font.py [new file with mode: 0644]
Lib/lib-tk/tkFont.py
Misc/NEWS

diff --git a/Lib/lib-tk/test/test_tkinter/test_font.py b/Lib/lib-tk/test/test_tkinter/test_font.py
new file mode 100644 (file)
index 0000000..8e20f4d
--- /dev/null
@@ -0,0 +1,35 @@
+import unittest
+import Tkinter
+#from Tkinter
+import tkFont as font
+from test.test_support import requires, run_unittest
+import test_ttk.support as support
+
+requires('gui')
+
+class FontTest(unittest.TestCase):
+
+    def setUp(self):
+        support.root_deiconify()
+
+    def tearDown(self):
+        support.root_withdraw()
+
+    def test_font_eq(self):
+        fontname = "TkDefaultFont"
+        try:
+            f = font.Font(name=fontname, exists=True)
+        except tkinter._tkinter.TclError:
+            f = font.Font(name=fontname, exists=False)
+        font1 = font.nametofont(fontname)
+        font2 = font.nametofont(fontname)
+        self.assertIsNot(font1, font2)
+        self.assertEqual(font1, font2)
+        self.assertNotEqual(font1, font1.copy())
+        self.assertNotEqual(font1, 0)
+        self.assertNotIn(font1, [0])
+
+tests_gui = (FontTest, )
+
+if __name__ == "__main__":
+    run_unittest(*tests_gui)
index 61c2f86abd8d9d31ba99a15dfa9f9e4d4c6738c3..dfdee425f3963ae79a79ab344b2a8b98f21093a9 100644 (file)
@@ -97,7 +97,7 @@ class Font:
         return self.name
 
     def __eq__(self, other):
-        return self.name == other.name and isinstance(other, Font)
+        return isinstance(other, Font) and self.name == other.name
 
     def __getitem__(self, key):
         return self.cget(key)
index a6c1416482f389ac0510ad947fe7213c7764f88b..f1c9ab32980f2b79b59f7e38c643df50db8e7873 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #1730136: Fix the comparison between a tkFont.Font and an object of
+  another kind.
+
 - Issue #19884: readline: Disable the meta modifier key if stdout is not
   a terminal to not write the ANSI sequence "\033[1034h" into stdout. This
   sequence is used on some terminal (ex: TERM=xterm-256color") to enable