diff options
author | Martin Pitt <martinpitt@gnome.org> | 2013-01-23 14:56:02 +0100 |
---|---|---|
committer | Martin Pitt <martinpitt@gnome.org> | 2013-01-23 14:56:02 +0100 |
commit | e65c124893ceaa9c97eb4c8c743fbeb756b9a6e6 (patch) | |
tree | 95e8804cb171c796047f6bc8726d5545d33b5d37 /tests/test_gobject.py | |
parent | a52245381fab3c2aebd330cc9c5e717a93c9607d (diff) | |
download | pygobject-e65c124893ceaa9c97eb4c8c743fbeb756b9a6e6.tar.gz |
Accept ±inf and NaN as float and double values
Also fix the broken error message when a float value is out of range.
PyErr_Format() does not support float macros.
https://bugzilla.gnome.org/show_bug.cgi?id=692381
Diffstat (limited to 'tests/test_gobject.py')
-rw-r--r-- | tests/test_gobject.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/test_gobject.py b/tests/test_gobject.py index a05d7589..ec4cb44b 100644 --- a/tests/test_gobject.py +++ b/tests/test_gobject.py @@ -624,10 +624,24 @@ class TestGValue(unittest.TestCase): # python float is G_TYPE_DOUBLE value = GObject.Value(float, 23.4) self.assertEqual(value.g_type, GObject.TYPE_DOUBLE) + value.set_value(1e50) + self.assertAlmostEqual(value.get_value(), 1e50) value = GObject.Value(GObject.TYPE_FLOAT, 23.4) self.assertEqual(value.g_type, GObject.TYPE_FLOAT) self.assertRaises(TypeError, value.set_value, 'string') + self.assertRaises(ValueError, value.set_value, 1e50) + + def test_float_inf_nan(self): + nan = float('nan') + for type_ in [GObject.TYPE_FLOAT, GObject.TYPE_DOUBLE]: + for x in [float('inf'), float('-inf'), nan]: + value = GObject.Value(type_, x) + # assertEqual() is False for (nan, nan) + if x is nan: + self.assertEqual(str(value.get_value()), 'nan') + else: + self.assertEqual(value.get_value(), x) def test_enum(self): value = GObject.Value(GLib.FileError, GLib.FileError.FAILED) |