6
Tests recent_notifications.Icon.
14
# Insert the recent_notifications module into the search path
15
app_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
16
rn_path = os.path.join(app_path, "recent_notifications")
17
sys.path.insert(0, rn_path)
19
from recent_notifications import Icon
21
class TestIcon(unittest.TestCase):
22
"""Tests recent_notifications.Icon."""
24
self.icon_path = os.path.join(app_path, "icons")
26
# Append the icon path to the theme search path so we can test load_icon
27
# with the custom icons even if they aren't installed.
28
theme = gtk.icon_theme_get_default()
29
theme.append_search_path(self.icon_path)
31
def test_load_icon(self):
34
icon = Icon.load_icon("recent-notifications", size)
35
self.assertNotEqual(icon, None)
36
self.assertEqual(icon.get_width(), size)
37
self.assertEqual(icon.get_height(), size)
39
icon_cached = Icon.load_icon("recent-notifications", size)
40
self.assertNotEqual(icon_cached, None)
41
self.assertEqual(icon_cached.get_width(), size)
42
self.assertEqual(icon_cached.get_height(), size)
44
self.assertTrue(icon is icon_cached)
46
def test_load_icon_from_file(self):
48
icon_name = os.path.join(self.icon_path, "recent-notifications.svg")
50
icon = Icon.load_icon_from_file(icon_name, size)
51
self.assertNotEqual(icon, None)
52
self.assertEqual(icon.get_width(), size)
53
self.assertEqual(icon.get_height(), size)
55
icon_cached = Icon.load_icon_from_file(icon_name, size)
56
self.assertNotEqual(icon_cached, None)
57
self.assertEqual(icon_cached.get_width(), size)
58
self.assertEqual(icon_cached.get_height(), size)
60
self.assertTrue(icon is icon_cached)
63
def test_clear_icon_cache(self):
65
icon_name = os.path.join(self.icon_path, "recent-notifications.svg")
67
icon_1 = Icon.load_icon("recent-notifications", size)
68
icon_f1 = Icon.load_icon_from_file(icon_name, size)
70
Icon.clear_icon_cache()
72
icon_2 = Icon.load_icon("recent-notifications", size)
73
icon_f2 = Icon.load_icon_from_file(icon_name, size)
75
self.assertFalse(icon_1 is icon_2)
76
self.assertFalse(icon_f1 is icon_f2)
78
if __name__ == '__main__':