Skip to content

Commit a6e182c

Browse files
committed
Remove use of ipython_genutils.
1 parent 7ec4a5b commit a6e182c

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

jupyter_console/ptshell.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import signal
1212
import subprocess
1313
import sys
14+
from tempfile import TemporaryDirectory
1415
import time
1516
from warnings import warn
1617

1718
from typing import Dict as DictType, Any as AnyType
1819

1920
from zmq import ZMQError
2021
from IPython.core import page
21-
from ipython_genutils.tempdir import NamedFileInTemporaryDirectory
2222
from traitlets import (
2323
Bool,
2424
Integer,
@@ -984,10 +984,11 @@ def handle_image_tempfile(self, data, mime):
984984
raw = base64.decodebytes(data[mime].encode('ascii'))
985985
imageformat = self._imagemime[mime]
986986
filename = 'tmp.{0}'.format(imageformat)
987-
with NamedFileInTemporaryDirectory(filename) as f:
988-
f.write(raw)
989-
f.flush()
990-
fmt = dict(file=f.name, format=imageformat)
987+
with TemporaryDirectory() as tempdir:
988+
fullpath = os.path.join(tempdir, filename)
989+
with open(fullpath, 'wb') as f:
990+
f.write(raw)
991+
fmt = dict(file=fullpath, format=imageformat)
991992
args = [s.format(**fmt) for s in self.tempfile_image_handler]
992993
rc = subprocess.call(args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
993994
return (rc == 0)

jupyter_console/tests/test_image_handler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Copyright (c) IPython Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4+
import base64
45
import os
56
import sys
7+
from tempfile import TemporaryDirectory
68
import unittest
7-
import base64
8-
99
from unittest.mock import patch
1010

11+
import pytest
12+
1113
from jupyter_console.ptshell import ZMQTerminalInteractiveShell
12-
from ipython_genutils.tempdir import TemporaryDirectory
13-
from ipython_genutils.testing.decorators import skip_without
1414

1515

1616
SCRIPT_PATH = os.path.join(
@@ -48,8 +48,8 @@ def raise_if_called(*args, **kwds):
4848
shell.handle_image(None, None) # arguments are dummy
4949
assert len(pil_called_with) == 1
5050

51-
@skip_without('PIL')
5251
def test_handle_image_PIL(self):
52+
pytest.importorskip('PIL')
5353
from PIL import Image, ImageShow
5454

5555
open_called_with = []

0 commit comments

Comments
 (0)