Skip to content

Commit ab39179

Browse files
committed
test: enable test_connect_socket Windows
1 parent 38cbc4f commit ab39179

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

test/test_attach.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,30 @@
1818
# pylint: disable=redefined-outer-name
1919

2020

21-
xfail_on_windows = pytest.mark.xfail(
22-
"os.name == 'nt'", reason="Broken in Windows, see #544")
21+
@pytest.fixture
22+
def server_addr() -> Generator[str, None, None]:
23+
"""Get a socket/named pipe address using serverstart().
2324
25+
On UNIX this is a socket path, on Windows a named pipe.
26+
"""
27+
nvim = pynvim.attach('child', argv=[
28+
"nvim", "--clean", "--embed",
29+
])
30+
addr = nvim.funcs.serverstart()
31+
nvim.funcs.serverstop(addr)
32+
nvim.close()
2433

25-
@pytest.fixture
26-
def tmp_socket() -> Generator[str, None, None]:
27-
"""Get a temporary UNIX socket file."""
28-
# see cpython#93914
29-
addr = tempfile.mktemp(prefix="test_python_", suffix='.sock',
30-
dir=os.path.curdir)
31-
try:
32-
yield addr
33-
finally:
34-
if os.path.exists(addr):
35-
with contextlib.suppress(OSError):
36-
os.unlink(addr)
34+
yield addr
3735

3836

39-
@xfail_on_windows
40-
def test_connect_socket(tmp_socket: str) -> None:
41-
"""Tests UNIX socket connection."""
42-
p = subprocess.Popen(["nvim", "--clean", "-n", "--headless",
43-
"--listen", tmp_socket])
37+
def test_connect_socket(server_addr: str) -> None:
38+
"""Tests socket/pipe connection."""
39+
p = subprocess.Popen(["nvim", "--clean", "--headless",
40+
"--listen", server_addr])
4441
time.sleep(0.2) # wait a bit until nvim starts up
4542

4643
try:
47-
nvim: Nvim = pynvim.attach('socket', path=tmp_socket)
44+
nvim: Nvim = pynvim.attach('socket', path=server_addr)
4845
assert 42 == nvim.eval('42')
4946
assert "?" == nvim.command_output('echo "?"')
5047
finally:
@@ -69,7 +66,7 @@ def test_connect_tcp() -> None:
6966
"""Tests TCP connection."""
7067
address = '127.0.0.1'
7168
port = find_free_port()
72-
p = subprocess.Popen(["nvim", "--clean", "-n", "--headless",
69+
p = subprocess.Popen(["nvim", "--clean", "--headless",
7370
"--listen", f"{address}:{port}"])
7471
time.sleep(0.2) # wait a bit until nvim starts up
7572

@@ -91,7 +88,8 @@ def test_connect_tcp_no_server() -> None:
9188
pynvim.attach('tcp', address='127.0.0.1', port=port)
9289

9390

94-
@xfail_on_windows
91+
@pytest.mark.xfail("os.name == 'nt'",
92+
reason="stdio attach broken on Windows, see #544")
9593
def test_connect_stdio(vim: Nvim) -> None:
9694
"""Tests stdio connection, using jobstart(..., {'rpc': v:true})."""
9795

0 commit comments

Comments
 (0)