def test_reister_path_duplicates(self): """Ensure search path only occur once if registered multipel times""" with settings_context(self.settings): resources.register_dir(self.absolute_path) resources.register_dir(self.absolute_path) resources.register_dir(self.absolute_path) self.assertEqual(len(settings.DATA_DIRS), 1)
def test_non_dir(self): """Register nonexistent path""" with settings_context(self.settings): with self.assertRaises(ImproperlyConfigured): resources.register_dir(self.nonexist_path)
def test_register_file(self): """Attempt to register a file as a search path""" with settings_context(self.settings): with self.assertRaises(ImproperlyConfigured): resources.register_dir(self.file_path)
def test_register_data_dir(self): """Register a data dir""" with settings_context(self.settings): resources.register_data_dir(self.absolute_path) self.assertEqual(len(settings.DATA_DIRS), 1)
def test_relative_path(self): """Raise error if relative path is passed""" with settings_context(self.settings): with self.assertRaises(ImproperlyConfigured): resources.register_dir(self.relative_path)
def test_register_texture_dir(self): """Register a texture dir""" with settings_context(self.settings): resources.register_texture_dir(self.absolute_path) self.assertEqual(len(settings.TEXTURE_DIRS), 1)
def test_register_scene_dir(self): """Register a scene dir""" with settings_context(self.settings): resources.register_scene_dir(self.absolute_path) self.assertEqual(len(settings.SCENE_DIRS), 1)
def test_no_search_dirs(self): """When no search dirs the finder should return None""" with settings_context({'DATA_DIRS': []}): finder = data.FilesystemFinder() result = finder.find(Path('data/data.json')) self.assertIsNone(result)
def test_register_program_dir(self): """Register a program dir""" with settings_context(self.settings): resources.register_program_dir(self.absolute_path) self.assertEqual(len(settings.PROGRAM_DIRS), 1)
def test_relative_path_raises_exception(self): with settings_context({'DATA_DIRS': ['relative_location']}): with self.assertRaises(ImproperlyConfigured): data.FilesystemFinder().find(Path('something'))
def test_absolute_path(self): """Ensure absolute paths are ignored""" with settings_context(self.finder_settings): finder = data.FilesystemFinder() result = finder.find(Path(self.root, Path('data/data.json'))) self.assertIsNone(result)
def test_scene_finder(self): """Find a scene""" with settings_context(self.finder_settings): result = scene.FilesystemFinder().find(Path('model.obj')) self.assertIsInstance(result, Path) self.assertTrue(result.name, 'model.obj')
def test_texture_finder(self): """Find a texture""" with settings_context(self.finder_settings): result = texture.FilesystemFinder().find(Path('image.png')) self.assertIsInstance(result, Path) self.assertTrue(result.name, 'image.png')
def test_program_finder(self): """Find a glsl file""" with settings_context(self.finder_settings): result = program.FilesystemFinder().find(Path('test.glsl')) self.assertIsInstance(result, Path) self.assertTrue(result.name, 'test.glsl')
def test_data_finder(self): """Find a data file""" with settings_context(self.finder_settings): result = data.FilesystemFinder().find(Path('data.json')) self.assertIsInstance(result, Path) self.assertTrue(result.name, 'data.json')
def test_with_screenshot_path(self): """Create screenshot with SCREENSHOT_PATH defined in settings""" with settings_context( {'SCREENSHOT_PATH': (Path.cwd() / 'screenshots')}): self.test_fbo()