path: local: str return full path on value error

This commit is contained in:
prd
2019-05-14 16:56:24 -07:00
committed by pared
parent 026d209599
commit 1cb4e5233e
3 changed files with 52 additions and 0 deletions
+33
View File
@@ -97,3 +97,36 @@ def ssh(ssh_server):
port=ssh_server.port,
key_filename=key_path,
)
@pytest.fixture
def temporary_windows_drive(repo_dir):
import string
import win32api
from ctypes import windll
from win32con import DDD_REMOVE_DEFINITION
drives = [
s[0].upper()
for s in win32api.GetLogicalDriveStrings().split("\000")
if len(s) > 0
]
new_drive_name = [
letter for letter in string.ascii_uppercase if letter not in drives
][0]
new_drive = "{}:".format(new_drive_name)
target_path = repo_dir.mkdtemp()
set_up_result = windll.kernel32.DefineDosDeviceW(0, new_drive, target_path)
if set_up_result == 0:
raise RuntimeError("Failed to mount windows drive!")
yield new_drive
tear_down_result = windll.kernel32.DefineDosDeviceW(
DDD_REMOVE_DEFINITION, new_drive, target_path
)
if tear_down_result == 0:
raise RuntimeError("Could not unmount windows drive!")