diff options
author | Paul Pogonyshev <pogonyshev@gmx.net> | 2009-05-16 00:12:46 +0300 |
---|---|---|
committer | Paul Pogonyshev <pogonyshev@gmx.net> | 2009-05-16 00:12:46 +0300 |
commit | ee2dfca5879125346bc309f4f13c553e12fb7460 (patch) | |
tree | 88e1e36dc66e54568e04a41384e3487f338571bd /tests | |
parent | 15b7265a00d405d6115f45ba0b1f26019ef1a52b (diff) | |
download | pygtk-ee2dfca5879125346bc309f4f13c553e12fb7460.tar.gz |
Add HSV support to gtk.gdk.Color objects
Add read-only float attributes for hue, saturation and value of a
color. Add a function to create a color objects out of HSV
components. Add unit tests and document new features. Part of bug
546019.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_color.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/test_color.py b/tests/test_color.py index d8484ae3..82f35c79 100644 --- a/tests/test_color.py +++ b/tests/test_color.py @@ -44,7 +44,10 @@ class Tests(unittest.TestCase): self.assertRaises(TypeError, lambda: gtk.gdk.Color([])) - def test_float_attribute(self): + def test_color_from_hsv(self): + self.assertEqual(gtk.gdk.Color('red'), gtk.gdk.color_from_hsv(0.0, 1.0, 1.0)) + + def test_float_attributes(self): c = gtk.gdk.Color(0, 10000, 65535) self.assertAlmostEqual(c.red_float, 0.0) self.assertAlmostEqual(c.green_float, 10000.0 / 65535.0) @@ -57,6 +60,22 @@ class Tests(unittest.TestCase): c.green = 12345 self.assertAlmostEqual(c.green_float, 12345.0 / 65535.0) + def test_hue(self): + self.assertAlmostEqual(gtk.gdk.Color('red').hue, 0 * 1.0 / 6) + self.assertAlmostEqual(gtk.gdk.Color('yellow').hue, 1 * 1.0 / 6) + self.assertAlmostEqual(gtk.gdk.Color('green').hue, 2 * 1.0 / 6) + self.assertAlmostEqual(gtk.gdk.Color('cyan').hue, 3 * 1.0 / 6) + self.assertAlmostEqual(gtk.gdk.Color('blue').hue, 4 * 1.0 / 6) + self.assertAlmostEqual(gtk.gdk.Color('magenta').hue, 5 * 1.0 / 6) + + def test_saturation(self): + self.assertAlmostEqual(gtk.gdk.Color('red').saturation, 1.0) + self.assertAlmostEqual(gtk.gdk.Color('gray').saturation, 0.0) + + def test_value(self): + self.assertAlmostEqual(gtk.gdk.Color('black').value, 0.0) + self.assertAlmostEqual(gtk.gdk.Color('white').value, 1.0) + 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)) |