Skip to content

Commit

Permalink
remove more dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
kalefranz committed Jun 17, 2016
1 parent 5188cae commit e700d04
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 157 deletions.
17 changes: 0 additions & 17 deletions conda/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,23 +354,6 @@ def clone_env(prefix1, prefix2, verbose=True, quiet=False, fetch_args=None):
return actions, untracked_files


def install_local_packages(prefix, paths, verbose=False):
explicit(paths, prefix, verbose=verbose)


def environment_for_conda_environment(prefix=root_dir):
# prepend the bin directory to the path
fmt = r'%s\Scripts' if sys.platform == 'win32' else '%s/bin'
binpath = fmt % abspath(prefix)
path = os.path.pathsep.join([binpath, os.getenv('PATH')])
env = {'PATH': path}
# copy existing environment variables, but not anything with PATH in it
for k, v in iteritems(os.environ):
if k != 'PATH':
env[k] = v
return binpath, env


def make_icon_url(info):
if 'channel' in info and 'icon' in info:
base_url = dirname(info['channel'])
Expand Down
29 changes: 0 additions & 29 deletions conda/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,6 @@ def gnu_get_libc_version():
return f()


def can_open(file):
"""
Return True if the given ``file`` can be opened for writing
"""
try:
fp = open(file, "ab")
fp.close()
return True
except IOError:
stderrlog.info("Unable to open %s\n" % file)
return False


def can_open_all(files):
"""
Return True if all of the provided ``files`` can be opened
"""
for f in files:
if not can_open(f):
return False
return True


def can_open_all_files_in_prefix(prefix, files):
"""
Returns True if all ``files`` at a given ``prefix`` can be opened
"""
return can_open_all((os.path.join(prefix, f) for f in files))

def try_write(dir_path):
if not isdir(dir_path):
return False
Expand Down
1 change: 0 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from conda.cli.common import arg2spec, spec_from_line
from conda.compat import text_type
import conda.config as config

from tests.helpers import capture_json_with_argv, assert_in

Expand Down
111 changes: 1 addition & 110 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,120 +1,11 @@
import random
import unittest

from .decorators import skip_if_no_mock
from .helpers import mock, assert_equals
from .helpers import assert_equals

from conda import utils

SOME_PREFIX = "/some/prefix"
SOME_FILES = ["a", "b", "c"]


def create_mock_open():
return mock.patch.object(utils, "open", create=True)


def create_mock_can_open():
can_open = mock.patch.object(utils, "can_open")
can_open.return_value = True
return can_open


class can_open_TestCase(unittest.TestCase):
@skip_if_no_mock
def test_returns_true_if_can_open(self):
with create_mock_open():
self.assertTrue(utils.can_open("/some/path/some/file"))

@skip_if_no_mock
def test_returns_false_if_unable_to_open(self):
with create_mock_open() as o:
o.side_effect = IOError
self.assertFalse(utils.can_open("/some/path/some/file"))

@skip_if_no_mock
def test_logs_file_to_debug_log(self):
random_file = "/some/path/to/a/file/%s" % random.randint(100, 200)
with create_mock_open() as o:
o.side_effect = IOError
with mock.patch.object(utils, "stderrlog") as log:
utils.can_open(random_file)
log.info.assert_called_with("Unable to open %s\n" % random_file)

@skip_if_no_mock
def test_closes_file_handler_if_successful(self):
with create_mock_open() as o:
utils.can_open("/some/file")
o.assert_has_calls([
mock.call("/some/file", "ab"),
mock.call().close(),
])


class can_open_all_TestCase(unittest.TestCase):
@skip_if_no_mock
def test_returns_true_if_all_files_are_openable(self):
with create_mock_can_open():
self.assertTrue(utils.can_open_all([
"/some/path/a",
"/some/path/b",
]))

@skip_if_no_mock
def test_returns_false_if_not_all_files_are_opened(self):
with create_mock_can_open() as can_open:
can_open.return_value = False
self.assertFalse(utils.can_open_all([
"/some/path/a",
"/some/path/b",
]))

@skip_if_no_mock
def test_only_call_can_open_as_many_times_as_needed(self):
with create_mock_can_open() as can_open:
can_open.side_effect = [True, False, True]
self.assertFalse(utils.can_open_all([
"/can/open",
"/cannot/open",
"/can/open",
]))
self.assertEqual(can_open.call_count, 2)


class can_open_all_files_in_prefix_TestCase(unittest.TestCase):
@skip_if_no_mock
def test_returns_true_on_success(self):
with create_mock_open():
self.assertTrue(utils.can_open_all_files_in_prefix(SOME_PREFIX, SOME_FILES))

@skip_if_no_mock
def test_returns_false_if_unable_to_open_file_for_writing(self):
with create_mock_open() as o:
o.side_effect = IOError
self.assertFalse(utils.can_open_all_files_in_prefix(SOME_PREFIX, SOME_FILES))

@skip_if_no_mock
def test_dispatches_to_can_can_call(self):
with mock.patch.object(utils, "can_open_all") as can_open_all:
utils.can_open_all_files_in_prefix(SOME_PREFIX, SOME_FILES)
self.assertTrue(can_open_all.called)

@skip_if_no_mock
def test_tries_to_open_all_files(self):
random_files = ['%s' % i for i in range(random.randint(10, 20))]
with create_mock_can_open():
utils.can_open_all_files_in_prefix(SOME_PREFIX, random_files)

@skip_if_no_mock
def test_stops_checking_as_soon_as_the_first_file_fails(self):
with create_mock_can_open() as can_open:
can_open.side_effect = [True, False, True]
self.assertFalse(
utils.can_open_all_files_in_prefix(SOME_PREFIX, SOME_FILES)
)
self.assertEqual(can_open.call_count, 2)


def test_path_translations():
paths = [
(r";z:\miniconda\Scripts\pip.exe",
Expand Down

0 comments on commit e700d04

Please sign in to comment.