Esempio n. 1
0
    def test_find_conflicts_called_once(self):
        bad_deps = {
            'python':
            {((MatchSpec("statistics"),
               MatchSpec("python[version='>=2.7,<2.8.0a0']")), 'python=3')}
        }

        with patch('conda.resolve.Resolve.find_conflicts') as monkey:
            monkey.side_effect = UnsatisfiableError(bad_deps, strict=True)
            with self.assertRaises(UnsatisfiableError):
                # Statistics is a py27 only package allowing us a simple unsatisfiable case
                stdout, stderr, _ = run_command(Commands.INSTALL, self.prefix,
                                                'statistics')
            self.assertEqual(monkey.call_count, 1)
            monkey.reset_mock()
            with self.assertRaises(UnsatisfiableError):
                stdout, stderr, _ = run_command(Commands.INSTALL, self.prefix,
                                                'statistics',
                                                '--freeze-installed')
            self.assertEqual(monkey.call_count, 1)
            monkey.reset_mock()
            with self.assertRaises(UnsatisfiableError):
                stdout, stderr, _ = run_command(Commands.CREATE, self.testenv,
                                                'statistics', 'python=3.7')
            self.assertEqual(monkey.call_count, 1)
Esempio n. 2
0
def test_clean_and_packages(clear_cache):
    pkg = "bzip2"

    with make_temp_package_cache() as pkgs_dir:
        # pkg doesn't exist ahead of time
        assert_not_pkg(pkg, _get_pkgs(pkgs_dir))

        with make_temp_env(pkg) as prefix:
            # pkg exists
            assert_any_pkg(pkg, _get_pkgs(pkgs_dir))

            # --json flag is regression test for #5451
            stdout, _, _ = run_command(Commands.CLEAN, "", "--packages",
                                       "--yes", "--json")
            json_loads(stdout)  # assert valid json

            # pkg still exists since its in use by temp env
            assert_any_pkg(pkg, _get_pkgs(pkgs_dir))

            run_command(Commands.REMOVE, prefix, pkg, "--yes", "--json")
            stdout, _, _ = run_command(Commands.CLEAN, "", "--packages",
                                       "--yes", "--json")
            json_loads(stdout)  # assert valid json

            # pkg is removed
            assert_not_pkg(pkg, _get_pkgs(pkgs_dir))

        # pkg is still removed
        assert_not_pkg(pkg, _get_pkgs(pkgs_dir))
Esempio n. 3
0
def prefix(tmpdir):
    prefix = tmpdir.mkdir("cli_install_prefix")
    test_env = tmpdir.mkdir("cli_install_test_env")
    run_command(Commands.CREATE, str(prefix), 'python=3.7')
    yield str(prefix), str(test_env)
    rm_rf(prefix)
    rm_rf(test_env)
Esempio n. 4
0
def test_clean_all(clear_cache):
    pkg = "bzip2"

    with make_temp_package_cache() as pkgs_dir:
        # pkg, tarball, & index cache doesn't exist ahead of time
        pkgs, tars, cache = _get_all(pkgs_dir)
        assert_not_pkg(pkg, pkgs)
        assert_not_pkg(pkg, tars)
        assert not cache

        with make_temp_env(pkg) as prefix:
            # pkg, tarball, & index cache exists
            pkgs, tars, cache = _get_all(pkgs_dir)
            assert_any_pkg(pkg, pkgs)
            assert_any_pkg(pkg, tars)
            assert cache

            stdout, _, _ = run_command(Commands.CLEAN, "", "--all", "--yes",
                                       "--json")
            json_loads(stdout)  # assert valid json

            # pkg still exists since its in use by temp env
            # tarball is removed
            # index cache is cleared
            pkgs, tars, cache = _get_all(pkgs_dir)
            assert_any_pkg(pkg, pkgs)
            assert_not_pkg(pkg, tars)
            assert not cache

            run_command(Commands.REMOVE, prefix, pkg, "--yes", "--json")
            stdout, _, _ = run_command(Commands.CLEAN, "", "--packages",
                                       "--yes", "--json")
            json_loads(stdout)  # assert valid json

            # pkg is removed
            # tarball is still removed
            # index cache is still cleared
            pkgs, tars, index_cache = _get_all(pkgs_dir)
            assert_not_pkg(pkg, pkgs)
            assert_not_pkg(pkg, tars)
            assert not cache

        # pkg is still removed
        # tarball is still removed
        # index cache is still cleared
        pkgs, tars, index_cache = _get_all(pkgs_dir)
        assert_not_pkg(pkg, pkgs)
        assert_not_pkg(pkg, tars)
        assert not cache
