1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
"""
test_icon.py
by Jason Conti
March 5, 2010
Tests recent_notifications.Icon.
"""
import gtk
import os.path
import unittest
import sys
# Insert the recent_notifications module into the search path
app_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
rn_path = os.path.join(app_path, "recent_notifications")
sys.path.insert(0, rn_path)
from recent_notifications import Icon
class TestIcon(unittest.TestCase):
"""Tests recent_notifications.Icon."""
def setUp(self):
self.icon_path = os.path.join(app_path, "icons")
# Append the icon path to the theme search path so we can test load_icon
# with the custom icons even if they aren't installed.
theme = gtk.icon_theme_get_default()
theme.append_search_path(self.icon_path)
def test_load_icon(self):
size = 48
icon = Icon.load_icon("recent-notifications", size)
self.assertNotEqual(icon, None)
self.assertEqual(icon.get_width(), size)
self.assertEqual(icon.get_height(), size)
icon_cached = Icon.load_icon("recent-notifications", size)
self.assertNotEqual(icon_cached, None)
self.assertEqual(icon_cached.get_width(), size)
self.assertEqual(icon_cached.get_height(), size)
self.assertTrue(icon is icon_cached)
def test_load_icon_from_file(self):
size = 48
icon_name = os.path.join(self.icon_path, "recent-notifications.svg")
icon = Icon.load_icon_from_file(icon_name, size)
self.assertNotEqual(icon, None)
self.assertEqual(icon.get_width(), size)
self.assertEqual(icon.get_height(), size)
icon_cached = Icon.load_icon_from_file(icon_name, size)
self.assertNotEqual(icon_cached, None)
self.assertEqual(icon_cached.get_width(), size)
self.assertEqual(icon_cached.get_height(), size)
self.assertTrue(icon is icon_cached)
def test_clear_icon_cache(self):
size = 48
icon_name = os.path.join(self.icon_path, "recent-notifications.svg")
icon_1 = Icon.load_icon("recent-notifications", size)
icon_f1 = Icon.load_icon_from_file(icon_name, size)
Icon.clear_icon_cache()
icon_2 = Icon.load_icon("recent-notifications", size)
icon_f2 = Icon.load_icon_from_file(icon_name, size)
self.assertFalse(icon_1 is icon_2)
self.assertFalse(icon_f1 is icon_f2)
if __name__ == '__main__':
unittest.main()
|