Skip to content

Commit

Permalink
Merge pull request conda#7369 from kalefranz/win-symlink-test-failures
Browse files Browse the repository at this point in the history
fix windows test failures when symlink not available
  • Loading branch information
kalefranz authored Jun 19, 2018
2 parents 6cfd3b6 + 99c5b8b commit 95ab6f4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
7 changes: 7 additions & 0 deletions tests/core/test_path_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from conda.gateways.disk.link import islink, stat_nlink
from conda.gateways.disk.permissions import is_executable
from conda.gateways.disk.read import compute_md5sum, compute_sha256sum
from conda.gateways.disk.test import softlink_supported
from conda.gateways.disk.update import touch
from conda.models.enums import LinkType, NoarchType, PathType
from conda.models.records import PathDataV1
Expand Down Expand Up @@ -107,6 +108,9 @@ def test_CompilePycAction_generic(self):
assert axns == ()

def test_CompilePycAction_noarch_python(self):
if not softlink_supported(__file__, self.prefix) and on_win:
pytest.skip("softlink not supported")

target_python_version = '%d.%d' % sys.version_info[:2]
sp_dir = get_python_site_packages_short_path(target_python_version)
transaction_context = {
Expand Down Expand Up @@ -261,6 +265,9 @@ def test_simple_LinkPathAction_hardlink(self):
assert not lexists(axn.target_full_path)

def test_simple_LinkPathAction_softlink(self):
if not softlink_supported(__file__, self.prefix) and on_win:
pytest.skip("softlink not supported")

source_full_path = make_test_file(self.pkgs_dir)
target_short_path = source_short_path = basename(source_full_path)

Expand Down
24 changes: 20 additions & 4 deletions tests/gateways/disk/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import pytest

from conda.compat import TemporaryDirectory
from conda.gateways.disk.create import create_link
from conda.common.compat import on_win
from conda.gateways.disk.create import create_link, mkdir_p
from conda.gateways.disk.delete import move_to_trash, rm_rf
from conda.gateways.disk.link import islink, symlink
from conda.gateways.disk.test import softlink_supported
from conda.gateways.disk.update import touch
from conda.models.enums import LinkType
from .test_permissions import _make_read_only, _try_open, tempdir
Expand Down Expand Up @@ -66,6 +68,9 @@ def test_remove_link_to_file():
dst_link = join(td, "test_link")
src_file = join(td, "test_file")
_write_file(src_file, "welcome to the ministry of silly walks")
if not softlink_supported(src_file, td) and on_win:
pytest.skip("softlink not supported")

symlink(src_file, dst_link)
assert isfile(src_file)
assert not islink(src_file)
Expand All @@ -82,17 +87,25 @@ def test_remove_link_to_dir():
with tempdir() as td:
dst_link = join(td, "test_link")
src_dir = join(td, "test_dir")
_write_file(src_dir, "welcome to the ministry of silly walks")
symlink(src_dir, dst_link)
test_file = join(td, "test_file")
mkdir_p(src_dir)
touch(test_file)
assert isdir(src_dir)
assert not islink(src_dir)
assert not islink(dst_link)
if not softlink_supported(test_file, td) and on_win:
pytest.skip("softlink not supported")

symlink(src_dir, dst_link)
assert islink(dst_link)
assert rm_rf(dst_link)
assert not isdir(dst_link)
assert not islink(dst_link)
assert not lexists(dst_link)
assert isdir(src_dir)
assert rm_rf(src_dir)
assert not isdir(src_dir)
assert not islink(src_dir)
assert not lexists(dst_link)


def test_rm_rf_does_not_follow_symlinks():
Expand All @@ -106,6 +119,9 @@ def test_rm_rf_does_not_follow_symlinks():
os.makedirs(subdir)
# link to the file in the subfolder
link_path = join(subdir, 'file_link')
if not softlink_supported(real_file, tmp) and on_win:
pytest.skip("softlink not supported")

create_link(real_file, link_path, link_type=LinkType.softlink)
assert islink(link_path)
# rm_rf the subfolder
Expand Down
8 changes: 7 additions & 1 deletion tests/gateways/disk/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from unittest import TestCase
import uuid

from conda.common.compat import on_win, PY2
import pytest

from conda.common.compat import on_win, PY2
from conda.gateways.disk.create import mkdir_p
from conda.gateways.disk.delete import rm_rf
from conda.gateways.disk.link import link, islink, readlink, stat_nlink, symlink
from conda.gateways.disk.test import softlink_supported
from conda.gateways.disk.update import touch

log = getLogger(__name__)
Expand Down Expand Up @@ -60,6 +62,10 @@ def test_soft_link(self):
assert isfile(path1_real_file)
assert not islink(path1_real_file)

if not softlink_supported(path1_real_file, self.test_dir) and on_win:
pytest.skip("softlink not supported")


symlink(path1_real_file, path2_symlink)
assert exists(path2_symlink)
assert lexists(path2_symlink)
Expand Down
5 changes: 4 additions & 1 deletion tests/test_exports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals

from conda.common.compat import on_win


def test_exports():
import conda.exports
Expand All @@ -12,7 +14,8 @@ def test_conda_subprocess():
from subprocess import Popen, PIPE
import conda

p = Popen(['echo', '"%s"' % conda.__version__], env=os.environ, stdout=PIPE, stderr=PIPE)
p = Popen(['echo', '"%s"' % conda.__version__], env=os.environ, stdout=PIPE, stderr=PIPE,
shell=on_win)
stdout, stderr = p.communicate()
rc = p.returncode
if rc != 0:
Expand Down

0 comments on commit 95ab6f4

Please sign in to comment.