Skip to content

Commit

Permalink
Merge branch 'main' into anyio
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Mar 10, 2024
2 parents e737994 + cdc988a commit c37329b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 4 additions & 0 deletions ipykernel/pickleutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from types import FunctionType

# This registers a hook when it's imported
try:
from ipyparallel.serialize import codeutil # noqa: F401
except ImportError:
pass
from traitlets.log import get_logger
from traitlets.utils.importstring import import_item

Expand Down
23 changes: 14 additions & 9 deletions tests/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,20 +620,25 @@ def test_sequential_control_messages():
# Get replies
replies = [get_reply(kc, msg_id, channel="control") for msg_id in msg_ids]

def ensure_datetime(arg):
# Support arg which is a datetime or str.
if isinstance(arg, str):
if sys.version_info[:2] < (3, 11) and arg.endswith("Z"):
# Python < 3.11 doesn't support "Z" suffix in datetime.fromisoformat,
# so use alternative timezone format.
# https://github.com/python/cpython/issues/80010
arg = arg[:-1] + "+00:00"
return datetime.fromisoformat(arg)
return arg

# Check messages are processed in order, one at a time, and of a sensible duration.
previous_end = None
for reply, sleep in zip(replies, sleeps):
start_str = reply["metadata"]["started"]
if sys.version_info[:2] < (3, 11) and start_str.endswith("Z"):
# Python < 3.11 doesn't support "Z" suffix in datetime.fromisoformat,
# so use alternative timezone format.
# https://github.com/python/cpython/issues/80010
start_str = start_str[:-1] + "+00:00"
start = datetime.fromisoformat(start_str)
end = reply["header"]["date"] # Already a datetime
start = ensure_datetime(reply["metadata"]["started"])
end = ensure_datetime(reply["header"]["date"])

if previous_end is not None:
assert start > previous_end
assert start >= previous_end
previous_end = end

assert end >= start + timedelta(seconds=sleep)
Expand Down

0 comments on commit c37329b

Please sign in to comment.