def test_reraise(self): try: try: raise ValueError("foo") except Exception as e: util.reraise(TypeError, e) except Exception as e: self.assertTrue(isinstance(e, TypeError)) self.assertTrue("ValueError" in traceback.format_exc()) else: self.assertTrue(False)
def translate_errors(): """Context manager for mutagen calls to load/save. Translates exceptions to local ones. """ try: yield except AudioFileError: raise except mutagen.MutagenError as e: reraise(AudioFileError, e) except Exception as e: reraise(MutagenBug, e)
def init_backend(backend_name): """Imports the player backend module for the given name. Raises PlayerError if the import fails. the module provides the following functions: init(librarian) -> new player instance """ modulename = "quodlibet.player." + backend_name try: backend = importlib.import_module(modulename) except ImportError as e: util.reraise(PlayerError, str(e)) else: return backend
def init_backend(backend_name): """Imports the player backend module for the given name. Raises PlayerError if the import fails. the module provides the following functions: init(librarian) -> new player instance """ modulename = "quodlibet.player." + backend_name try: backend = __import__(modulename, {}, {}, "quodlibet.player") except Exception as e: if const.DEBUG: util.print_exc() util.reraise(PlayerError, str(e)) else: return backend