Skip to content

Commit

Permalink
Darker
Browse files Browse the repository at this point in the history
  • Loading branch information
covracer committed May 1, 2024
1 parent 7747c12 commit d3b1907
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions IPython/core/magics/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,11 +1598,11 @@ def _format_time(timespan, precision=3):
# See bug: https://bugs.launchpad.net/ipython/+bug/348466
# Try to prevent crashes by being more secure than it needs to
# E.g. eclipse is able to print a µ, but has no sys.stdout.encoding set.
units = [u"s", u"ms",u'us',"ns"] # the safe value
if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding:
units = ["s", "ms", "us", "ns"] # the safe value
if hasattr(sys.stdout, "encoding") and sys.stdout.encoding:
try:
u'\u03bc'.encode(sys.stdout.encoding)
units = [u"s", u"ms",u'\u03bcs',"ns"]
"\u03bc".encode(sys.stdout.encoding)
units = ["s", "ms", "\u03bcs", "ns"]
except:
pass
scaling = [1, 1e3, 1e6, 1e9]
Expand Down
10 changes: 6 additions & 4 deletions IPython/core/tests/test_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,14 @@ def test_time_local_ns():
assert ip.user_ns["myvar"] == 1
del ip.user_ns["myvar"]


def test_time_microseconds_display():
"""Ensure ASCII is used when necessary"""
with mock.patch('sys.stdout', io.TextIOWrapper(StringIO(), encoding='utf-8')):
assert execution._format_time(0.000001) == '1 \u03bcs'
with mock.patch('sys.stdout', io.TextIOWrapper(StringIO(), encoding='ascii')):
assert execution._format_time(0.000001) == '1 us'
with mock.patch("sys.stdout", io.TextIOWrapper(StringIO(), encoding="utf-8")):
assert execution._format_time(0.000001) == "1 \u03bcs"
with mock.patch("sys.stdout", io.TextIOWrapper(StringIO(), encoding="ascii")):
assert execution._format_time(0.000001) == "1 us"


# Test %%capture magic. Added to test issue #13926
def test_capture():
Expand Down

0 comments on commit d3b1907

Please sign in to comment.