def test_remove_link_to_dir(tmpdir): dst_link = join(text_type(tmpdir), "test_link") src_dir = join(text_type(tmpdir), "test_dir") tmpdir.mkdir("test_dir") os.symlink(src_dir, dst_link) assert isdir(src_dir) assert not islink(src_dir) assert islink(dst_link) assert rm_rf(dst_link) is True assert isdir(src_dir) # make sure the directory is still there assert not isdir(dst_link) assert not lexists(dst_link)
def test_remove_link_to_file(tmpdir): dst_link = join(text_type(tmpdir), "test_link") src_file = join(text_type(tmpdir), "test_file") _write_file(src_file, "welcome to the ministry of silly walks") os.symlink(src_file, dst_link) assert isfile(src_file) assert not islink(src_file) assert islink(dst_link) assert rm_rf(dst_link) is True assert isfile(src_file) # make sure the directory is still there assert not isfile(dst_link) assert not lexists(dst_link)
def test_clean_source_cache(self): cache_dirs = { 'source cache': text_type(context.src_cache), 'git cache': text_type(context.git_cache), 'hg cache': text_type(context.hg_cache), 'svn cache': text_type(context.svn_cache), } assert all(isdir(d) for d in itervalues(cache_dirs)) run_command(Commands.CLEAN, '', "--source-cache --yes") assert not all(isdir(d) for d in itervalues(cache_dirs))
def install(prefix, specs, args, env, prune=False): # TODO: support all various ways this happens # Including 'nodefaults' in the channels list disables the defaults new_specs = [] channel_urls = set() for elem in specs: if "::" in elem: channel_urls.add(elem.split("::")[0]) new_specs.append(elem.split("::")[-1]) else: new_specs.append(elem) specs = new_specs channel_urls = list(channel_urls) # TODO: support all various ways this happens # Including 'nodefaults' in the channels list disables the defaults channel_urls = channel_urls + [chan for chan in env.channels if chan != "nodefaults"] index = get_index(channel_urls=channel_urls, prepend="nodefaults" not in env.channels, prefix=prefix) _channel_priority_map = prioritize_channels(channel_urls) action_set = plan.install_actions_list( prefix, index, specs, prune=prune, channel_priority_map=_channel_priority_map ) with common.json_progress_bars(json=args.json and not args.quiet): for actions in action_set: try: plan.execute_actions(actions, index, verbose=not args.quiet) except RuntimeError as e: if len(e.args) > 0 and "LOCKERROR" in e.args[0]: raise LockError("Already locked: %s" % text_type(e)) else: raise CondaRuntimeError("RuntimeError: %s" % e) except SystemExit as e: raise CondaSystemExit("Exiting", e)
def test_prefix_record_no_channel(self): with env_unmodified(conda_tests_ctxt_mgmt_def_pol): pr = PrefixRecord( name='austin', version='1.2.3', build_string='py34_2', build_number=2, url="https://repo.anaconda.com/pkgs/main/win-32/austin-1.2.3-py34_2.tar.bz2", subdir="win-32", md5='0123456789', files=(), ) assert pr.url == "https://repo.anaconda.com/pkgs/main/win-32/austin-1.2.3-py34_2.tar.bz2" assert pr.channel.canonical_name == 'defaults' assert pr.subdir == "win-32" assert pr.fn == "austin-1.2.3-py34_2.tar.bz2" channel_str = text_type(Channel("https://repo.anaconda.com/pkgs/main/win-32/austin-1.2.3-py34_2.tar.bz2")) assert channel_str == "https://repo.anaconda.com/pkgs/main/win-32" assert dict(pr.dump()) == dict( name='austin', version='1.2.3', build='py34_2', build_number=2, url="https://repo.anaconda.com/pkgs/main/win-32/austin-1.2.3-py34_2.tar.bz2", md5='0123456789', files=(), channel=channel_str, subdir="win-32", fn="austin-1.2.3-py34_2.tar.bz2", constrains=(), depends=(), )
def test_channel_alias_w_conda_path(self): channel = Channel('bioconda') assert channel.channel_name == "bioconda" assert channel.channel_location == "10.2.3.4:8080/conda" assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.scheme == "https" assert channel.canonical_name == 'bioconda' assert channel.urls() == [ "https://10.2.3.4:8080/conda/bioconda/%s" % self.platform, "https://10.2.3.4:8080/conda/bioconda/noarch", ] assert channel.token == "tk-123-45" assert text_type(channel) == "https://10.2.3.4:8080/conda/bioconda" assert text_type(Channel('bioconda/linux-32')) == "https://10.2.3.4:8080/conda/bioconda/linux-32"
def test_remove_dir(tmpdir): test_dir = "test" tmpdir.mkdir(test_dir) path = join(text_type(tmpdir), test_dir) assert isdir(path) assert not islink(path) assert rm_rf(path) is True assert not isdir(path) assert not lexists(path)
def test_packages_not_found(self): with make_temp_env() as prefix: with pytest.raises(PackageNotFoundError) as exc: run_command(Commands.INSTALL, prefix, "not-a-real-package") assert "not-a-real-package" in text_type(exc.value) stdout, stderr = run_command(Commands.INSTALL, prefix, "not-a-real-package", use_exception_handler=True) assert "not-a-real-package" in stderr
def test_read_no_link(tmpdir): tempdir = text_type(tmpdir) no_link = join(tempdir, 'no_link') no_softlink = join(tempdir, 'no_softlink') _make_lines_file(no_link) s1 = read_no_link(tempdir) assert s1 == {'line 1', 'line 2', 'line 4'} _make_lines_file(no_softlink) s2 = read_no_link(tempdir) assert s2 == {'line 1', 'line 2', 'line 4'}
def test_default_channel(self): dc = Channel('defaults') assert dc.canonical_name == 'defaults' assert dc.urls() == self.DEFAULT_URLS assert dc.subdir is None assert text_type(dc) == 'defaults' dc = Channel('defaults/win-32') assert dc.canonical_name == 'defaults' assert dc.subdir == 'win-32' assert dc.urls()[0] == 'https://repo.anaconda.com/pkgs/main/win-32' assert dc.urls()[1] == 'https://repo.anaconda.com/pkgs/main/noarch' assert dc.urls()[2].endswith('/win-32')
def empty_env_tmpdir(self, tmpdir): # TODO :: Figure out if the pkgcache and a way to look for alternatives until one is found and add # a warning about it. ''' # Slightly fancier, "works on my computer", using the last 3 dirs is probably a pytest-ism? self.tmpdir = os.path.join('opt', 'conda.tmp', *(text_type(tmpdir).split(os.sep)[-3:])) try: try: rm_rf(self.tmpdir) except: pass os.makedirs(self.tmpdir) except: self.tmpdir = text_type(tmpdir) ''' self.tmpdir = text_type(tmpdir) return self.tmpdir
def test_prefix_record_no_channel(self): pr = PrefixRecord( name='austin', version='1.2.3', build_string='py34_2', build_number=2, url= "https://repo.continuum.io/pkgs/free/win-32/austin-1.2.3-py34_2.tar.bz2", subdir="win-32", md5='0123456789', files=(), ) assert pr.channel.canonical_name == 'defaults' assert pr.subdir == "win-32" assert pr.fn == "austin-1.2.3-py34_2.tar.bz2" channel_str = text_type( Channel( "https://repo.continuum.io/pkgs/free/win-32/austin-1.2.3-py34_2.tar.bz2" )) assert channel_str == "https://repo.continuum.io/pkgs/free" assert dict(pr.dump()) == dict( name='austin', version='1.2.3', build='py34_2', build_number=2, url= "https://repo.continuum.io/pkgs/free/win-32/austin-1.2.3-py34_2.tar.bz2", md5='0123456789', files=(), channel=channel_str, subdir="win-32", fn="austin-1.2.3-py34_2.tar.bz2", auth=None, constrains=(), depends=(), noarch=None, preferred_env=None, arch=None, platform=None, )
def install(prefix, specs, args, env, prune=False): # TODO: support all various ways this happens # Including 'nodefaults' in the channels list disables the defaults new_specs = [] channel_urls = set() for elem in specs: if "::" in elem: channel_urls.add(elem.split("::")[0]) new_specs.append(elem.split("::")[-1]) else: new_specs.append(elem) specs = new_specs channel_urls = list(channel_urls) # TODO: support all various ways this happens # Including 'nodefaults' in the channels list disables the defaults channel_urls = channel_urls + [ chan for chan in env.channels if chan != 'nodefaults' ] index = get_index(channel_urls=channel_urls, prepend='nodefaults' not in env.channels, prefix=prefix) _channel_priority_map = prioritize_channels(channel_urls) action_set = plan.install_actions_list( prefix, index, specs, prune=prune, channel_priority_map=_channel_priority_map) with common.json_progress_bars(json=args.json and not args.quiet): for actions in action_set: try: plan.execute_actions(actions, index, verbose=not args.quiet) except RuntimeError as e: if len(e.args) > 0 and "LOCKERROR" in e.args[0]: raise LockError('Already locked: %s' % text_type(e)) else: raise CondaHTTPError('CondaHTTPError: %s' % e) except SystemExit as e: raise CondaSystemExit('Exiting', e)
def test_parse_on_empty_env(self): with mock.patch.object(History, 'parse') as mock_parse: with History(make_temp_prefix(name=text_type(self.tmpdir))) as h: self.assertEqual(mock_parse.call_count, 0) self.assertEqual(len(h.parse()), 0) self.assertEqual(len(h.parse()), 1)
def test_yield_lines(tmpdir): tempfile = join(text_type(tmpdir), "testfile") _make_lines_file(tempfile) lines = list(yield_lines(tempfile)) assert lines == ['line 1', 'line 2', 'line 4']
def test_remove_file_to_trash(tmpdir): test_file = "test.txt" path = join(text_type(tmpdir), test_file) _write_file(path, "welcome to the ministry of silly walks") assert rm_rf(path) is True