Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: mock slowest test. #13885

Merged
merged 1 commit into from Feb 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 24 additions & 7 deletions IPython/core/tests/test_interactiveshell.py
Expand Up @@ -17,6 +17,7 @@
import sys
import tempfile
import unittest
import pytest
from unittest import mock

from os.path import join
Expand Down Expand Up @@ -635,10 +636,23 @@ def test_control_c(self, *mocks):
)
self.assertEqual(ip.user_ns["_exit_code"], -signal.SIGINT)

def test_magic_warnings(self):
for magic_cmd in ("pip", "conda", "cd"):
with self.assertWarnsRegex(Warning, "You executed the system command"):
ip.system_raw(magic_cmd)

@pytest.mark.parametrize("magic_cmd", ["pip", "conda", "cd"])
def test_magic_warnings(magic_cmd):
if sys.platform == "win32":
to_mock = "os.system"
expected_arg, expected_kwargs = magic_cmd, dict()
else:
to_mock = "subprocess.call"
expected_arg, expected_kwargs = magic_cmd, dict(
shell=True, executable=os.environ.get("SHELL", None)
)

with mock.patch(to_mock, return_value=0) as mock_sub:
with pytest.warns(Warning, match=r"You executed the system command"):
ip.system_raw(magic_cmd)
mock_sub.assert_called_once_with(expected_arg, **expected_kwargs)


# TODO: Exit codes are currently ignored on Windows.
class TestSystemPipedExitCode(ExitCodeChecks):
Expand Down Expand Up @@ -1089,9 +1103,12 @@ def test_run_cell_asyncio_run():


def test_should_run_async():
assert not ip.should_run_async("a = 5")
assert ip.should_run_async("await x")
assert ip.should_run_async("import asyncio; await asyncio.sleep(1)")
assert not ip.should_run_async("a = 5", transformed_cell="a = 5")
assert ip.should_run_async("await x", transformed_cell="await x")
assert ip.should_run_async(
"import asyncio; await asyncio.sleep(1)",
transformed_cell="import asyncio; await asyncio.sleep(1)",
)


def test_set_custom_completer():
Expand Down