Blob Blame History Raw
From a6e182c463571a189be3d21f56f81c247be85cdb Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Sun, 21 Mar 2021 02:21:45 -0400
Subject: [PATCH 2/2] Remove use of ipython_genutils.

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
 jupyter_console/ptshell.py                  | 11 ++++++-----
 jupyter_console/tests/test_image_handler.py | 10 +++++-----
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/jupyter_console/ptshell.py b/jupyter_console/ptshell.py
index 2c46462..b26ddec 100644
--- a/jupyter_console/ptshell.py
+++ b/jupyter_console/ptshell.py
@@ -11,6 +11,7 @@ from queue import Empty
 import signal
 import subprocess
 import sys
+from tempfile import TemporaryDirectory
 import time
 from warnings import warn
 
@@ -18,7 +19,6 @@ from typing import Dict as DictType, Any as AnyType
 
 from zmq import ZMQError
 from IPython.core import page
-from ipython_genutils.tempdir import NamedFileInTemporaryDirectory
 from traitlets import (
     Bool,
     Integer,
@@ -984,10 +984,11 @@ class ZMQTerminalInteractiveShell(SingletonConfigurable):
         raw = base64.decodebytes(data[mime].encode('ascii'))
         imageformat = self._imagemime[mime]
         filename = 'tmp.{0}'.format(imageformat)
-        with NamedFileInTemporaryDirectory(filename) as f:
-            f.write(raw)
-            f.flush()
-            fmt = dict(file=f.name, format=imageformat)
+        with TemporaryDirectory() as tempdir:
+            fullpath = os.path.join(tempdir, filename)
+            with open(fullpath, 'wb') as f:
+                f.write(raw)
+            fmt = dict(file=fullpath, format=imageformat)
             args = [s.format(**fmt) for s in self.tempfile_image_handler]
             rc = subprocess.call(args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
         return (rc == 0)
diff --git a/jupyter_console/tests/test_image_handler.py b/jupyter_console/tests/test_image_handler.py
index bcd2a32..28773b5 100644
--- a/jupyter_console/tests/test_image_handler.py
+++ b/jupyter_console/tests/test_image_handler.py
@@ -1,16 +1,16 @@
 # Copyright (c) IPython Development Team.
 # Distributed under the terms of the Modified BSD License.
 
+import base64
 import os
 import sys
+from tempfile import TemporaryDirectory
 import unittest
-import base64
-
 from unittest.mock import patch
 
+import pytest
+
 from jupyter_console.ptshell import ZMQTerminalInteractiveShell
-from ipython_genutils.tempdir import TemporaryDirectory
-from ipython_genutils.testing.decorators import skip_without
 
 
 SCRIPT_PATH = os.path.join(
@@ -48,8 +48,8 @@ class ZMQTerminalInteractiveShellTestCase(unittest.TestCase):
         shell.handle_image(None, None)  # arguments are dummy
         assert len(pil_called_with) == 1
 
-    @skip_without('PIL')
     def test_handle_image_PIL(self):
+        pytest.importorskip('PIL')
         from PIL import Image, ImageShow
 
         open_called_with = []
-- 
2.29.2