Beispiel #1
0
def test_uninstallpathset_no_paths(mock_logger):
    """
    Test UninstallPathSet logs notification when there are no paths to uninstall

    """
    from pip.req import UninstallPathSet
    from pip.exceptions import InstallationError
    from pkg_resources import get_distribution

    test_dist = get_distribution("pip")
    uninstall_set = UninstallPathSet(test_dist)
    uninstall_set.remove()  # with no files added to set
    mock_logger.notify.assert_any_call("Can't uninstall 'pip'. No files were found to uninstall.")
Beispiel #2
0
def test_uninstallpathset_no_paths(mock_logger):
    """
    Test UninstallPathSet logs notification when there are no paths to uninstall

    """
    from pip.req import UninstallPathSet
    from pip.exceptions import InstallationError
    from pkg_resources import get_distribution
    test_dist = get_distribution('pip')
    uninstall_set = UninstallPathSet(test_dist)
    uninstall_set.remove()  #with no files added to set
    mock_logger.notify.assert_any_call(
        "Can't uninstall 'pip'. No files were found to uninstall.")
Beispiel #3
0
def test_uninstallpathset_no_paths(mock_logger):
    """
    Test UninstallPathSet logs notification when there are no paths to uninstall

    """
    from pip.req import UninstallPathSet
    from pkg_resources import get_distribution
    test_dist = get_distribution('pip')
    # ensure that the distribution is "local"
    with patch("pip.req.dist_is_local") as mock_dist_is_local:
        mock_dist_is_local.return_value = True
        uninstall_set = UninstallPathSet(test_dist)
        uninstall_set.remove() #with no files added to set
    mock_logger.notify.assert_any_call("Can't uninstall 'pip'. No files were found to uninstall.")
Beispiel #4
0
def test_uninstallpathset_non_local(mock_logger):
    """
    Test UninstallPathSet logs notification and returns (with no exception) when dist is non-local

    """
    from pip.req import UninstallPathSet
    from pip.exceptions import InstallationError
    from pkg_resources import get_distribution

    test_dist = get_distribution("pip")
    test_dist.location = "/NON_LOCAL"
    uninstall_set = UninstallPathSet(test_dist)
    uninstall_set.remove()  # with no files added to set; which is the case when trying to remove non-local dists
    mock_logger.notify.assert_any_call("Not uninstalling pip at /NON_LOCAL, outside environment %s" % sys.prefix)
Beispiel #5
0
def test_uninstallpathset_no_paths(mock_logger):
    """
    Test UninstallPathSet logs notification when there are no paths to uninstall

    """
    from pip.req import UninstallPathSet
    from pkg_resources import get_distribution
    test_dist = get_distribution('pip')
    # ensure that the distribution is "local"
    with patch("pip.req.dist_is_local") as mock_dist_is_local:
        mock_dist_is_local.return_value = True
        uninstall_set = UninstallPathSet(test_dist)
        uninstall_set.remove()  #with no files added to set
    mock_logger.notify.assert_any_call(
        "Can't uninstall 'pip'. No files were found to uninstall.")
Beispiel #6
0
def test_uninstallpathset_non_local(mock_logger):
    """
    Test UninstallPathSet logs notification and returns (with no exception) when dist is non-local

    """
    from pip.req import UninstallPathSet
    from pip.exceptions import InstallationError
    from pkg_resources import get_distribution
    test_dist = get_distribution('pip')
    test_dist.location = '/NON_LOCAL'
    uninstall_set = UninstallPathSet(test_dist)
    uninstall_set.remove(
    )  #with no files added to set; which is the case when trying to remove non-local dists
    mock_logger.notify.assert_any_call(
        "Not uninstalling pip at /NON_LOCAL, outside environment %s" %
        sys.prefix)
Beispiel #7
0
def test_uninstallpathset_non_local(mock_logger):
    """
    Test UninstallPathSet logs notification and returns (with no exception) when dist is non-local

    """
    nonlocal_path = os.path.abspath("/nonlocal")
    from pip.req import UninstallPathSet
    from pkg_resources import get_distribution
    test_dist = get_distribution('pip')
    test_dist.location = nonlocal_path
    # ensure that the distribution is "non-local"
    # setting location isn't enough, due to egg-link file checking for
    # develop-installs
    with patch("pip.req.dist_is_local") as mock_dist_is_local:
        mock_dist_is_local.return_value = False
        uninstall_set = UninstallPathSet(test_dist)
        uninstall_set.remove() #with no files added to set; which is the case when trying to remove non-local dists
    mock_logger.notify.assert_any_call("Not uninstalling pip at %s, outside environment %s" % (nonlocal_path, sys.prefix)), mock_logger.notify.mock_calls
Beispiel #8
0
def test_uninstallpathset_no_paths():
    """
    Test UninstallPathSet raises installation error when there are no paths (uses mocking)

    """
    from pip.req import UninstallPathSet
    from pip.exceptions import InstallationError
    mock_dist = Mock(project_name='pkg')
    uninstall_set = UninstallPathSet(mock_dist)
    assert_raises(InstallationError, uninstall_set.remove)
Beispiel #9
0
def test_uninstallpathset_non_local(mock_logger):
    """
    Test UninstallPathSet logs notification and returns (with no exception) when dist is non-local

    """
    nonlocal_path = os.path.abspath("/nonlocal")
    from pip.req import UninstallPathSet
    from pkg_resources import get_distribution
    test_dist = get_distribution('pip')
    test_dist.location = nonlocal_path
    # ensure that the distribution is "non-local"
    # setting location isn't enough, due to egg-link file checking for
    # develop-installs
    with patch("pip.req.dist_is_local") as mock_dist_is_local:
        mock_dist_is_local.return_value = False
        uninstall_set = UninstallPathSet(test_dist)
        uninstall_set.remove(
        )  #with no files added to set; which is the case when trying to remove non-local dists
    mock_logger.notify.assert_any_call(
        "Not uninstalling pip at %s, outside environment %s" %
        (nonlocal_path, sys.prefix)), mock_logger.notify.mock_calls