Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe2cad8

Browse files
committed
Fix unicode printing on windows in tests.
and a few other fixes.
1 parent eaf2267 commit fe2cad8

5 files changed

Lines changed: 11 additions & 12 deletions

File tree

IPython/core/interactiveshell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ def banner(self):
10021002
def show_banner(self, banner=None):
10031003
if banner is None:
10041004
banner = self.banner
1005-
sys.stdout.write(banner)
1005+
print(banner)
10061006

10071007
#-------------------------------------------------------------------------
10081008
# Things related to hooks

IPython/utils/tempdir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class NamedFileInTemporaryDirectory:
13-
def __init__(self, filename, mode="w+b", bufsize=-1, add_to_syspath=False, **kwds):
13+
def __init__(self, filename, mode, bufsize=-1, add_to_syspath=False, **kwds):
1414
"""
1515
Open a file named `filename` in a temporary directory.
1616

tests/test_display_2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def test_video_embedding():
347347
with pytest.raises(ValueError):
348348
v = display.Video(b"abc")
349349

350-
with NamedFileInTemporaryDirectory("test.mp4") as f:
350+
with NamedFileInTemporaryDirectory("test.mp4", "wb") as f:
351351
f.write(b"abc")
352352
f.close()
353353

tests/test_embed.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# -----------------------------------------------------------------------------
2525

2626

27-
_sample_embed = b"""
27+
_sample_embed = """
2828
import IPython
2929
3030
a = 3
@@ -36,12 +36,12 @@
3636
print('bye!')
3737
"""
3838

39-
_exit = b"exit\r"
39+
_exit = "exit\r"
4040

4141

4242
def test_ipython_embed():
4343
"""test that `IPython.embed()` works"""
44-
with NamedFileInTemporaryDirectory("file_with_embed.py") as f:
44+
with NamedFileInTemporaryDirectory("file_with_embed.py", "w") as f:
4545
f.write(_sample_embed)
4646
f.flush()
4747
f.close() # otherwise msft won't be able to read the file
@@ -57,12 +57,11 @@ def test_ipython_embed():
5757
stdin=subprocess.PIPE,
5858
stdout=subprocess.PIPE,
5959
stderr=subprocess.PIPE,
60+
text=True,
61+
encoding="UTF-8",
6062
)
61-
out, err = p.communicate(_exit)
62-
try:
63-
std = out.decode("UTF-8", "replace")
64-
except UnicodeDecodeError as e:
65-
raise ValueError(f"Error decoding {out!r}") from e
63+
std, err = p.communicate(_exit)
64+
assert isinstance(std, str)
6665

6766
assert p.returncode == 0, (p.returncode, std)
6867
assert "3 . 14" in std

tests/test_tempdir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def test_named_file_in_temporary_directory():
15-
with NamedFileInTemporaryDirectory("filename") as file:
15+
with NamedFileInTemporaryDirectory("filename", "wb") as file:
1616
name = file.name
1717
assert not file.closed
1818
assert Path(name).exists()

0 commit comments

Comments
 (0)