##// END OF EJS Templates
run script tests on Windows...
Min RK -
Show More
@@ -970,103 +970,94 b' def test_script_config():'
970 assert "whoda" in sm.magics["cell"]
970 assert "whoda" in sm.magics["cell"]
971
971
972
972
973 @pytest.fixture
973 def test_script_out():
974 def event_loop():
975 policy = asyncio.get_event_loop_policy()
976 loop = policy.new_event_loop()
977 policy.set_event_loop(loop)
978 yield loop
979 loop.close()
980
981
982 @dec.skip_win32
983 @pytest.mark.skipif(
984 sys.platform == "win32", reason="This test does not run under Windows"
985 )
986 def test_script_out(event_loop):
987 assert event_loop.is_running() is False
988
989 ip = get_ipython()
974 ip = get_ipython()
990 ip.run_cell_magic("script", "--out output sh", "echo 'hi'")
975 ip.run_cell_magic("script", f"--out output {sys.executable}", "print('hi')")
991 assert not event_loop.is_running()
976 assert ip.user_ns["output"].strip() == "hi"
992 assert ip.user_ns["output"] == "hi\n"
993
977
994
978
995 @dec.skip_win32
979 def test_script_err():
996 @pytest.mark.skipif(
997 sys.platform == "win32", reason="This test does not run under Windows"
998 )
999 def test_script_err(event_loop):
1000 ip = get_ipython()
980 ip = get_ipython()
1001 assert not event_loop.is_running()
981 ip.run_cell_magic(
1002 ip.run_cell_magic("script", "--err error sh", "echo 'hello' >&2")
982 "script",
1003 assert not event_loop.is_running()
983 f"--err error {sys.executable}",
1004 assert ip.user_ns["error"] == "hello\n"
984 "import sys; print('hello', file=sys.stderr)",
985 )
986 assert ip.user_ns["error"].strip() == "hello"
1005
987
1006
988
1007 @dec.skip_win32
1008 @pytest.mark.skipif(
1009 sys.platform == "win32", reason="This test does not run under Windows"
1010 )
1011 def test_script_out_err():
989 def test_script_out_err():
1012
990
1013 ip = get_ipython()
991 ip = get_ipython()
1014 ip.run_cell_magic(
992 ip.run_cell_magic(
1015 "script", "--out output --err error sh", "echo 'hi'\necho 'hello' >&2"
993 "script",
994 f"--out output --err error {sys.executable}",
995 "\n".join(
996 [
997 "import sys",
998 "print('hi')",
999 "print('hello', file=sys.stderr)",
1000 ]
1001 ),
1016 )
1002 )
1017 assert ip.user_ns["output"] == "hi\n"
1003 assert ip.user_ns["output"].strip() == "hi"
1018 assert ip.user_ns["error"] == "hello\n"
1004 assert ip.user_ns["error"].strip() == "hello"
1019
1005
1020
1006
1021 @dec.skip_win32
1022 @pytest.mark.skipif(
1023 sys.platform == "win32", reason="This test does not run under Windows"
1024 )
1025 async def test_script_bg_out():
1007 async def test_script_bg_out():
1026 ip = get_ipython()
1008 ip = get_ipython()
1027 ip.run_cell_magic("script", "--bg --out output sh", "echo 'hi'")
1009 ip.run_cell_magic("script", f"--bg --out output {sys.executable}", "print('hi')")
1028 assert (await ip.user_ns["output"].read()) == b"hi\n"
1010 assert (await ip.user_ns["output"].read()).strip() == b"hi"
1029 assert ip.user_ns["output"].at_eof()
1011 assert ip.user_ns["output"].at_eof()
1030
1012
1031 @dec.skip_win32
1013
1032 @pytest.mark.skipif(
1033 sys.platform == "win32", reason="This test does not run under Windows"
1034 )
1035 async def test_script_bg_err():
1014 async def test_script_bg_err():
1036 ip = get_ipython()
1015 ip = get_ipython()
1037 ip.run_cell_magic("script", "--bg --err error sh", "echo 'hello' >&2")
1016 ip.run_cell_magic(
1038 assert (await ip.user_ns["error"].read()) == b"hello\n"
1017 "script",
1018 f"--bg --err error {sys.executable}",
1019 "import sys; print('hello', file=sys.stderr)",
1020 )
1021 assert (await ip.user_ns["error"].read()).strip() == b"hello"
1039 assert ip.user_ns["error"].at_eof()
1022 assert ip.user_ns["error"].at_eof()
1040
1023
1041
1024
1042 @dec.skip_win32
1043 @pytest.mark.skipif(
1044 sys.platform == "win32", reason="This test does not run under Windows"
1045 )
1046 async def test_script_bg_out_err():
1025 async def test_script_bg_out_err():
1047 ip = get_ipython()
1026 ip = get_ipython()
1048 ip.run_cell_magic(
1027 ip.run_cell_magic(
1049 "script", "--bg --out output --err error sh", "echo 'hi'\necho 'hello' >&2"
1028 "script",
1029 f"--bg --out output --err error {sys.executable}",
1030 "\n".join(
1031 [
1032 "import sys",
1033 "print('hi')",
1034 "print('hello', file=sys.stderr)",
1035 ]
1036 ),
1050 )
1037 )
1051 assert (await ip.user_ns["output"].read()) == b"hi\n"
1038 assert (await ip.user_ns["output"].read()).strip() == b"hi"
1052 assert (await ip.user_ns["error"].read()) == b"hello\n"
1039 assert (await ip.user_ns["error"].read()).strip() == b"hello"
1053 assert ip.user_ns["output"].at_eof()
1040 assert ip.user_ns["output"].at_eof()
1054 assert ip.user_ns["error"].at_eof()
1041 assert ip.user_ns["error"].at_eof()
1055
1042
1056
1043
1057 @dec.skip_win32
1058 @pytest.mark.skipif(
1059 sys.platform == "win32", reason="This test does not run under Windows"
1060 )
1061 async def test_script_bg_proc():
1044 async def test_script_bg_proc():
1062 ip = get_ipython()
1045 ip = get_ipython()
1063 ip.run_cell_magic(
1046 ip.run_cell_magic(
1064 "script", "--bg --proc p sh --out out", "echo 'hi'\necho 'hello' >&2"
1047 "script",
1048 f"--bg --out output --proc p {sys.executable}",
1049 "\n".join(
1050 [
1051 "import sys",
1052 "print('hi')",
1053 "print('hello', file=sys.stderr)",
1054 ]
1055 ),
1065 )
1056 )
1066 p = ip.user_ns["p"]
1057 p = ip.user_ns["p"]
1067 await p.wait()
1058 await p.wait()
1068 assert p.returncode == 0
1059 assert p.returncode == 0
1069 assert (await p.stdout.read()) == b"hi\n"
1060 assert (await p.stdout.read()).strip() == b"hi"
1070 # not captured, so empty
1061 # not captured, so empty
1071 assert (await p.stderr.read()) == b""
1062 assert (await p.stderr.read()) == b""
1072 assert p.stdout.at_eof()
1063 assert p.stdout.at_eof()
General Comments 0
You need to be logged in to leave comments. Login now