From a29cb1a1da1da419a220229d0161f476f420131e Mon Sep 17 00:00:00 2001 From: Paul Pogonyshev Date: Sat, 2 Aug 2008 16:08:41 +0000 Subject: =?UTF-8?q?Bug=20527212=20=E2=80=93=20types=20with=20well-defined?= =?UTF-8?q?=20equality=20semantics=20are=20not=20properly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-08-02 Paul Pogonyshev Bug 527212 – types with well-defined equality semantics are not properly comparable * gtk/gdk.override (_wrap_pygdk_region_tp_richcompare): New function. * gtk/gdkcolor.override (_wrap_gdk_color_tp_richcompare): New function. * gtk/gdkrectangle.override (_wrap_gdk_rectangle_tp_richcompare): New function. * tests/test_conversion.py (testColorCreation): Move to thematic test file. * tests/Makefile.am: * tests/test_color.py: * tests/test_rectangle.py: Two new test files. 2008-08-02 Paul Pogonyshev Bug 527212 – types with well-defined equality semantics are not properly comparable * pygtk-gdkcolor.xml: Document new constructor option. Document proper comparison as of PyGTK 2.14. * pygtk-gdkregion.xml: Document proper comparison as of PyGTK 2.14. * pygtk-gdkrectangle.xml: Document proper comparison as of PyGTK 2.14. svn path=/trunk/; revision=3014 --- tests/Makefile.am | 40 +++++++++++++++++--------------- tests/test_color.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/test_conversion.py | 29 ----------------------- tests/test_rectangle.py | 28 ++++++++++++++++++++++ 4 files changed, 109 insertions(+), 48 deletions(-) create mode 100644 tests/test_color.py create mode 100644 tests/test_rectangle.py (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index e5756f4c..3ca928b9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,24 +1,26 @@ EXTRA_DIST = $(tests) common.py runtests.py testmodule.py leak.glade -tests = \ - test_actiongroup.py \ - test_api.py \ - test_bin.py \ - test_button.py \ - test_container.py - test_conversion.py \ - test_dialog.py \ - test_enum.py \ - test_gdk.py \ - test_glade.py \ - test_liststore.py - test_pango.py \ - test_plug.py \ - test_radiobutton.py \ - test_style.py \ - test_textview.py \ - test_treeview.py \ - test_filechooserdialog.py +tests = \ + test_actiongroup.py \ + test_api.py \ + test_bin.py \ + test_button.py \ + test_color.py \ + test_container.py \ + test_conversion.py \ + test_dialog.py \ + test_enum.py \ + test_filechooserdialog.py \ + test_gdk.py \ + test_glade.py \ + test_liststore.py \ + test_pango.py \ + test_plug.py \ + test_radiobutton.py \ + test_rectangle.py \ + test_style.py \ + test_textview.py \ + test_treeview.py GTK_PY_FILES = __init__.py _lazyutils.py compat.py deprecation.py keysyms.py diff --git a/tests/test_color.py b/tests/test_color.py new file mode 100644 index 00000000..616c716e --- /dev/null +++ b/tests/test_color.py @@ -0,0 +1,60 @@ +# -*- Mode: Python -*- + +import unittest + +from common import gtk + + +class Tests(unittest.TestCase): + + def test_constructor(self): + """ Test GdkColor creation """ + + c = gtk.gdk.Color(1, 2, 3) + self.assertEqual(c.red, 1) + self.assertEqual(c.green, 2) + self.assertEqual(c.blue, 3) + + c = gtk.gdk.Color(pixel=0xffff) + self.assertEqual(c.pixel, 0xffff) + + c = gtk.gdk.Color(pixel=0xffffL) + self.assertEqual(c.pixel, 0xffff) + + c = gtk.gdk.Color(pixel=0xffffffffL) + self.assertEqual(c.pixel, 0xffffffffL) + + c = gtk.gdk.Color('red') + self.assertEqual(c.red, 65535) + self.assertEqual(c.green, 0) + self.assertEqual(c.blue, 0) + + c = gtk.gdk.Color('#ff0000') + self.assertEqual(c.red, 65535) + self.assertEqual(c.green, 0) + self.assertEqual(c.blue, 0) + + self.assertRaises(TypeError, lambda: gtk.gdk.Color([])) + + def test_equal(self): + self.assertEqual(gtk.gdk.Color(0, 0, 0), gtk.gdk.Color(0, 0, 0)) + self.assertEqual(gtk.gdk.Color(100, 200, 300), gtk.gdk.Color(100, 200, 300)) + self.assertEqual(gtk.gdk.Color('#abc'), gtk.gdk.Color('#aabbcc')) + self.assertEqual(gtk.gdk.Color('#100020003000'), gtk.gdk.Color(0x1000, 0x2000, 0x3000)) + + def test_not_equal(self): + self.assertNotEqual(gtk.gdk.Color('red'), gtk.gdk.Color('blue')) + self.assertNotEqual(gtk.gdk.Color(1, 0, 0), gtk.gdk.Color(0, 0, 0)) + self.assertNotEqual(gtk.gdk.Color(0, 1, 0), gtk.gdk.Color(0, 0, 0)) + self.assertNotEqual(gtk.gdk.Color(0, 0, 1), gtk.gdk.Color(0, 0, 0)) + + def test_non_hashable(self): + self.assertRaises(TypeError, lambda: hash(gtk.gdk.Color())) + + def dict_key(): + {} [gtk.gdk.Color()] = 'must raise' + self.assertRaises(TypeError, dict_key) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_conversion.py b/tests/test_conversion.py index a63d7914..2642d11e 100644 --- a/tests/test_conversion.py +++ b/tests/test_conversion.py @@ -52,35 +52,6 @@ class Tests(unittest.TestCase): self.assertEqual(entry.get_property('invisible_char'), valid_value, valid_value) - def testColorCreation(self): - """ Test GdkColor creation """ - - c = gtk.gdk.Color(1, 2, 3) - self.assertEqual(c.red, 1) - self.assertEqual(c.green, 2) - self.assertEqual(c.blue, 3) - - c = gtk.gdk.Color(pixel=0xffff) - self.assertEqual(c.pixel, 0xffff) - - c = gtk.gdk.Color(pixel=0xffffL) - self.assertEqual(c.pixel, 0xffff) - - c = gtk.gdk.Color(pixel=0xffffffffL) - self.assertEqual(c.pixel, 0xffffffffL) - - c = gtk.gdk.Color('red') - self.assertEqual(c.red, 65535) - self.assertEqual(c.green, 0) - self.assertEqual(c.blue, 0) - - c = gtk.gdk.Color('#ff0000') - self.assertEqual(c.red, 65535) - self.assertEqual(c.green, 0) - self.assertEqual(c.blue, 0) - - self.assertRaises(TypeError, lambda: gtk.gdk.Color([])) - def testUIntArg(self): child = gtk.DrawingArea() table = gtk.Table(2, 2, False) diff --git a/tests/test_rectangle.py b/tests/test_rectangle.py new file mode 100644 index 00000000..ab5b0646 --- /dev/null +++ b/tests/test_rectangle.py @@ -0,0 +1,28 @@ +# -*- Mode: Python -*- + +import unittest + +from common import gtk + + +class Tests(unittest.TestCase): + + def test_equal(self): + self.assertEqual(gtk.gdk.Rectangle(0, 0, 1, 1), gtk.gdk.Rectangle(0, 0, 1, 1)) + + def test_not_equal(self): + self.assertNotEqual(gtk.gdk.Rectangle(1, 0, 10, 10), gtk.gdk.Rectangle(0, 0, 10, 10)) + self.assertNotEqual(gtk.gdk.Rectangle(0, 1, 10, 10), gtk.gdk.Rectangle(0, 0, 10, 10)) + self.assertNotEqual(gtk.gdk.Rectangle(0, 0, 11, 10), gtk.gdk.Rectangle(0, 0, 10, 10)) + self.assertNotEqual(gtk.gdk.Rectangle(0, 0, 10, 11), gtk.gdk.Rectangle(0, 0, 10, 10)) + + def test_non_hashable(self): + self.assertRaises(TypeError, lambda: hash(gtk.gdk.Rectangle())) + + def dict_key(): + {} [gtk.gdk.Rectangle()] = 'must raise' + self.assertRaises(TypeError, dict_key) + + +if __name__ == '__main__': + unittest.main() -- cgit v1.2.1