Esempio n. 5
0
def test_clean_logfiles(clear_cache):
    """Logfiles are found in pkgs_dir/.logs.

    Since these log files are uniquely implemented for the experimental libmamba release we will
    mock the log files.
    """
    pkg = "bzip2"

    with make_temp_package_cache() as pkgs_dir:
        # logfiles don't exist ahead of time
        assert not _get_logfiles(pkgs_dir)

        with make_temp_env(pkg):
            # mimic logfiles being created
            logs = join(pkgs_dir, CONDA_LOGS_DIR)
            mkdir_p(logs)
            path = join(logs, f"{datetime.utcnow():%Y%m%d-%H%M%S-%f}.log")
            with open(path, "w"):
                pass

            # logfiles exist
            assert path in _get_logfiles(pkgs_dir)

            # --json flag is regression test for #5451
            stdout, _, _ = run_command(Commands.CLEAN, "", "--logfiles",
                                       "--yes", "--json")
            json_loads(stdout)  # assert valid json

            # logfiles removed
            assert not _get_logfiles(pkgs_dir)

        # logfiles still removed
        assert not _get_logfiles(pkgs_dir)
Esempio n. 6
0
    def test_search_2(self):
        with make_temp_env() as prefix:
            stdout, stderr, _ = run_command(Commands.SEARCH,
                                            prefix,
                                            "nose",
                                            use_exception_handler=True)
            result = stdout.replace("Loading channels: ...working... done", "")

            assert "nose                           1.3.7          py37_2  pkgs/main" in result
Esempio n. 7
0
    def test_basic(self):
        with make_temp_env("python=3.5") as prefix:
            assert exists(join(prefix, PYTHON_BINARY))
            assert package_is_installed(prefix, 'python=3')

            output, error, _ = run_command(Commands.LIST, prefix, "-e")

            with Utf8NamedTemporaryFile(mode="w", suffix="txt",
                                        delete=False) as env_txt:
                env_txt.write(output)
                env_txt.flush()
                env_txt.close()
                prefix2 = make_temp_prefix()
                run_command(Commands.CREATE, prefix2, "--file", env_txt.name)

                assert package_is_installed(prefix2, "python")

            output2, error, _ = run_command(Commands.LIST, prefix2, "-e")
            self.assertEqual(output, output2)
Esempio n. 8
0
    def test_channel_order_channel_priority_true(self):
        # This is broken, make_temp_env will reset the context. We get away with it, but really
        # we need a function that does both these at the same time.
        with env_var("CONDA_PINNED_PACKAGES",
                     "python=3.6",
                     stack_callback=conda_tests_ctxt_mgmt_def_pol):
            with make_temp_env("pycosat==0.6.2") as prefix:
                assert package_is_installed(prefix, 'python=3.6')
                assert package_is_installed(prefix, 'pycosat')

                # add conda-forge channel
                o, e, _ = run_command(Commands.CONFIG, prefix, "--prepend",
                                      "channels", "conda-forge", '--json')
                assert context.channels == ("conda-forge", "defaults"), o + e
                # update --all
                update_stdout, _, _ = run_command(Commands.UPDATE, prefix,
                                                  '--all')

                # this assertion works with the pinned_packages config to make sure
                # conda update --all still respects the pinned python version
                assert package_is_installed(prefix, 'python=3.6')

                # pycosat should be in the SUPERSEDED list
                # after the 4.4 solver work, looks like it's in the DOWNGRADED list
                # This language needs changed anyway here.
                # For packages that CHANGE because they're being moved to a higher-priority channel
                # the message should be
                #
                # The following packages will be UPDATED to a higher-priority channel:
                #
                installed_str, x = update_stdout.split('UPDATED')
                assert re.search(
                    r'pkgs/main::pycosat-0.6.2-py36h[^\s]+ --> conda-forge::pycosat',
                    x)

                # python sys.version should show conda-forge python
                python_tuple = get_conda_list_tuple(prefix, "python")
                assert python_tuple[3] == 'conda-forge'
                # conda list should show pycosat coming from conda-forge
                pycosat_tuple = get_conda_list_tuple(prefix, "pycosat")
                assert pycosat_tuple[3] == 'conda-forge'
