|
4 | 4 | Needs to be run by nose (to make ipython session available). |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import asyncio |
7 | 8 | import io |
8 | 9 | import os |
9 | 10 | import re |
| 11 | +import shlex |
10 | 12 | import sys |
11 | 13 | import warnings |
12 | | -from textwrap import dedent |
13 | | -from unittest import TestCase |
14 | | -from unittest import mock |
15 | 14 | from importlib import invalidate_caches |
16 | 15 | from io import StringIO |
17 | 16 | from pathlib import Path |
| 17 | +from textwrap import dedent |
| 18 | +from unittest import TestCase, mock |
18 | 19 |
|
19 | 20 | import nose.tools as nt |
20 | 21 |
|
21 | | -import shlex |
| 22 | +import pytest |
22 | 23 |
|
23 | 24 | from IPython import get_ipython |
24 | 25 | from IPython.core import magic |
25 | 26 | from IPython.core.error import UsageError |
26 | | -from IPython.core.magic import (Magics, magics_class, line_magic, |
27 | | - cell_magic, |
28 | | - register_line_magic, register_cell_magic) |
29 | | -from IPython.core.magics import execution, script, code, logging, osm |
| 27 | +from IPython.core.magic import ( |
| 28 | + Magics, |
| 29 | + cell_magic, |
| 30 | + line_magic, |
| 31 | + magics_class, |
| 32 | + register_cell_magic, |
| 33 | + register_line_magic, |
| 34 | +) |
| 35 | +from IPython.core.magics import code, execution, logging, osm, script |
30 | 36 | from IPython.testing import decorators as dec |
31 | 37 | from IPython.testing import tools as tt |
32 | 38 | from IPython.utils.io import capture_output |
33 | | -from IPython.utils.tempdir import (TemporaryDirectory, |
34 | | - TemporaryWorkingDirectory) |
35 | 39 | from IPython.utils.process import find_cmd |
36 | | -from .test_debugger import PdbTestInput |
| 40 | +from IPython.utils.tempdir import TemporaryDirectory, TemporaryWorkingDirectory |
37 | 41 |
|
38 | | -import pytest |
| 42 | +from .test_debugger import PdbTestInput |
39 | 43 |
|
40 | 44 |
|
41 | 45 | @magic.magics_class |
@@ -947,41 +951,76 @@ def test_script_config(): |
947 | 951 | sm = script.ScriptMagics(shell=ip) |
948 | 952 | nt.assert_in('whoda', sm.magics['cell']) |
949 | 953 |
|
| 954 | +@dec.skip_iptest_but_not_pytest |
950 | 955 | @dec.skip_win32 |
| 956 | +@pytest.mark.skipif( |
| 957 | + sys.platform == "win32", reason="This test does not run under Windows" |
| 958 | +) |
951 | 959 | def test_script_out(): |
| 960 | + assert asyncio.get_event_loop().is_running() is False |
| 961 | + |
952 | 962 | ip = get_ipython() |
953 | 963 | ip.run_cell_magic("script", "--out output sh", "echo 'hi'") |
| 964 | + assert asyncio.get_event_loop().is_running() is False |
954 | 965 | nt.assert_equal(ip.user_ns['output'], 'hi\n') |
955 | 966 |
|
| 967 | +@dec.skip_iptest_but_not_pytest |
956 | 968 | @dec.skip_win32 |
| 969 | +@pytest.mark.skipif( |
| 970 | + sys.platform == "win32", reason="This test does not run under Windows" |
| 971 | +) |
957 | 972 | def test_script_err(): |
958 | 973 | ip = get_ipython() |
| 974 | + assert asyncio.get_event_loop().is_running() is False |
959 | 975 | ip.run_cell_magic("script", "--err error sh", "echo 'hello' >&2") |
| 976 | + assert asyncio.get_event_loop().is_running() is False |
960 | 977 | nt.assert_equal(ip.user_ns['error'], 'hello\n') |
961 | 978 |
|
| 979 | + |
| 980 | +@dec.skip_iptest_but_not_pytest |
962 | 981 | @dec.skip_win32 |
| 982 | +@pytest.mark.skipif( |
| 983 | + sys.platform == "win32", reason="This test does not run under Windows" |
| 984 | +) |
963 | 985 | def test_script_out_err(): |
| 986 | + |
964 | 987 | ip = get_ipython() |
965 | | - ip.run_cell_magic("script", "--out output --err error sh", "echo 'hi'\necho 'hello' >&2") |
966 | | - nt.assert_equal(ip.user_ns['output'], 'hi\n') |
967 | | - nt.assert_equal(ip.user_ns['error'], 'hello\n') |
| 988 | + ip.run_cell_magic( |
| 989 | + "script", "--out output --err error sh", "echo 'hi'\necho 'hello' >&2" |
| 990 | + ) |
| 991 | + nt.assert_equal(ip.user_ns["output"], "hi\n") |
| 992 | + nt.assert_equal(ip.user_ns["error"], "hello\n") |
968 | 993 |
|
| 994 | + |
| 995 | +@dec.skip_iptest_but_not_pytest |
969 | 996 | @dec.skip_win32 |
| 997 | +@pytest.mark.skipif( |
| 998 | + sys.platform == "win32", reason="This test does not run under Windows" |
| 999 | +) |
970 | 1000 | async def test_script_bg_out(): |
971 | 1001 | ip = get_ipython() |
972 | 1002 | ip.run_cell_magic("script", "--bg --out output sh", "echo 'hi'") |
973 | 1003 | nt.assert_equal((await ip.user_ns["output"].read()), b"hi\n") |
974 | | - ip.user_ns['output'].close() |
| 1004 | + ip.user_ns["output"].close() |
| 1005 | + asyncio.get_event_loop().stop() |
975 | 1006 |
|
| 1007 | +@dec.skip_iptest_but_not_pytest |
976 | 1008 | @dec.skip_win32 |
| 1009 | +@pytest.mark.skipif( |
| 1010 | + sys.platform == "win32", reason="This test does not run under Windows" |
| 1011 | +) |
977 | 1012 | async def test_script_bg_err(): |
978 | 1013 | ip = get_ipython() |
979 | 1014 | ip.run_cell_magic("script", "--bg --err error sh", "echo 'hello' >&2") |
980 | 1015 | nt.assert_equal((await ip.user_ns["error"].read()), b"hello\n") |
981 | 1016 | ip.user_ns["error"].close() |
982 | 1017 |
|
983 | 1018 |
|
| 1019 | +@dec.skip_iptest_but_not_pytest |
984 | 1020 | @dec.skip_win32 |
| 1021 | +@pytest.mark.skipif( |
| 1022 | + sys.platform == "win32", reason="This test does not run under Windows" |
| 1023 | +) |
985 | 1024 | async def test_script_bg_out_err(): |
986 | 1025 | ip = get_ipython() |
987 | 1026 | ip.run_cell_magic( |
|
0 commit comments