Debian Codegraph @

test/test_icon.py

raw
1 #!/usr/bin/env python3
2 from xdg.IconTheme import IconTheme, getIconPath, getIconData
3 import tempfile, shutil, os
4 import unittest
5
6 import resources
7
8 example_dir = os.path.join(os.path.dirname(__file__), 'example')
9 def example_file(filename):
10 return os.path.join(example_dir, filename)
11
12 class IconThemeTest(unittest.TestCase):
13 def test_find_icon_exists(self):
14 print("Finding an icon that probably exists:")
15 print (getIconPath("firefox"))
16
17 def test_find_icon_nonexistant(self):
18 icon = getIconPath("oijeorjewrjkngjhbqefew")
19 assert icon is None, "%r is not None" % icon
20
21 def test_validate_icon_theme(self):
22 theme = IconTheme()
23 theme.parse(example_file("index.theme"))
24 theme.validate()
25
26 class IconDataTest(unittest.TestCase):
27 def test_read_icon_data(self):
28 tmpdir = tempfile.mkdtemp()
29 try:
30 png_file = os.path.join(tmpdir, "test.png")
31 with open(png_file, "wb") as f:
32 f.write(resources.png_data)
33
34 icon_file = os.path.join(tmpdir, "test.icon")
35 with open(icon_file, "w") as f:
36 f.write(resources.icon_data)
37
38 icondata = getIconData(png_file)
39 icondata.validate()
40
41 self.assertEqual(icondata.getDisplayName(), 'Mime text/plain')
42 self.assertEqual(icondata.getAttachPoints(), [(200,200), (800,200), (500,500), (200,800), (800,800)])
43 self.assertEqual(icondata.getEmbeddedTextRectangle(), [100,100,900,900])
44
45 assert "<IconData" in repr(icondata), repr(icondata)
46
47 finally:
48 shutil.rmtree(tmpdir)
49