Esempio n. 9
0
    def test_multi_channel_export(self):
        """
            When try to import from txt
            every package should come from same channel
        """
        with make_temp_env("python=3.5") as prefix:
            assert exists(join(prefix, PYTHON_BINARY))
            assert package_is_installed(prefix, 'python=3')

            run_command(Commands.INSTALL, prefix, "six", "-c", "conda-forge")
            assert package_is_installed(prefix, "six")

            output, error, _ = run_command(Commands.LIST, prefix, "-e")
            self.assertIn("conda-forge", output)

            try:
                with Utf8NamedTemporaryFile(mode="w",
                                            suffix="txt",
                                            delete=False) as env_txt:
                    env_txt.write(output)
                    env_txt.close()
                    prefix2 = make_temp_prefix()
                    run_command(Commands.CREATE, prefix2, "--file",
                                env_txt.name)

                    assert package_is_installed(prefix2, "python")
                output2, error, _ = run_command(Commands.LIST, prefix2, "-e")
                self.assertEqual(output, output2)
            finally:
                rm_rf(env_txt.name)
Esempio n. 10
0
def test_find_conflicts_called_once(prefix):
    prefix, test_env = prefix
    bad_deps = {
        'python':
        {((MatchSpec("statistics"),
           MatchSpec("python[version='>=2.7,<2.8.0a0']")), 'python=3')}
    }

    with patch(
            "conda.resolve.Resolve.find_conflicts",
            side_effect=UnsatisfiableError(bad_deps, strict=True),
    ) as mocked_find_conflicts:
        with pytest.raises(UnsatisfiableError):
            # Statistics is a py27 only package allowing us a simple unsatisfiable case
            run_command(Commands.INSTALL, prefix, "statistics")
        assert mocked_find_conflicts.call_count == 1

        mocked_find_conflicts.reset_mock()
        with pytest.raises(UnsatisfiableError):
            run_command(Commands.INSTALL, prefix, "statistics",
                        "--freeze-installed")
        assert mocked_find_conflicts.call_count == 1

        mocked_find_conflicts.reset_mock()
        with pytest.raises(UnsatisfiableError):
            run_command(Commands.CREATE, test_env, "statistics", "python=3.7")
        assert mocked_find_conflicts.call_count == 1
Esempio n. 11
0
 def test_search_3(self):
     with make_temp_env() as prefix:
         stdout, stderr, _ = run_command(
             Commands.SEARCH,
             prefix,
             "*/linux-64::nose==1.3.7[build=py37_2]",
             "--info",
             use_exception_handler=True,
         )
         result = stdout.replace("Loading channels: ...working... done", "")
         assert "file name   : nose-1.3.7-py37_2" in result
         assert "name        : nose" in result
         assert (
             "url         : https://repo.anaconda.com/pkgs/main/linux-64/nose-1.3.7-py37_2"
             in result)
Esempio n. 12
0
    def test_channel_priority_update(self):
        """
            This case will fail now
        """
        with make_temp_env("python=3.6.5", "pycosat") as prefix:
            assert package_is_installed(prefix, 'python')

            # add conda-forge channel
            o, e, _ = run_command(Commands.CONFIG, prefix, "--prepend",
                                  "channels", "conda-forge", '--json')
            assert context.channels == ("conda-forge", "defaults"), o + e

            # update python
            update_stdout, _, _ = run_command(Commands.UPDATE, prefix,
                                              'python')

            # pycosat should be in the SUPERSEDED list
            superceded_split = update_stdout.split('UPDATED')
            assert len(superceded_split) == 2
            assert 'conda-forge' in superceded_split[1]

            # python sys.version should show conda-forge python
            python_tuple = get_conda_list_tuple(prefix, "python")
            assert python_tuple[3] == 'conda-forge'
Esempio n. 13
0
def test_clean_force_pkgs_dirs(clear_cache):
    pkg = "bzip2"

    with make_temp_package_cache() as pkgs_dir:
        # pkgs_dir is a directory
        assert isdir(pkgs_dir)

        with make_temp_env(pkg):
            stdout, _, _ = run_command(Commands.CLEAN, "", "--force-pkgs-dirs",
                                       "--yes", "--json")
            json_loads(stdout)  # assert valid json

            # pkgs_dir is removed
            assert not exists(pkgs_dir)

        # pkgs_dir is still removed
        assert not exists(pkgs_dir)
Esempio n. 14
0
def test_clean_index_cache(clear_cache):
    pkg = "bzip2"

    with make_temp_package_cache():
        # index cache doesn't exist ahead of time
        assert not _get_index_cache()

        with make_temp_env(pkg):
            # index cache exists
            assert _get_index_cache()

            stdout, _, _ = run_command(Commands.CLEAN, "", "--index-cache",
                                       "--yes", "--json")
            json_loads(stdout)  # assert valid json

            # index cache is cleared
            assert not _get_index_cache()

        # index cache is still cleared
        assert not _get_index_cache()
