2018-11-26 12:27:41 +00:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import pytest
|
2018-11-24 14:34:23 +00:00
|
|
|
import os
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from ..compat import symlink_to, symlink_remove, path2str
|
|
|
|
|
|
|
|
|
|
|
|
def target_local_path():
|
2018-11-26 12:27:41 +00:00
|
|
|
return "./foo-target"
|
|
|
|
|
2018-11-24 14:34:23 +00:00
|
|
|
|
|
|
|
def link_local_path():
|
2018-11-26 12:27:41 +00:00
|
|
|
return "./foo-symlink"
|
2018-11-24 14:34:23 +00:00
|
|
|
|
|
|
|
|
2018-11-26 12:27:41 +00:00
|
|
|
@pytest.fixture(scope="function")
|
2018-11-24 14:34:23 +00:00
|
|
|
def setup_target(request):
|
2018-11-26 12:27:41 +00:00
|
|
|
target = Path(target_local_path())
|
|
|
|
if not target.exists():
|
|
|
|
os.mkdir(path2str(target))
|
2018-11-24 14:34:23 +00:00
|
|
|
|
2018-11-26 12:27:41 +00:00
|
|
|
# yield -- need to cleanup even if assertion fails
|
|
|
|
# https://github.com/pytest-dev/pytest/issues/2508#issuecomment-309934240
|
|
|
|
def cleanup():
|
|
|
|
symlink_remove(Path(link_local_path()))
|
|
|
|
os.rmdir(target_local_path())
|
2018-11-24 14:34:23 +00:00
|
|
|
|
2018-11-26 12:27:41 +00:00
|
|
|
request.addfinalizer(cleanup)
|
2018-11-24 14:34:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_create_symlink_windows(setup_target):
|
2018-11-26 12:27:41 +00:00
|
|
|
target = Path(target_local_path())
|
|
|
|
link = Path(link_local_path())
|
|
|
|
assert target.exists()
|
2018-11-24 14:34:23 +00:00
|
|
|
|
2018-11-26 12:27:41 +00:00
|
|
|
symlink_to(link, target)
|
|
|
|
assert link.exists()
|