def test_findlib(): """ Test finding of libs """ if not sys.platform.startswith('linux'): return # Candidate libs for common lib dirs, paths = core.findlib.generate_candidate_libs(['libpython']) assert paths # Candidate libs for common freeimage fi_dir = os.path.join(core.appdata_dir('imageio'), 'freeimage') dirs, paths = core.findlib.generate_candidate_libs(['libfreeimage'], [fi_dir]) assert fi_dir in dirs assert paths open(os.path.join(fi_dir, 'notalib.test.so'), 'wb') # Loading libs gllib = ctypes.util.find_library('GL') core.load_lib([gllib], []) core.load_lib([], ['libfreeimage'], [fi_dir]) # Fail raises(ValueError, core.load_lib, [], []) # Nothing given raises(ValueError, core.load_lib, ['', None], []) # Nothing given raises(OSError, core.load_lib, ['thislibdoesnotexist_foobar'], []) raises(OSError, core.load_lib, [], ['notalib'], [fi_dir])
def test_findlib2(): if not sys.platform.startswith("linux"): skip("test on linux only") need_internet() # need our own version of FI to test this bit # Candidate libs for common freeimage fi_dir = os.path.join(core.appdata_dir("imageio"), "freeimage") if not os.path.isdir(fi_dir): os.mkdir(fi_dir) dirs, paths = core.findlib.generate_candidate_libs(["libfreeimage"], [fi_dir]) # assert fi_dir in dirs -> Cannot test: lib may not exist assert paths open(os.path.join(fi_dir, "notalib.test.so"), "wb") # Loading libs gllib = ctypes.util.find_library("GL") core.load_lib([gllib], []) core.load_lib([], ["libfreeimage"], [fi_dir]) # Fail raises(ValueError, core.load_lib, [], []) # Nothing given raises(ValueError, core.load_lib, ["", None], []) # Nothing given raises(OSError, core.load_lib, ["thislibdoesnotexist_foobar"], []) raises(OSError, core.load_lib, [], ["notalib"], [fi_dir])
def test_findlib2(): if not sys.platform.startswith('linux'): skip('test on linux only') need_internet() # need our own version of FI to test this bit # Candidate libs for common freeimage fi_dir = os.path.join(core.appdata_dir('imageio'), 'freeimage') if not os.path.isdir(fi_dir): os.mkdir(fi_dir) dirs, paths = core.findlib.generate_candidate_libs(['libfreeimage'], [fi_dir]) #assert fi_dir in dirs -> Cannot test: lib may not exist assert paths open(os.path.join(fi_dir, 'notalib.test.so'), 'wb') # Loading libs gllib = ctypes.util.find_library('GL') core.load_lib([gllib], []) core.load_lib([], ['libfreeimage'], [fi_dir]) # Fail raises(ValueError, core.load_lib, [], []) # Nothing given raises(ValueError, core.load_lib, ['', None], []) # Nothing given raises(OSError, core.load_lib, ['thislibdoesnotexist_foobar'], []) raises(OSError, core.load_lib, [], ['notalib'], [fi_dir])
def test_findlib(): """ Test finding of libs """ if not sys.platform.startswith('linux'): return # Candidate libs for common lib dirs, paths = core.findlib.generate_candidate_libs(['libpython']) assert paths # Candidate libs for common freeimage fi_dir = os.path.join(core.appdata_dir('imageio'), 'freeimage') dirs, paths = core.findlib.generate_candidate_libs(['libfreeimage'], [fi_dir]) assert fi_dir in dirs assert paths open(os.path.join(fi_dir, 'notalib.test.so'), 'wb') # Loading libs gllib = ctypes.util.find_library('GL') core.load_lib([gllib], []) core.load_lib([], ['libfreeimage'], [fi_dir]) # Fail raises(ValueError, core.load_lib, [], []) # Nothing given raises(ValueError, core.load_lib, ['', None], []) # Nothing given raises(OSError, core.load_lib, ['thislibdoesnotexist_foobar'], []) raises(OSError, core.load_lib, [], ['notalib'], [fi_dir])
def test_findlib2(): if not sys.platform.startswith("linux"): skip("test on linux only") need_internet() # need our own version of FI to test this bit # Candidate libs for common freeimage fi_dir = os.path.join(core.appdata_dir("imageio"), "freeimage") if not os.path.isdir(fi_dir): os.mkdir(fi_dir) dirs, paths = core.findlib.generate_candidate_libs(["libfreeimage"], [fi_dir]) # assert fi_dir in dirs -> Cannot test: lib may not exist assert paths open(os.path.join(fi_dir, "notalib.test.so"), "wb") # Loading libs gllib = ctypes.util.find_library("GL") core.load_lib([gllib], []) core.load_lib([], ["libfreeimage"], [fi_dir]) # Fail raises(ValueError, core.load_lib, [], []) # Nothing given raises(ValueError, core.load_lib, ["", None], []) # Nothing given raises(OSError, core.load_lib, ["thislibdoesnotexist_foobar"], []) raises(OSError, core.load_lib, [], ["notalib"], [fi_dir])
def test_findlib2(): if not sys.platform.startswith('linux'): skip('test on linux only') need_internet() # need our own version of FI to test this bit # Candidate libs for common freeimage fi_dir = os.path.join(core.appdata_dir('imageio'), 'freeimage') if not os.path.isdir(fi_dir): os.mkdir(fi_dir) dirs, paths = core.findlib.generate_candidate_libs(['libfreeimage'], [fi_dir]) #assert fi_dir in dirs -> Cannot test: lib may not exist assert paths open(os.path.join(fi_dir, 'notalib.test.so'), 'wb') # Loading libs gllib = ctypes.util.find_library('GL') core.load_lib([gllib], []) core.load_lib([], ['libfreeimage'], [fi_dir]) # Fail raises(ValueError, core.load_lib, [], []) # Nothing given raises(ValueError, core.load_lib, ['', None], []) # Nothing given raises(OSError, core.load_lib, ['thislibdoesnotexist_foobar'], []) raises(OSError, core.load_lib, [], ['notalib'], [fi_dir])
def _load_freeimage(self): # todo: we want to load from location relative to exe in frozen apps # Get lib dirs lib_dirs = [appdata_dir('imageio')] # Make sure that we have our binary version of the libary lib_filename = get_freeimage_lib() or 'notavalidlibname' # Load library lib_names = ['freeimage', 'libfreeimage'] exact_lib_names = [lib_filename, 'FreeImage', 'libfreeimage.dylib', 'libfreeimage.so', 'libfreeimage.so.3'] try: lib, fname = load_lib(exact_lib_names, lib_names, lib_dirs) except OSError: # pragma: no cover # Could not load. Get why e_type, e_value, e_tb = sys.exc_info() del e_tb load_error = str(e_value) err_msg = load_error + '\nPlease install the FreeImage library.' raise OSError(err_msg) # Store self._lib = lib self._lib_fname = fname