changeset 573:85f1ab8af698 pyntnclick

Test refactor.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 11 Feb 2012 15:54:32 +0200
parents e393954e3749
children 4e14721e74a8
files pyntnclick/tests/test_resources.py
diffstat 1 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/pyntnclick/tests/test_resources.py	Sat Feb 11 15:53:14 2012 +0200
+++ b/pyntnclick/tests/test_resources.py	Sat Feb 11 15:54:32 2012 +0200
@@ -14,37 +14,40 @@
 
 
 class ResourcesTestCase(TestCase):
+    def setUp(self):
+        self.res = self.get_resource_loader()
+
+    def get_resource_loader(self, *args, **kw):
+        res = Resources('pyntnclick.tests', *args, **kw)
+        res.CONVERT_ALPHA = False  # Because we have no display.
+        return res
+
     def test_get_paths_no_lang(self):
-        res = Resources('pyntnclick.tests')
         self.assertEqual([test_path('thing'), data_path('thing')],
-                         res.get_paths('thing'))
+                         self.res.get_paths('thing'))
 
     def test_get_paths_lang(self):
-        res = Resources('pyntnclick.tests', 'en')
+        res = self.get_resource_loader('en')
         self.assertEqual([test_path('en/thing'), test_path('thing'),
                           data_path('en/thing'), data_path('thing')],
                          res.get_paths('thing'))
 
     def test_get_resource_path_missing(self):
-        res = Resources('pyntnclick.tests')
         try:
-            res.get_resource_path('should_not_exist')
+            self.res.get_resource_path('should_not_exist')
             self.fail('Expected ResourceNotFound error.')
         except ResourceNotFound, e:
             self.assertEqual('should_not_exist', e.args[0])
 
     def test_get_resource_path_in_test(self):
-        res = Resources('pyntnclick.tests')
         self.assertEqual(test_path('test_resources.py'),
-                         res.get_resource_path('test_resources.py'))
+                         self.res.get_resource_path('test_resources.py'))
 
     def test_get_resource_path_in_data(self):
-        res = Resources('pyntnclick.tests')
-        self.assertEqual(data_path('images/pyntnclick/hand.png'),
-                         res.get_resource_path('images/pyntnclick/hand.png'))
+        self.assertEqual(
+            data_path('images/pyntnclick/hand.png'),
+            self.res.get_resource_path('images/pyntnclick/hand.png'))
 
     def test_load_image(self):
-        res = Resources('pyntnclick.tests')
-        res.CONVERT_ALPHA = False
-        image = res.load_image('pyntnclick/hand.png')
+        image = self.res.load_image('pyntnclick/hand.png')
         self.assertTrue(isinstance(image, Surface))