Work around #1603 in tests.

Add long_tmpdir fixture, that always supplies a long rather than short path name on Windows.

Use long_tmpdir in the implementation of @pyfile, and in all tests that use tmpdir to generate code.
This commit is contained in:
Pavel Minaev 2019-07-18 02:48:34 -07:00 committed by Pavel Minaev
parent 3cb99794d9
commit 73d29fa55b
2 changed files with 32 additions and 9 deletions

View file

@ -15,7 +15,7 @@ from tests.patterns import some
@pytest.mark.skipif(sys.platform == "win32", reason="Linux/Mac only test.")
@pytest.mark.parametrize("os_type", ["INVALID", ""])
def test_client_ide_from_path_mapping_linux_backend(
pyfile, tmpdir, start_method, run_as, os_type
pyfile, start_method, run_as, os_type
):
"""
Test simulating that the backend is on Linux and the client is on Windows
@ -65,7 +65,7 @@ def test_client_ide_from_path_mapping_linux_backend(
session.wait_for_exit()
def test_with_dot_remote_root(pyfile, tmpdir, start_method, run_as):
def test_with_dot_remote_root(pyfile, long_tmpdir, start_method, run_as):
@pyfile
def code_to_debug():
from debug_me import backchannel
@ -74,8 +74,8 @@ def test_with_dot_remote_root(pyfile, tmpdir, start_method, run_as):
backchannel.send(os.path.abspath(__file__))
print("done") # @bp
path_local = tmpdir.mkdir("local") / "code_to_debug.py"
path_remote = tmpdir.mkdir("remote") / "code_to_debug.py"
path_local = long_tmpdir.mkdir("local") / "code_to_debug.py"
path_remote = long_tmpdir.mkdir("remote") / "code_to_debug.py"
dir_local = path_local.dirname
dir_remote = path_remote.dirname
@ -110,7 +110,7 @@ def test_with_dot_remote_root(pyfile, tmpdir, start_method, run_as):
session.wait_for_exit()
def test_with_path_mappings(pyfile, tmpdir, start_method, run_as):
def test_with_path_mappings(pyfile, long_tmpdir, start_method, run_as):
@pyfile
def code_to_debug():
from debug_me import backchannel
@ -129,8 +129,8 @@ def test_with_path_mappings(pyfile, tmpdir, start_method, run_as):
call_me_back.call_me_back(call_func) # @call_me_back
print("done")
dir_local = tmpdir.mkdir("local")
dir_remote = tmpdir.mkdir("remote")
dir_local = long_tmpdir.mkdir("local")
dir_remote = long_tmpdir.mkdir("remote")
path_local = dir_local / "code_to_debug.py"
path_remote = dir_remote / "code_to_debug.py"

View file

@ -7,6 +7,7 @@ from __future__ import absolute_import, print_function, unicode_literals
import inspect
import os
import platform
import py.path
import pytest
import tempfile
import threading
@ -97,8 +98,30 @@ def daemon(request):
assert not thread.is_alive()
if platform.system() != 'Windows':
@pytest.fixture
def long_tmpdir(request, tmpdir):
return tmpdir
else:
import ctypes
GetLongPathNameW = ctypes.windll.kernel32.GetLongPathNameW
GetLongPathNameW.argtypes = [ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32]
GetLongPathNameW.restype = ctypes.c_uint32
@pytest.fixture
def long_tmpdir(request, tmpdir):
"""Like tmpdir, but ensures that it's a long rather than short filename on Win32.
"""
path = compat.filename(tmpdir.strpath)
buffer = ctypes.create_unicode_buffer(512)
if GetLongPathNameW(path, buffer, len(buffer)):
path = buffer.value
return py.path.local(path)
@pytest.fixture
def pyfile(request, tmpdir):
def pyfile(request, long_tmpdir):
"""A fixture providing a factory function that generates .py files.
The returned factory takes a single function with an empty argument list,
@ -160,7 +183,7 @@ def pyfile(request, tmpdir):
source = ''.join(source)
# Write it to file.
tmpfile = tmpdir / (name + '.py')
tmpfile = long_tmpdir / (name + '.py')
tmpfile.strpath = compat.filename(tmpfile.strpath)
assert not tmpfile.check()
tmpfile.write(source)