summaryrefslogtreecommitdiff
path: root/tests/test_gicon.py
diff options
context:
space:
mode:
authorJinkun Jang <jinkun.jang@samsung.com>2013-03-13 02:21:24 +0900
committerJinkun Jang <jinkun.jang@samsung.com>2013-03-13 02:21:24 +0900
commitc6b9e84f2f7f8c85939a8e5ff5d8a5aa067cecf3 (patch)
tree1436172370a45714687122f914354ad167a2f528 /tests/test_gicon.py
parentf7d643cbb2184346b6f8d26091eb7eb38c6bbfe1 (diff)
downloadpygobject2-c6b9e84f2f7f8c85939a8e5ff5d8a5aa067cecf3.tar.gz
pygobject2-c6b9e84f2f7f8c85939a8e5ff5d8a5aa067cecf3.tar.bz2
pygobject2-c6b9e84f2f7f8c85939a8e5ff5d8a5aa067cecf3.zip
Diffstat (limited to 'tests/test_gicon.py')
-rw-r--r--tests/test_gicon.py111
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/test_gicon.py b/tests/test_gicon.py
new file mode 100644
index 0000000..5ce7ece
--- /dev/null
+++ b/tests/test_gicon.py
@@ -0,0 +1,111 @@
+# -*- Mode: Python -*-
+
+import os
+import unittest
+
+from common import gio, glib
+
+
+class TestIcon(unittest.TestCase):
+ def test_eq(self):
+ self.assertEquals(gio.FileIcon(gio.File('foo.png')),
+ gio.FileIcon(gio.File('foo.png')))
+ self.assertEquals(gio.ThemedIcon('foo'),
+ gio.ThemedIcon('foo'))
+
+ self.assertNotEqual(gio.FileIcon(gio.File('foo.png')),
+ gio.FileIcon(gio.File('bar.png')))
+ self.assertNotEquals(gio.ThemedIcon('foo'),
+ gio.ThemedIcon('bar'))
+ self.assertNotEquals(gio.FileIcon(gio.File('foo.png')),
+ gio.ThemedIcon('foo'))
+
+ def test_hash(self):
+ self.assertEquals(hash(gio.FileIcon(gio.File('foo.png'))),
+ hash(gio.FileIcon(gio.File('foo.png'))))
+ self.assertEquals(hash(gio.ThemedIcon('foo')),
+ hash(gio.ThemedIcon('foo')))
+
+class TestLoadableIcon(unittest.TestCase):
+ def setUp(self):
+ self.file = open('temp.svg', 'w')
+ self.svg = ('<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
+ '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" '
+ '"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">'
+ '<svg width="32" height="32"/>')
+ self.file.write(self.svg)
+ self.file.close()
+ self.icon = gio.FileIcon(gio.File('temp.svg'))
+
+ def tearDown(self):
+ if os.path.exists('temp.svg'):
+ os.unlink('temp.svg')
+
+ def test_load(self):
+ stream, type = self.icon.load()
+ try:
+ self.assert_(isinstance(stream, gio.InputStream))
+ self.assertEquals(self.svg, stream.read())
+ finally:
+ stream.close()
+
+ def test_load_async(self):
+ def callback(icon, result):
+ try:
+ stream, type = icon.load_finish(result)
+ self.assert_(isinstance(stream, gio.InputStream))
+ self.assertEquals(self.svg, stream.read())
+ finally:
+ loop.quit()
+ stream.close()
+
+ self.icon.load_async(callback)
+
+ loop = glib.MainLoop()
+ loop.run()
+
+class TestFileIcon(unittest.TestCase):
+ def test_constructor(self):
+ file = gio.File('foo.png')
+ self.assert_(file is gio.FileIcon(file).get_file())
+
+class TestThemedIcon(unittest.TestCase):
+ def setUp(self):
+ self.icon = gio.ThemedIcon("open")
+
+ def test_constructor(self):
+ have_use_default_fallbacks = ('use_default_fallbacks'
+ in gio.ThemedIcon.props.__members__)
+ icon = gio.ThemedIcon('foo')
+ self.assertEquals(['foo'], icon.props.names)
+ self.assert_(not have_use_default_fallbacks
+ or not icon.props.use_default_fallbacks)
+
+ icon = gio.ThemedIcon(['foo', 'bar', 'baz'])
+ self.assertEquals(['foo', 'bar', 'baz'], icon.props.names)
+ self.assert_(not have_use_default_fallbacks
+ or not icon.props.use_default_fallbacks)
+
+ icon = gio.ThemedIcon('xxx-yyy-zzz', True)
+ self.assertEquals(['xxx-yyy-zzz', 'xxx-yyy', 'xxx'], icon.props.names)
+ self.assert_(not have_use_default_fallbacks
+ or icon.props.use_default_fallbacks)
+
+ def test_constructor_illegals(self):
+ self.assertRaises(TypeError, lambda: gio.ThemedIcon(42))
+ self.assertRaises(TypeError, lambda: gio.ThemedIcon(['foo', 42, 'bar']))
+
+ def test_get_names(self):
+ self.assertEquals(self.icon.get_names(), ['open'])
+
+ def test_append_name(self):
+ self.assertEquals(self.icon.get_names(), ['open'])
+ self.icon.append_name('close')
+ self.assertEquals(self.icon.get_names(), ['open', 'close'])
+
+class TestEmblemedIcon(unittest.TestCase):
+ def test_emblemed_icon(self):
+ icon = gio.FileIcon(gio.File('foo.png'))
+ emblem = gio.Emblem(icon)
+ emblemed = gio.EmblemedIcon(icon, emblem)
+ self.assertEquals(emblemed.get_emblems()[0], emblem)