def test_subprocess_run_called_with_unknown_paltform(self): sys.platform = 'whatever_platform' with mock.patch('subprocess.run') as mock_run: utils.openFile(self.path) mock_run.assert_called_once_with(['Unknown platform', self.path], check=True)
def _openLicensesDir() -> None: license_file = resources.License.LICENSE.get() # pylint:disable=no-member license_dir = pathlib.Path(license_file).parent try: utils.openFile(license_dir) except subprocess.CalledProcessError: err_msg = f"Something went wrong while opening '{license_dir}'" logger.exception(err_msg) # Crazy hack: on Windows, for some reason, 'explorer's exit code # is 1, even though the directory is opened in the file manager, so # we do not show the error message to the user if not sys.platform.startswith('win32'): errornotifier.errorMessage([err_msg])
def openImage(self) -> None: '''Open the image in the OS default image viewer''' path = self.image.path try: utils.openFile(path) except subprocess.CalledProcessError: err_msg = f"Something went wrong while opening '{path}'" logger.exception(err_msg) # Crazy hack: on Windows, for some reason, 'explorer's exit code # is 1, even though the image is opened in the image viewer, so # we do not show the error message to the user if not sys.platform.startswith('win32'): errornotifier.errorMessage([err_msg])
def test_subprocess_run_called_with_mac_img_viewer_cmd(self): sys.platform = 'darwin' with mock.patch('subprocess.run') as mock_run: utils.openFile(self.path) mock_run.assert_called_once_with(['open', self.path], check=True)