561
|
1 import os.path
|
|
2 from unittest import TestCase
|
|
3
|
562
|
4 from pyntnclick.resources import Resources, ResourceNotFound
|
561
|
5
|
|
6
|
|
7 TEST_PATH = os.path.dirname(__file__)
|
|
8 DATA_PATH = os.path.join(os.path.dirname(TEST_PATH), 'data')
|
|
9
|
|
10 test_path = lambda p: os.path.join(TEST_PATH, p)
|
|
11 data_path = lambda p: os.path.join(DATA_PATH, p)
|
|
12
|
|
13
|
|
14 class ResourcesTestCase(TestCase):
|
|
15 def test_get_paths_no_lang(self):
|
|
16 res = Resources('pyntnclick.tests')
|
|
17 self.assertEqual([test_path('thing'), data_path('thing')],
|
|
18 res.get_paths('thing'))
|
|
19
|
|
20 def test_get_paths_lang(self):
|
|
21 res = Resources('pyntnclick.tests', 'en')
|
|
22 self.assertEqual([test_path('en/thing'), test_path('thing'),
|
|
23 data_path('en/thing'), data_path('thing')],
|
|
24 res.get_paths('thing'))
|
562
|
25
|
|
26 def test_get_resource_path_missing(self):
|
|
27 res = Resources('pyntnclick.tests')
|
|
28 try:
|
|
29 res.get_resource_path('should_not_exist')
|
|
30 self.fail('Expected ResourceNotFound error.')
|
|
31 except ResourceNotFound, e:
|
|
32 self.assertEqual('should_not_exist', e.args[0])
|
|
33
|
|
34 def test_get_resource_path_in_test(self):
|
|
35 res = Resources('pyntnclick.tests')
|
|
36 self.assertEqual(test_path('test_resources.py'),
|
|
37 res.get_resource_path('test_resources.py'))
|
|
38
|
|
39 def test_get_resource_path_in_data(self):
|
|
40 res = Resources('pyntnclick.tests')
|
|
41 self.assertEqual(data_path('images/pyntnclick/hand.png'),
|
|
42 res.get_resource_path('images/pyntnclick/hand.png'))
|