<commit_before>
import textwrap
from os.path import join
from tempfile import mkdtemp
from test_pip import here, reset_env, run_pip, pyversion, lib_py, get_env, diff_states, write_file

site_pkg = join(lib_py, 'site-packages')
easy_install_pth = join(site_pkg, 'easy-install.pth')

def test_simple_uninstall():
    """
    Test simple install and uninstall.
    
    """
    reset_env()
    result = run_pip('install', 'INITools==0.2', expect_error=True)
    assert join(site_pkg, 'initools') in result.files_created, sorted(result.files_created.keys())
    result2 = run_pip('uninstall', 'INITools', '-y', expect_error=True)
    diff = diff_states(result.files_before, result2.files_after, ignore=['build']).values()
    assert diff == [{}, {}, {}], diff

def test_uninstall_with_scripts():
    """
    Uninstall an easy_installed package with scripts.
    
    """
    reset_env()
    env = get_env()
    result = env.run(join(env.bin_dir, 'easy_install'), 'PyLogo')
    assert('PyLogo' in result.files_updated[easy_install_pth].bytes), result.files_after[easy_install_pth].bytes
    result2 = run_pip('uninstall', 'pylogo', '-y', expect_error=True)
    diff = diff_states(result.files_before, result2.files_after, ignore=['build']).values()
    assert diff == [{}, {}, {}], diff


def test_uninstall_namespace_package():
    """
    Uninstall a distribution with a namespace package without clobbering
    the namespace and everything in it.
    
    """
    reset_env()
    result = run_pip('install', 'pd.requires==0.0.3', expect_error=True)
    assert join(site_pkg, 'pd') in result.files_created, sorted(result.files_created.keys())
    result2 = run_pip('uninstall', 'pd.find', '-y', expect_error=True)
    assert join(site_pkg, 'pd') not in result2.files_deleted, sorted(result2.files_deleted.keys())
    assert join(site_pkg, 'pd', 'find') in result2.files_deleted, sorted(result2.files_deleted.keys())

def test_uninstall_console_scripts():
    """
    Test uninstalling a package with more files (console_script entry points, extra directories).
    
    """
    reset_env()
    result = run_pip('install', 'virtualenv', expect_error=True)
    assert ('bin/virtualenv') in result.files_created, sorted(result.files_created.keys())
    result2 = run_pip('uninstall', 'virtualenv', '-y', expect_error=True)
    diff = diff_states(result.files_before, result2.files_after, ignore=['build']).values()
    assert diff == [{}, {}, {}], diff


def test_uninstall_easy_installed_console_scripts():
    """
    Test uninstalling package with console_scripts that is easy_installed.
    
    """
    reset_env()
    env = get_env()
    result = env.run(join(env.bin_dir, 'easy_install'), 'virtualenv')
    assert ('bin/virtualenv') in result.files_created, sorted(result.files_created.keys())
    result2 = run_pip('uninstall', 'virtualenv', '-y', expect_error=True)
    diff = diff_states(result.files_before, result2.files_after, ignore=['build']).values()
    assert diff == [{}, {}, {}], diff


def test_uninstall_editable_from_svn():
    """
    Test uninstalling an editable installation from svn.
    
    """
    reset_env()
    result = run_pip('install', '-e', 'svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev', expect_error=True)
    egg_link = result.files_created[join(site_pkg, 'INITools.egg-link')]
    result2 = run_pip('uninstall', '-y', 'initools', expect_error=True)
    assert ('src/initools' in result2.files_after), 'oh noes, pip deleted my sources!'
    diff = diff_states(result.files_before, result2.files_after, ignore=['build', 'src']).values()
    assert diff == [{}, {}, {}], diff

    
def test_uninstall_editable_with_source_outside_venv():
    """
    Test uninstalling editable install from existing source outside the venv.
    
    """
    tmpdir = join(mkdtemp(), 'virtualenv')
    reset_env()
    env = get_env()
    result = env.run('hg', 'clone', 'http://bitbucket.org/ianb/virtualenv/', tmpdir)
    result2 = run_pip('install', '-e', tmpdir)
    assert (join(site_pkg, 'virtualenv.egg-link') in result2.files_created), result2.files_created.keys()
    result3 = run_pip('uninstall', '-y', 'virtualenv', expect_error=True)
    diff = diff_states(result.files_before, result3.files_after, ignore=['build']).values()
    assert diff == [{}, {}, {}], diff

    
def test_uninstall_from_reqs_file():
    """
    Test uninstall from a requirements file.
    
    """
    reset_env()
    write_file('test-req.txt', textwrap.dedent("""\
        -e svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev
        # and something else to test out:
        PyLogo<0.4
        """))
    result = run_pip('install', '-r', 'test-req.txt')
    write_file('test-req.txt', textwrap.dedent("""\
        # -f, -i, and --extra-index-url should all be ignored by uninstall
        -f http://www.example.com
        -i http://www.example.com
        --extra-index-url http://www.example.com
        
        -e svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev
        # and something else to test out:
        PyLogo<0.4
        """))
    result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y')
    diff = diff_states(result.files_before, result2.files_after, ignore=['build', 'src', 'test-req.txt']).values()
    assert diff == [{}, {}, {}], diff

<commit_msg>6/8 tests pass, still two failures<commit_after>
import textwrap
from os.path import join
from tempfile import mkdtemp
from test_pip import here, reset_env, run_pip, get_env, diff_states, write_file

