Show More
@@ -17,6 +17,7 b' import shutil' | |||
|
17 | 17 | import sys |
|
18 | 18 | import tempfile |
|
19 | 19 | import unittest |
|
20 | import pytest | |
|
20 | 21 | from unittest import mock |
|
21 | 22 | |
|
22 | 23 | from os.path import join |
@@ -635,10 +636,23 b' class TestSystemRaw(ExitCodeChecks):' | |||
|
635 | 636 | ) |
|
636 | 637 | self.assertEqual(ip.user_ns["_exit_code"], -signal.SIGINT) |
|
637 | 638 | |
|
638 | def test_magic_warnings(self): | |
|
639 | for magic_cmd in ("pip", "conda", "cd"): | |
|
640 | with self.assertWarnsRegex(Warning, "You executed the system command"): | |
|
641 | ip.system_raw(magic_cmd) | |
|
639 | ||
|
640 | @pytest.mark.parametrize("magic_cmd", ["pip", "conda", "cd"]) | |
|
641 | def test_magic_warnings(magic_cmd): | |
|
642 | if sys.platform == "win32": | |
|
643 | to_mock = "os.system" | |
|
644 | expected_arg, expected_kwargs = magic_cmd, dict() | |
|
645 | else: | |
|
646 | to_mock = "subprocess.call" | |
|
647 | expected_arg, expected_kwargs = magic_cmd, dict( | |
|
648 | shell=True, executable=os.environ.get("SHELL", None) | |
|
649 | ) | |
|
650 | ||
|
651 | with mock.patch(to_mock, return_value=0) as mock_sub: | |
|
652 | with pytest.warns(Warning, match=r"You executed the system command"): | |
|
653 | ip.system_raw(magic_cmd) | |
|
654 | mock_sub.assert_called_once_with(expected_arg, **expected_kwargs) | |
|
655 | ||
|
642 | 656 | |
|
643 | 657 | # TODO: Exit codes are currently ignored on Windows. |
|
644 | 658 | class TestSystemPipedExitCode(ExitCodeChecks): |
@@ -1089,9 +1103,12 b' def test_run_cell_asyncio_run():' | |||
|
1089 | 1103 | |
|
1090 | 1104 | |
|
1091 | 1105 | def test_should_run_async(): |
|
1092 | assert not ip.should_run_async("a = 5") | |
|
1093 | assert ip.should_run_async("await x") | |
|
1094 |
assert ip.should_run_async( |
|
|
1106 | assert not ip.should_run_async("a = 5", transformed_cell="a = 5") | |
|
1107 | assert ip.should_run_async("await x", transformed_cell="await x") | |
|
1108 | assert ip.should_run_async( | |
|
1109 | "import asyncio; await asyncio.sleep(1)", | |
|
1110 | transformed_cell="import asyncio; await asyncio.sleep(1)", | |
|
1111 | ) | |
|
1095 | 1112 | |
|
1096 | 1113 | |
|
1097 | 1114 | def test_set_custom_completer(): |
General Comments 0
You need to be logged in to leave comments.
Login now