comparison pyntnclick/tests/test_resources.py @ 573:85f1ab8af698 pyntnclick

Test refactor.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 11 Feb 2012 15:54:32 +0200
parents 20e296d4a3a5
children 27809609eeca
comparison
equal deleted inserted replaced
572:e393954e3749 573:85f1ab8af698
12 test_path = lambda p: os.path.join(TEST_PATH, p) 12 test_path = lambda p: os.path.join(TEST_PATH, p)
13 data_path = lambda p: os.path.join(DATA_PATH, p) 13 data_path = lambda p: os.path.join(DATA_PATH, p)
14 14
15 15
16 class ResourcesTestCase(TestCase): 16 class ResourcesTestCase(TestCase):
17 def setUp(self):
18 self.res = self.get_resource_loader()
19
20 def get_resource_loader(self, *args, **kw):
21 res = Resources('pyntnclick.tests', *args, **kw)
22 res.CONVERT_ALPHA = False # Because we have no display.
23 return res
24
17 def test_get_paths_no_lang(self): 25 def test_get_paths_no_lang(self):
18 res = Resources('pyntnclick.tests')
19 self.assertEqual([test_path('thing'), data_path('thing')], 26 self.assertEqual([test_path('thing'), data_path('thing')],
20 res.get_paths('thing')) 27 self.res.get_paths('thing'))
21 28
22 def test_get_paths_lang(self): 29 def test_get_paths_lang(self):
23 res = Resources('pyntnclick.tests', 'en') 30 res = self.get_resource_loader('en')
24 self.assertEqual([test_path('en/thing'), test_path('thing'), 31 self.assertEqual([test_path('en/thing'), test_path('thing'),
25 data_path('en/thing'), data_path('thing')], 32 data_path('en/thing'), data_path('thing')],
26 res.get_paths('thing')) 33 res.get_paths('thing'))
27 34
28 def test_get_resource_path_missing(self): 35 def test_get_resource_path_missing(self):
29 res = Resources('pyntnclick.tests')
30 try: 36 try:
31 res.get_resource_path('should_not_exist') 37 self.res.get_resource_path('should_not_exist')
32 self.fail('Expected ResourceNotFound error.') 38 self.fail('Expected ResourceNotFound error.')
33 except ResourceNotFound, e: 39 except ResourceNotFound, e:
34 self.assertEqual('should_not_exist', e.args[0]) 40 self.assertEqual('should_not_exist', e.args[0])
35 41
36 def test_get_resource_path_in_test(self): 42 def test_get_resource_path_in_test(self):
37 res = Resources('pyntnclick.tests')
38 self.assertEqual(test_path('test_resources.py'), 43 self.assertEqual(test_path('test_resources.py'),
39 res.get_resource_path('test_resources.py')) 44 self.res.get_resource_path('test_resources.py'))
40 45
41 def test_get_resource_path_in_data(self): 46 def test_get_resource_path_in_data(self):
42 res = Resources('pyntnclick.tests') 47 self.assertEqual(
43 self.assertEqual(data_path('images/pyntnclick/hand.png'), 48 data_path('images/pyntnclick/hand.png'),
44 res.get_resource_path('images/pyntnclick/hand.png')) 49 self.res.get_resource_path('images/pyntnclick/hand.png'))
45 50
46 def test_load_image(self): 51 def test_load_image(self):
47 res = Resources('pyntnclick.tests') 52 image = self.res.load_image('pyntnclick/hand.png')
48 res.CONVERT_ALPHA = False
49 image = res.load_image('pyntnclick/hand.png')
50 self.assertTrue(isinstance(image, Surface)) 53 self.assertTrue(isinstance(image, Surface))