summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2014-01-07 09:16:54 -0800
committerSimon Feltman <sfeltman@src.gnome.org>2014-01-07 09:30:37 -0800
commit9b02b29016958791dfa9d7ebfc6c2ec44ab5690d (patch)
tree8fe7e0d45bd3a96c13d67b332c1f842b7795401c /tests
parentf6a87935596a3b59c238a5572b288f34691b53d1 (diff)
downloadpygobject-9b02b29016958791dfa9d7ebfc6c2ec44ab5690d.tar.gz
overrides: Fix __repr__ for various Gdk structs
Change __repr__ overrides for Gdk.Color, Gdk.RGBA, and Gdk.Atom to return a string reprentation that is valid Python given an expected environment. See: http://docs.python.org/2/reference/datamodel.html#object.__repr__
Diffstat (limited to 'tests')
-rw-r--r--tests/test_atoms.py7
-rw-r--r--tests/test_overrides_gdk.py9
2 files changed, 14 insertions, 2 deletions
diff --git a/tests/test_atoms.py b/tests/test_atoms.py
index 1561dbd4..18f8d098 100644
--- a/tests/test_atoms.py
+++ b/tests/test_atoms.py
@@ -20,10 +20,13 @@ class TestGdkAtom(unittest.TestCase):
self.assertEqual(str(Gdk.SELECTION_CLIPBOARD), 'CLIPBOARD')
def test_repr(self):
+ # __repr__ should generate a string which is parsable when possible
+ # http://docs.python.org/2/reference/datamodel.html#object.__repr__
atom = Gdk.Atom.intern('my_string', False)
- self.assertEqual(repr(atom), 'Gdk.Atom<my_string>')
+ self.assertEqual(repr(atom), 'Gdk.Atom.intern("my_string", False)')
+ self.assertEqual(eval(repr(atom)), atom)
- self.assertEqual(repr(Gdk.SELECTION_CLIPBOARD), 'Gdk.Atom<CLIPBOARD>')
+ self.assertEqual(repr(Gdk.SELECTION_CLIPBOARD), 'Gdk.Atom.intern("CLIPBOARD", False)')
def test_in_single(self):
a_selection = Gdk.Atom.intern('test_clipboard', False)
diff --git a/tests/test_overrides_gdk.py b/tests/test_overrides_gdk.py
index 648597ea..90e2fdef 100644
--- a/tests/test_overrides_gdk.py
+++ b/tests/test_overrides_gdk.py
@@ -148,3 +148,12 @@ class TestGdk(unittest.TestCase):
self.assertEqual(c.green, 65535)
self.assertEqual(c.blue, 32896)
self.assertEqual(Gdk.color_parse('bogus'), None)
+
+ def test_color_representations(self):
+ # __repr__ should generate a string which is parsable when possible
+ # http://docs.python.org/2/reference/datamodel.html#object.__repr__
+ color = Gdk.Color(red=65535, green=32896, blue=1)
+ self.assertEqual(eval(repr(color)), color)
+
+ rgba = Gdk.RGBA(red=1.0, green=0.8, blue=0.6, alpha=0.4)
+ self.assertEqual(eval(repr(rgba)), rgba)