#site_pkg = join(lib_py, 'site-packages')
#easy_install_pth = join(site_pkg, 'easy-install.pth')

def test_simple_uninstall():
    """
    Test simple install and uninstall.
    
    """
    env = reset_env()
    result = run_pip('install', 'INITools==0.2', expect_error=True)
    assert join(env.site_packages, 'initools') in result.files_created, sorted(result.files_created.keys())
    result2 = run_pip('uninstall', 'INITools', '-y', expect_error=True)
    assert diff_states(result.files_before, result2.files_after, ignore=[env.relative_env_path/'build', 'cache']).values() == [{}, {}, {}]

def test_uninstall_with_scripts():
    """
    Uninstall an easy_installed package with scripts.
    
    """
    env = reset_env()
    result = env.run('easy_install', 'PyLogo')
    easy_install_pth = env.site_packages/ 'easy-install.pth'
    assert('PyLogo' in result.files_updated[easy_install_pth].bytes), result.files_after[easy_install_pth].bytes
    result2 = run_pip('uninstall', 'pylogo', '-y', expect_error=True)
    assert diff_states(result.files_before, result2.files_after, ignore=[env.relative_env_path/'build', 'cache']).values() == [{}, {}, {}]

def test_uninstall_namespace_package():
    """
    Uninstall a distribution with a namespace package without clobbering
    the namespace and everything in it.
    
    """
    env = reset_env()
    result = run_pip('install', 'pd.requires==0.0.3', expect_error=True)
    assert join(env.site_packages, 'pd') in result.files_created, sorted(result.files_created.keys())
    result2 = run_pip('uninstall', 'pd.find', '-y', expect_error=True)
    assert join(env.site_packages, 'pd') not in result2.files_deleted, sorted(result2.files_deleted.keys())
    assert join(env.site_packages, 'pd', 'find') in result2.files_deleted, sorted(result2.files_deleted.keys())

def test_uninstall_console_scripts():
    """
    Test uninstalling a package with more files (console_script entry points, extra directories).
    
    """
    env = reset_env()
    result = run_pip('install', 'virtualenv', expect_error=True)
    assert (env.bin_dir/'virtualenv') in result.files_created, sorted(result.files_created.keys())
    result2 = run_pip('uninstall', 'virtualenv', '-y', expect_error=True)
    assert diff_states(result.files_before, result2.files_after, ignore=[env.relative_env_path/'build', 'cache']).values() == [{}, {}, {}]

def test_uninstall_easy_installed_console_scripts():
    """
    Test uninstalling package with console_scripts that is easy_installed.
    
    """
    env = reset_env()
    result = env.run('easy_install', 'virtualenv')
    assert (env.bin_dir/'virtualenv') in result.files_created, sorted(result.files_created.keys())
    result2 = run_pip('uninstall', 'virtualenv', '-y', expect_error=True)
    assert diff_states(result.files_before, result2.files_after, ignore=[env.relative_env_path/'build', 'cache']).values() == [{}, {}, {}]

def test_uninstall_editable_from_svn():
    """
    Test uninstalling an editable installation from svn.
    
    """
    env = reset_env()
    result = run_pip('install', '-e', 'svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev', expect_error=True)
    egg_link = result.files_created[env.site_packages/ 'INITools.egg-link']
    result2 = run_pip('uninstall', '-y', 'initools', expect_error=True)
    assert (env.relative_env_path/'src'/'initools' in result2.files_after), 'oh noes, pip deleted my sources!'
    assert diff_states(result.files_before, result2.files_after, ignore=[env.relative_env_path/'src'/'initools', env.relative_env_path/'build']).values() == [{}, {}, {}]

    
def test_uninstall_editable_with_source_outside_venv():
    """
    Test uninstalling editable install from existing source outside the venv.
    
    """
    tmpdir = join(mkdtemp(), 'virtualenv')
    env = reset_env()
    result = env.run('hg', 'clone', 'http://bitbucket.org/ianb/virtualenv/', tmpdir)
    result2 = run_pip('install', '-e', tmpdir)
    assert (join(env.site_packages, 'virtualenv.egg-link') in result2.files_created), result2.files_created.keys()
    result3 = run_pip('uninstall', '-y', 'virtualenv', expect_error=True)
    assert diff_states(result.files_before, result3.files_after, ignore=[env.relative_env_path/'build']).values() == [{}, {}, {}]

    
def test_uninstall_from_reqs_file():
    """
    Test uninstall from a requirements file.
    
    """
    env = reset_env()
    write_file('test-req.txt', textwrap.dedent("""\
        -e svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev
        # and something else to test out:
        PyLogo<0.4
        """))
    result = run_pip('install', '-r', 'test-req.txt')
    write_file('test-req.txt', textwrap.dedent("""\
        # -f, -i, and --extra-index-url should all be ignored by uninstall
        -f http://www.example.com
        -i http://www.example.com
        --extra-index-url http://www.example.com
        
        -e svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev
        # and something else to test out:
        PyLogo<0.4
        """))
    result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y')
    assert diff_states(result.files_before, result2.files_after, ignore=[env.relative_env_path/'build', env.relative_env_path/'src'/'initools']).values() == [{}, {}, {}]

{'fraction_non_alphanumeric': 0.15518994361770957, 'fraction_numerical': 0.006100378962935576, 'mean_word_length': 4.041938490214353, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '480299', 'n_tokens_mistral': 3608, 'n_tokens_neox': 3533, 'n_words': 702}