Esempio n. 15
0
def test_clean_tarballs(clear_cache):
    pkg = "bzip2"

    with make_temp_package_cache() as pkgs_dir:
        # tarball doesn't exist ahead of time
        assert_not_pkg(pkg, _get_tars(pkgs_dir))

        with make_temp_env(pkg):
            # tarball exists
            assert_any_pkg(pkg, _get_tars(pkgs_dir))

            # --json flag is regression test for #5451
            stdout, _, _ = run_command(Commands.CLEAN, "", "--tarballs",
                                       "--yes", "--json")
            json_loads(stdout)  # assert valid json

            # tarball is removed
            assert_not_pkg(pkg, _get_tars(pkgs_dir))

        # tarball is still removed
        assert_not_pkg(pkg, _get_tars(pkgs_dir))
Esempio n. 16
0
def test_clean_tempfiles(clear_cache):
    """Tempfiles are either suffixed with .c~ or .trash.

    .c~ is used to indicate that conda is actively using that file. If the conda process is
    terminated unexpectedly these .c~ files may remain and hence can be cleaned up after the fact.

    .trash appears to be a legacy suffix that is no longer used by conda.

    Since the presence of .c~ and .trash files are dependent upon irregular termination we create
    our own temporary files to confirm they get cleaned up.
    """
    pkg = "bzip2"

    with make_temp_package_cache() as pkgs_dir:
        # tempfiles don't exist ahead of time
        assert not _get_tempfiles(pkgs_dir)

        with make_temp_env(pkg):
            # mimic tempfiles being created
            path = _get_tars(pkgs_dir)[0]  # grab any tarball
            for ext in CONDA_TEMP_EXTENSIONS:
                copy(path, f"{path}{ext}")

            # tempfiles exist
            assert len(_get_tempfiles(pkgs_dir)) == len(CONDA_TEMP_EXTENSIONS)

            # --json flag is regression test for #5451
            stdout, _, _ = run_command(Commands.CLEAN, "", "--tempfiles",
                                       pkgs_dir, "--yes", "--json")
            json_loads(stdout)  # assert valid json

            # tempfiles removed
            assert not _get_tempfiles(pkgs_dir)

        # tempfiles still removed
        assert not _get_tempfiles(pkgs_dir)
Esempio n. 17
0
    def test_multi_channel_explicit(self):
        """
            When try to import from txt
            every package should come from same channel
        """
        with make_temp_env("python=3.5") as prefix:
            assert exists(join(prefix, PYTHON_BINARY))
            assert package_is_installed(prefix, 'python=3')

            run_command(Commands.INSTALL, prefix, "six", "-c", "conda-forge")
            assert package_is_installed(prefix, "conda-forge::six")

            output, error, _ = run_command(Commands.LIST, prefix, "--explicit")
            assert not error
            assert "conda-forge" in output

            urls1 = set(url for url in output.split()
                        if url.startswith("http"))

            try:
                with Utf8NamedTemporaryFile(mode="w",
                                            suffix="txt",
                                            delete=False) as env_txt:
                    env_txt.write(output)
                    env_txt.close()
                    prefix2 = make_temp_prefix()
                    run_command(Commands.CREATE, prefix2, "--file",
                                env_txt.name)

                    assert package_is_installed(prefix2, "python")
                    assert package_is_installed(prefix2, "six")
                output2, error2, _ = run_command(Commands.LIST, prefix2,
                                                 "--explicit")
                assert not error2
                urls2 = set(url for url in output2.split()
                            if url.startswith("http"))
                assert urls1 == urls2
            finally:
                rm_rf(env_txt.name)
Esempio n. 18
0
 def test_link_order_post_link_depend(self):
     stdout, stderr, _ = run_command(Commands.CREATE, self.prefix, "e_post_link_package", "-c", "conda-test")
     assert(stderr == '')
Esempio n. 19
0
 def setUp(self):
     self.prefix = tempfile.mkdtemp()
     self.testenv = tempfile.mkdtemp()
     run_command(Commands.CREATE, self.prefix, 'python=3.7')
Esempio n. 20
0
def test_pre_link_message(prefix, pre_link_messages_package):
    prefix, _ = prefix
    with patch("conda.cli.common.confirm_yn", return_value=True):
        stdout, _, _ = run_command(Commands.INSTALL, prefix,
                                   pre_link_messages_package, "--use-local")
        assert "Lorem ipsum dolor sit amet" in stdout