~jconti/recent-notifications/trunk

« back to all changes in this revision

Viewing changes to tests/test_icon.py

  • Committer: Jason Conti
  • Date: 2010-03-06 01:32:31 UTC
  • Revision ID: jason.conti@gmail.com-20100306013231-lmkfwkvrjj37xuoz
Adding a quick test framework to help avoid typo errors like the ones fixed by the previous commit. Need to write more tests. Currently testing Icon.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
test_icon.py
 
3
by Jason Conti
 
4
March 5, 2010
 
5
 
 
6
Tests recent_notifications.Icon.
 
7
"""
 
8
 
 
9
import gtk
 
10
import os.path
 
11
import unittest
 
12
import sys
 
13
 
 
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)
 
18
 
 
19
from recent_notifications import Icon
 
20
 
 
21
class TestIcon(unittest.TestCase):
 
22
  """Tests recent_notifications.Icon."""
 
23
  def setUp(self):
 
24
    self.icon_path = os.path.join(app_path, "icons")
 
25
 
 
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)
 
30
 
 
31
  def test_load_icon(self):
 
32
    size = 48
 
33
    
 
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)
 
38
 
 
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)
 
43
 
 
44
    self.assertTrue(icon is icon_cached)
 
45
 
 
46
  def test_load_icon_from_file(self):
 
47
    size = 48
 
48
    icon_name = os.path.join(self.icon_path, "recent-notifications.svg")
 
49
 
 
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)
 
54
 
 
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)
 
59
 
 
60
    self.assertTrue(icon is icon_cached)
 
61
 
 
62
 
 
63
  def test_clear_icon_cache(self):
 
64
    size = 48
 
65
    icon_name = os.path.join(self.icon_path, "recent-notifications.svg")
 
66
 
 
67
    icon_1 = Icon.load_icon("recent-notifications", size)
 
68
    icon_f1 = Icon.load_icon_from_file(icon_name, size)
 
69
 
 
70
    Icon.clear_icon_cache()
 
71
 
 
72
    icon_2 = Icon.load_icon("recent-notifications", size)
 
73
    icon_f2 = Icon.load_icon_from_file(icon_name, size)
 
74
 
 
75
    self.assertFalse(icon_1 is icon_2)
 
76
    self.assertFalse(icon_f1 is icon_f2)
 
77
 
 
78
if __name__ == '__main__':
 
79
  unittest.main()