Skip to content

Commit

Permalink
Add code that adds ENSURE_WRITE on Windows whenever calling UNLINK
Browse files Browse the repository at this point in the history
  • Loading branch information
tswicegood committed Apr 21, 2015
1 parent 331640c commit 7cdca3d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
4 changes: 4 additions & 0 deletions conda/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ def nothing_to_do(actions):
def add_unlink(actions, dist):
if inst.UNLINK not in actions:
actions[inst.UNLINK] = []
if sys.platform == "win32":
if inst.ENSURE_WRITE not in actions:
actions[inst.ENSURE_WRITE] = []
actions[inst.ENSURE_WRITE].append(dist)
actions[inst.UNLINK].append(dist)


Expand Down
41 changes: 35 additions & 6 deletions tests/test_plan.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from contextlib import contextmanager
import sys
import json
import random
Expand Down Expand Up @@ -52,23 +53,51 @@ def test_add_unlink_takes_two_arguments(args):


class add_unlink_TestCase(unittest.TestCase):
def generate_random_dist(self):
return {
"name": "foobar%s" % random.randint(100, 200),
"files": ["a", "b", "c"]
}

@contextmanager
def mock_platform(self, windows=False):
with mock.patch.object(plan, "sys") as sys:
sys.platform = "win32" if windows else "not win32"
yield sys

def test_simply_adds_unlink_on_non_windows(self):
actions = {}
dist = {"foo": "bar%s" % random.randint(100, 200)}
with mock.patch.object(plan, "sys") as sys:
sys.platform = "not win32"
dist = self.generate_random_dist()
with self.mock_platform(windows=False):
plan.add_unlink(actions, dist)
self.assertIn(inst.UNLINK, actions)
self.assertEqual(actions[inst.UNLINK], [dist, ])

def test_adds_to_existing_actions(self):
actions = {inst.UNLINK: [{"foo": "bar"}]}
dist = {"foo": "bar%s" % random.randint(100, 200)}
with mock.patch.object(plan, "sys") as sys:
sys.platform = "not win32"
dist = self.generate_random_dist()
with self.mock_platform(windows=False):
plan.add_unlink(actions, dist)
self.assertEqual(2, len(actions[inst.UNLINK]))

def test_adds_ensure_write_on_windows(self):
actions = {}
dist = self.generate_random_dist()
with self.mock_platform(windows=True):
plan.add_unlink(actions, dist)
self.assertIn(inst.ENSURE_WRITE, actions)
self.assertEqual(actions[inst.ENSURE_WRITE], [dist, ])

def test_adds_to_existing_actions(self):
actions = {
inst.UNLINK: [{"foo": "bar"}],
inst.ENSURE_WRITE: [{"foo": "bar"}],
}
dist = self.generate_random_dist()
with self.mock_platform(windows=True):
plan.add_unlink(actions, dist)
self.assertEqual(actions[inst.ENSURE_WRITE], [{"foo": "bar"}, dist])


class TestAddDeaultsToSpec(unittest.TestCase):
# tests for plan.add_defaults_to_specs(r, linked, specs)
Expand Down

0 comments on commit 7cdca3d

Please sign in to comment.