예제 #1
0
def test_get_channeldata():
    """
    Test the get_channeldata method properly finds a good ggd package and handles a bad ggd package 
    """
    pytest_enable_socket()

    ## Uninstall hg19-gaps-v1
    try:
        uninstall_hg19_gaps_ucsc_v1()
    except:
        pass

    ## Install hg19-gaps-v1
    try:
        install_hg19_gaps_ucsc_v1()
    except:
        pass
    
    ## Test normal run
    ggd_recipe = "hg19-gaps-ucsc-v1"
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata([ggd_recipe],ggd_channel)
    assert ggd_recipe in jdict["packages"].keys()

    ## Similar installed package
    ggd_recipe = "hg19-gaps"
    ggd_channel = "genomics"
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        uninstall.get_channeldata([ggd_recipe],ggd_channel)
    output = temp_stdout.getvalue().strip() 
    assert "Packages installed on your system that are similar include:" in output
    assert "hg19-gaps-ucsc-v1" in output
    assert uninstall.get_channeldata([ggd_recipe],ggd_channel) == False

    ## Test bad recipe 
    bad_recipe = "BadRecipe"
    ggd_channel = "genomics"
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        uninstall.get_channeldata([bad_recipe],ggd_channel)
    output = temp_stdout.getvalue().strip() 
    print("OUTPUT: '''", output, "''''")
    assert "{} is not in the ggd-{} channel".format(bad_recipe,ggd_channel)
    assert "Unable to find any package similar to the package entered. Use 'ggd search' or 'conda find' to identify the right package" in output
    assert "This package may not be installed on your system" in output
    assert uninstall.get_channeldata([bad_recipe],ggd_channel) == False

    ## Test bad channel 
    ggd_recipe = "hg19-gaps-ucsc-v1"
    bad_channel = "BadChannel"
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        uninstall.get_channeldata([ggd_recipe],bad_channel) 
    output = temp_stdout.getvalue().strip() 
    assert "The 'BadChannel' channel is not a ggd conda channel" in output
예제 #2
0
def test_get_channeldata():
    """
    Test the get_channeldata method properly finds a good ggd package and handles a bad ggd package 
    """
    pytest_enable_socket()

    ## Uninstall hg19-gaps-v1
    try:
        uninstall_hg19_gaps_ucsc_v1()
    except:
        pass

    ## Install hg19-gaps-v1
    try:
        install_hg19_gaps_ucsc_v1()
    except:
        pass
    
    ## Test normal run
    ggd_recipe = "hg19-gaps-ucsc-v1"
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata(ggd_recipe,ggd_channel)
    assert ggd_recipe in jdict["packages"].keys()

    ## Similar installed package
    ggd_recipe = "hg19-gaps"
    ggd_channel = "genomics"
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        uninstall.get_channeldata(ggd_recipe,ggd_channel)
    output = temp_stdout.getvalue().strip() 
    assert "Packages installed on your system that are similar include:" in output
    assert "hg19-gaps-ucsc-v1" in output
    assert uninstall.get_channeldata(ggd_recipe,ggd_channel) == False

    ## Test bad recipe 
    bad_recipe = "BadRecipe"
    ggd_channel = "genomics"
    with redirect_stdout(temp_stdout):
        uninstall.get_channeldata(bad_recipe,ggd_channel)
    output = temp_stdout.getvalue().strip() 
    assert "Packages installed on your system that are similar include:" in output
    assert "{} is not in the ggd-{} channel".format(bad_recipe,ggd_channel)
    assert "Unable to find any package similar to the package entered. Use 'ggd search' or 'conda find' to identify the right package" in output
    assert "This package may not be installed on your system" in output
    assert uninstall.get_channeldata(bad_recipe,ggd_channel) == False

    ## Test bad channel 
    ggd_recipe = "hg19-gaps-ucsc-v1"
    bad_channel = "BadChannel"
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        uninstall.get_channeldata(ggd_recipe,bad_channel) ## Exit due to bad url from ggd.search
    assert "SystemExit" in str(pytest_wrapped_e.exconly()) ## test that SystemExit was raised by sys.exit() 
    assert pytest_wrapped_e.match("The 'BadChannel' channel is not a ggd conda channel") ## Check that the exit code is 1
예제 #3
0
def test_remove_from_condaroot():
    """
    Test that the remove_from_condaroot function properly removes installed ggd packages from the conda root
    """

    ## install hg19-gaps-v1
    install_hg19_gaps_v1()

    ggd_recipe = "hg19-gaps-v1"
    ggd_channel = "genomics"
    version = uninstall.get_channeldata(ggd_recipe,ggd_channel)["packages"][ggd_recipe]["version"]

    ## Check that the files are in the conda root
    conda_root = utils.conda_root()
    check_list = sp.check_output(['find', conda_root, '-name', ggd_recipe+"-"+str(version)+"*"]).decode('utf8').strip().split("\n")
    for f in check_list:
        if conda_root in f:
            if conda_root+"/envs/" not in f:
                assert ggd_recipe+"-"+str(version) in f 
    
    ## remove ggd recipe files from conda root
    uninstall.remove_from_condaroot(ggd_recipe,version)

    ## Check that the files were removed
    conda_root = utils.conda_root()
    check_list = sp.check_output(['find', conda_root, '-name', ggd_recipe+"-"+str(version)+"*"]).decode('utf8').strip().split("\n")
    for f in check_list:
        if conda_root in f:
            if conda_root+"/envs/" not in f:
                assert ggd_recipe+"-"+str(version) not in f 

       
    ## Finish uninstalling hg19-gaps-v1
    uninstall_hg19_gaps_v1()
예제 #4
0
def test_get_channeldata():
    """
    Test the get_channeldata method properly finds a good ggd package and handles a bad ggd package 
    """
    ## Uninstall hg19-gaps-v1
    try:
        uninstall_hg19_gaps_v1()
    except:
        pass

    ## Install hg19-gaps-v1
    try:
        install_hg19_gaps_v1()
    except:
        pass
    
    ## Test normal run
    ggd_recipe = "hg19-gaps-v1"
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata(ggd_recipe,ggd_channel)
    assert ggd_recipe in jdict["packages"].keys()

    ## Similar installed package
    ggd_recipe = "hg19-gaps"
    ggd_channel = "genomics"
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        uninstall.get_channeldata(ggd_recipe,ggd_channel)
    output = temp_stdout.getvalue().strip() 
    assert "Packages installed on your system that are similar include:" in output
    assert "hg19-gaps-v1" in output
    assert uninstall.get_channeldata(ggd_recipe,ggd_channel) == False

    ## Test bad recipe 
    bad_recipe = "BadRecipe"
    ggd_channel = "genomics"
    with redirect_stdout(temp_stdout):
        uninstall.get_channeldata(bad_recipe,ggd_channel)
    output = temp_stdout.getvalue().strip() 
    assert "Packages installed on your system that are similar include:" in output
    assert "{} is not in the ggd-{} channel".format(bad_recipe,ggd_channel)
    assert "Unable to find any package similar to the package entered. Use 'ggd search' or 'conda find' to identify the right package" in output
    assert "This package may not be installed on your system" in output
    assert uninstall.get_channeldata(bad_recipe,ggd_channel) == False

    ## Test bad channel 
    ggd_recipe = "hg19-gaps-v1"
    bad_channel = "BadChannel"
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        uninstall.get_channeldata(ggd_recipe,bad_channel) ## Exit due to bad url from ggd.search
    assert "SystemExit" in str(pytest_wrapped_e.exconly()) ## test that SystemExit was raised by sys.exit() 
    assert pytest_wrapped_e.match("1") ## Check that the exit code is 1
예제 #5
0
def test_uninstall_internet_free():
    """
    Test the uninstall method in an internet free context 
        (uninstall)
    """

    ## Install hg19-gaps
    try:
        pytest_enable_socket()
        install_hg19_gaps_ucsc_v1()
    except:
        pass

    ## Check show-env in an internet free context
    pytest_disable_socket()
    ### Check that there is no interent
    assert utils.check_for_internet_connection() == False

    ## Check non-failure uninstall command
    ggd_recipe = "hg19-gaps-ucsc-v1"
    args = Namespace(channel='genomics',
                     command='uninstall',
                     names=[ggd_recipe])
    assert uninstall.uninstall((), args) == True

    #### Get jdict
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata([ggd_recipe], ggd_channel)
    conda_root = utils.conda_root()

    ### Check that the files are not in the conda root
    species = jdict["packages"][ggd_recipe]["identifiers"]["species"]
    build = jdict["packages"][ggd_recipe]["identifiers"]["genome-build"]
    version = jdict["packages"][ggd_recipe]["version"]
    path = os.path.join(conda_root, "share", "ggd", species, build, ggd_recipe,
                        version)
    check_list = sp.check_output([
        "find", conda_root, "-name", ggd_recipe + "-" + str(version) + "*"
    ]).decode("utf8").strip().split("\n")
    for f in check_list:
        if conda_root in f:
            if conda_root + "/envs/" not in path:
                assert ggd_recipe + "-" + str(version) not in path

    #### Check data files were removed
    assert glob.glob(path) == []
    try:
        os.listdir(path)
        assert False
    except OSError as e:
        if "No such file or directory" in str(e):
            pass
        else:
            assert False

    #### Check that the ggd package is no longer in the list of conda packages
    output = sp.check_output(["conda", "list", ggd_recipe])
    assert ggd_recipe not in str(output)
예제 #6
0
def test_uninstall():
    """
    Test that a package is properly uninstalled using the main uninstall funciton
    """

    ## Test handling of a package not installed
    ggd_recipe = "not-a-real-recipe"
    args = Namespace(channel='genomics', command='uninstall', name=ggd_recipe)
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        uninstall.uninstall((),args)
    assert "SystemExit" in str(pytest_wrapped_e.exconly()) ## test that SystemExit was raised by sys.exit() 
    assert pytest_wrapped_e.match("") ## Check that the exit code is ""


    ## Test a good uninstall
    #### Install hg19-gaps-v1
    install_hg19_gaps_v1()

    #### Check non-failure uninstall command
    ggd_recipe = "hg19-gaps-v1"
    args = Namespace(channel='genomics', command='uninstall', name=ggd_recipe)
    assert uninstall.uninstall((),args) == True

    #### Get jdict 
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata(ggd_recipe,ggd_channel)
    conda_root = utils.conda_root()

    ### Check that the files are not in the conda root
    version = jdict["packages"][ggd_recipe]["version"]
    check_list = sp.check_output(["find", conda_root, "-name", ggd_recipe+"-"+str(version)+"*"]).decode("utf8").strip().split("\n")
    for f in check_list:
        if conda_root in f:
            if conda_root+"/envs/" not in path:
                assert ggd_recipe+"-"+str(version) not in path 

    #### Check data files were removed
    species = jdict["packages"][ggd_recipe]["identifiers"]["species"]
    build = jdict["packages"][ggd_recipe]["identifiers"]["genome-build"]
    version = jdict["packages"][ggd_recipe]["version"]
    path = os.path.join(conda_root,"share","ggd",species,build,ggd_recipe,version)
    assert glob.glob(path) == []
    try:
        os.listdir(path) 
        assert False
    except OSError as e:
        if "No such file or directory" in str(e):
            pass
        else:
            assert False

    #### Check that the ggd package is no longer in the list of conda packages
    output = sp.check_output(["conda", "list", ggd_recipe])
    assert ggd_recipe not in str(output)
예제 #7
0
def test_check_for_installation():
    """
    Test the check_for_installation function to check if the ggd package is installed using the ggd file handling information
    """
    ## Test a not installed ggd recipe 
    ggd_recipe = "grch37-reference-genome-v1"
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata(ggd_recipe,ggd_channel)
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        uninstall.check_for_installation(ggd_recipe,jdict)
    output = temp_stdout.getvalue().strip() 
    assert "{} is not in the ggd recipe storage".format(ggd_recipe) in output

    ## Test installed package
    ggd_recipe = "hg19-gaps-v1"
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata(ggd_recipe,ggd_channel)
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        uninstall.check_for_installation(ggd_recipe,jdict)
    output = temp_stdout.getvalue().strip() 
    assert "Removing {} version {} file(s) from ggd recipe storage".format(ggd_recipe,jdict["packages"][ggd_recipe]["version"]) in output
예제 #8
0
def test_check_for_installation():
    """
    Test the check_for_installation function to check if the ggd package is installed using the ggd file handling information
    """
    pytest_enable_socket()

    ## Test a not installed ggd recipe 
    ggd_recipe = "grch37-reference-genome-1000g-v1"
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata(ggd_recipe,ggd_channel)
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        uninstall.check_for_installation([ggd_recipe],jdict)
    output = temp_stdout.getvalue().strip() 
    assert "{} is not in the ggd recipe storage".format(ggd_recipe) in output

    ## Test installed package
    ggd_recipe = "hg19-gaps-ucsc-v1"
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata(ggd_recipe,ggd_channel)
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        uninstall.check_for_installation([ggd_recipe],jdict)
    output = temp_stdout.getvalue().strip() 
    assert "Removing {} version {} file(s) from ggd recipe storage".format(ggd_recipe,jdict["packages"][ggd_recipe]["version"]) in output

    ## Update local metadata
    utils.update_installed_pkg_metadata(prefix=conda_root())

    args = Namespace(command="show-env", pattern=None)
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        show_env.show_env((),args)
    output = temp_stdout.getvalue().strip()
    assert "$ggd_hg19_gaps_v1_file" not in output
    assert "$ggd_hg19_gaps_v1_dir" not in output
예제 #9
0
def test_get_channeldata_internet_free():
    """
    Test the get_channeldata function in uninstall in an internet free context
        (uninstall)
    """

    ## Install hg19-gaps
    try:
        pytest_enable_socket()
        install_hg19_gaps_ucsc_v1()
    except:
        pass

    ## Check show-env in an internet free context
    pytest_disable_socket()
    ### Check that there is no interent
    assert utils.check_for_internet_connection() == False

    ## Test normal run
    ggd_recipe = "hg19-gaps-ucsc-v1"
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata([ggd_recipe], ggd_channel)
    assert ggd_recipe in jdict["packages"].keys()
예제 #10
0
def test_uninstall():
    """
    Test that a package is properly uninstalled using the main uninstall funciton
    """
    pytest_enable_socket()

    ## Test handling of a package not installed
    ggd_recipe = "not-a-real-recipe"
    args = Namespace(channel='genomics', command='uninstall', name=ggd_recipe)
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        uninstall.uninstall((),args)
    assert "SystemExit" in str(pytest_wrapped_e.exconly()) ## test that SystemExit was raised by sys.exit() 
    assert pytest_wrapped_e.match("") ## Check that the exit code is ""


    ## Test a good uninstall
    #### Install hg19-gaps-ucsc-v1
    try:
        install_hg19_gaps_ucsc_v1()
    except:
        pass

    #### Check non-failure uninstall command
    ggd_recipe = "hg19-gaps-ucsc-v1"

    #### Get conda list pkg info
    pkg_info = get_conda_package_list(utils.conda_root(),ggd_recipe)
    assert ggd_recipe in pkg_info.keys()

    #### Test uninstall 
    args = Namespace(channel='genomics', command='uninstall', name=ggd_recipe)
    assert uninstall.uninstall((),args) == True

    #### Get jdict 
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata(ggd_recipe,ggd_channel)
    conda_root = utils.conda_root()

    ### Check that the files are not in the conda root
    version = jdict["packages"][ggd_recipe]["version"]
    check_list = sp.check_output(["find", conda_root, "-name", ggd_recipe+"-"+str(version)+"*"]).decode("utf8").strip().split("\n")
    for f in check_list:
        if conda_root in f:
            if conda_root+"/envs/" not in path:
                assert ggd_recipe+"-"+str(version) not in path 

    #### Check data files were removed
    species = jdict["packages"][ggd_recipe]["identifiers"]["species"]
    build = jdict["packages"][ggd_recipe]["identifiers"]["genome-build"]
    version = jdict["packages"][ggd_recipe]["version"]
    path = os.path.join(conda_root,"share","ggd",species,build,ggd_recipe,version)
    assert glob.glob(path) == []
    try:
        os.listdir(path) 
        assert False
    except OSError as e:
        if "No such file or directory" in str(e):
            pass
        else:
            assert False

    #### Check that the ggd package is no longer in the list of conda packages
    output = sp.check_output(["conda", "list", ggd_recipe])
    assert ggd_recipe not in str(output)

    ### Test that the ggd_info metadata is updated with ggd pkg
    version = pkg_info[ggd_recipe]["version"]
    build = pkg_info[ggd_recipe]["build"]
    assert os.path.exists(os.path.join(utils.conda_root(),"share","ggd_info","noarch"))
    assert os.path.exists(os.path.join(utils.conda_root(),"share","ggd_info","noarch",ggd_recipe+"-{}-{}.tar.bz2".format(version,build))) == False
    assert os.path.exists(os.path.join(utils.conda_root(),"share","ggd_info","channeldata.json"))
    with open(os.path.join(utils.conda_root(),"share","ggd_info","channeldata.json")) as jfile:
        channeldata = json.load(jfile)
        assert ggd_recipe not in channeldata["packages"]
예제 #11
0
def test_remove_from_condaroot():
    """
    Test that the remove_from_condaroot function properly removes installed ggd packages from the provided prefix/conda environment
    """
    pytest_enable_socket()

    ggd_recipe = "hg19-pfam-domains-ucsc-v1"
    ggd_channel = "genomics"

    ### Uninstall ggd recipe
    uninstall_args = Namespace(channel='genomics', command='uninstall', name=ggd_recipe)
    try:
        uninstall.uninstall((),uninstall_args)
    except:
        pass

    ## Install hg19-pfam-domains-ucsc-v1 into current environment
    sp.check_call(["ggd", "install", ggd_recipe])

    ## Create temp envi
    temp_env = os.path.join(utils.conda_root(), "envs", "temp_env11")
    ### Remove temp env if it already exists
    sp.check_output(["conda", "env", "remove", "--name", "temp_env11"])
    try: 
        shutil.rmtree(temp_env)
    except Exception:
        pass 
    ### Create conda environmnet 
    sp.check_output(["conda", "create", "--name", "temp_env11"])
    
    ## Test prefix 
    ### Install ggd recipe using conda into temp_env
    install_args = Namespace(channel='genomics', command='install', debug=False, name=[ggd_recipe], file=[], prefix = temp_env)
    assert install.install((), install_args) == True 

    ## jdict and info
    jdict = uninstall.get_channeldata(ggd_recipe,ggd_channel)
    species = jdict["packages"][ggd_recipe]["identifiers"]["species"]
    build = jdict["packages"][ggd_recipe]["identifiers"]["genome-build"]
    version = jdict["packages"][ggd_recipe]["version"]

    ## Check that the files are in the conda root
    conda_root = utils.conda_root()
    check_list = sp.check_output(['find', conda_root, '-name', ggd_recipe+"-"+str(version)+"*"]).decode('utf8').strip().split("\n")
    for f in check_list:
        if conda_root in f:
            if conda_root+"/envs/" not in f:
                assert ggd_recipe+"-"+str(version) in f 

    ## Check that the files are in the temp_env
    check_list = sp.check_output(['find', temp_env, '-name', ggd_recipe+"-"+str(version)+"*"]).decode('utf8').strip().split("\n")
    for f in check_list:
        if temp_env in f:
            if temp_env+"/envs/" not in f:
                assert ggd_recipe+"-"+str(version) in f 

    ## Remove recipe from prefix
    uninstall.remove_from_condaroot(ggd_recipe,version,temp_env)

    ## Check that the files were removed from prefix
    check_list = sp.check_output(['find', temp_env, '-name', ggd_recipe+"-"+str(version)+"*"]).decode('utf8').strip().split("\n")
    for f in check_list:
        if temp_env in f:
            if temp_env+"/envs/" not in f:
                assert ggd_recipe+"-"+str(version) not in f 

    ## Check that the files were NOT removed from the conda root
    conda_root = utils.conda_root()
    check_list = sp.check_output(['find', conda_root, '-name', ggd_recipe+"-"+str(version)+"*"]).decode('utf8').strip().split("\n")
    for f in check_list:
        if conda_root in f:
            if conda_root+"/envs/" not in f:
                assert ggd_recipe+"-"+str(version) in f 

    ## remove ggd recipe files from conda root
    uninstall.remove_from_condaroot(ggd_recipe,version,conda_root)

    ## Check that the files were removed
    conda_root = utils.conda_root()
    check_list = sp.check_output(['find', conda_root, '-name', ggd_recipe+"-"+str(version)+"*"]).decode('utf8').strip().split("\n")
    for f in check_list:
        if conda_root in f:
            if conda_root+"/envs/" not in f:
                assert ggd_recipe+"-"+str(version) not in f 

       
    ## Finish uninstalling recipe
    args = Namespace(channel='genomics', command='uninstall', name=ggd_recipe)
    uninstall.uninstall((),args)

    ## Remove temp_env
    sp.check_output(["conda", "env", "remove", "--name", "temp_env11"])
    try: 
        shutil.rmtree(temp_env)
    except Exception:
        pass 
    assert os.path.exists(temp_env) == False
예제 #12
0
def test_check_for_installation_different_prefix():
    """
    Test that check_for_installation when a prefix is provided
    """

    ## Test installed package
    ggd_recipe = "hg19-pfam-domains-ucsc-v1"
    ggd_channel = "genomics"

    ### Uninstall ggd recipe
    uninstall_args = Namespace(channel='genomics', command='uninstall', name=ggd_recipe)
    try:
        uninstall.uninstall((),uninstall_args)
    except:
        pass

    ### Install ggd recipe
    install_args = Namespace(channel='genomics', command='install', debug=False, name=[ggd_recipe], file=[], prefix = conda_root())
    try:
        install.install((), install_args) 
    except:
        pass

    ## jdict and info
    jdict = uninstall.get_channeldata(ggd_recipe,ggd_channel)
    species = jdict["packages"][ggd_recipe]["identifiers"]["species"]
    build = jdict["packages"][ggd_recipe]["identifiers"]["genome-build"]
    version = jdict["packages"][ggd_recipe]["version"]

    ## Test the package in "conda_root" exists
    args = Namespace(command='list', pattern=None, prefix=conda_root())
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_installed_pkgs.list_installed_packages((), args)
    output = temp_stdout.getvalue().strip()
    assert ggd_recipe in output
    path = os.path.join(conda_root(),"share","ggd",species,build,ggd_recipe,version,"*")
    files = glob.glob(path)
    assert len(files) == 2

    ## Create temp envi
    temp_env = os.path.join(utils.conda_root(), "envs", "temp_env10")
    ### Remove temp env if it already exists
    sp.check_output(["conda", "env", "remove", "--name", "temp_env10"])
    try: 
        shutil.rmtree(temp_env)
    except Exception:
        pass 
    ### Create conda environmnet 
    sp.check_output(["conda", "create", "--name", "temp_env10"])
    
    ## Test prefix 
    ### Install ggd recipe using conda into temp_env
    install_args = Namespace(channel='genomics', command='install', debug=False, name=[ggd_recipe],file=[], prefix = temp_env)
    assert install.install((), install_args) == True 

    ## Test that the files are removed
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        uninstall.check_for_installation([ggd_recipe],jdict,prefix=temp_env)
    output = temp_stdout.getvalue().strip() 
    assert "Removing {} version {} file(s) from ggd recipe storage".format(ggd_recipe,jdict["packages"][ggd_recipe]["version"]) in output

    ## Update local metadata
    utils.update_installed_pkg_metadata(prefix=temp_env)

    ## Test the package was removed from the ggd info list
    args = Namespace(command='list', pattern=None, prefix=temp_env)
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_installed_pkgs.list_installed_packages((), args)
    output = temp_stdout.getvalue().strip()
    assert ggd_recipe not in output
    path = os.path.join(temp_env,"share","ggd",species,build,ggd_recipe,version,"*")
    files = glob.glob(path)
    assert len(files) == 0

    ## Test the package in "conda_root" was not removed
    args = Namespace(command='list', pattern=None, prefix=conda_root())
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_installed_pkgs.list_installed_packages((), args)
    output = temp_stdout.getvalue().strip()
    assert ggd_recipe in output
    path = os.path.join(conda_root(),"share","ggd",species,build,ggd_recipe,version,"*")
    files = glob.glob(path)
    assert len(files) == 2

    ## Remove prefix
    sp.check_output(["conda", "env", "remove", "--name", "temp_env10"])
    try: 
        shutil.rmtree(temp_env)
    except Exception:
        pass 
    assert os.path.exists(temp_env) == False


    ## Test the current environment (conda_root)
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        uninstall.check_for_installation([ggd_recipe],jdict,prefix=utils.conda_root())
    output = temp_stdout.getvalue().strip() 
    assert "Removing {} version {} file(s) from ggd recipe storage".format(ggd_recipe,jdict["packages"][ggd_recipe]["version"]) in output

    ## Update local metadata
    utils.update_installed_pkg_metadata(prefix=conda_root())

    ## Test environment variables removed
    args = Namespace(command="show-env", pattern=None)
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        show_env.show_env((),args)
    output = temp_stdout.getvalue().strip()
    assert "hg19_pfam_domains_ucsc_v1_file" not in output
    assert "hg19_pfam_domains_ucsc_v1_dir" not in output
    
    args = Namespace(command='list', pattern=None, prefix=conda_root())
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_installed_pkgs.list_installed_packages((), args)
    output = temp_stdout.getvalue().strip()
    assert ggd_recipe not in output

    path = os.path.join(conda_root(),"share","ggd",species,build,ggd_recipe,version,"*")
    files = glob.glob(path)
    assert len(files) == 0
예제 #13
0
def test_uninstall_multiple_package():
    """
    Test that multiple packages are uninstalled using the main uninstall function 
    """
    recipes = ["hg19-chrom-mapping-ensembl2ucsc-ncbi-v1","hg19-chrom-mapping-refseq2ucsc-ncbi-v1"]

    ## Install ggd recipe
    install_args = Namespace(channel='genomics', command='install', debug=False, name=recipes, file=[], prefix = conda_root(), id = None)
    try:
        install.install((), install_args) 
    except:
        pass

    #### Check that the recipe are installed by conda 
    pkg_info = get_conda_package_list(utils.conda_root())
    for recipe in recipes:
        assert recipe in pkg_info.keys()

    #### Get jdict 
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata(recipes,ggd_channel)

    #### Check data files exists
    for ggd_recipe in recipes:
        species = jdict["packages"][ggd_recipe]["identifiers"]["species"]
        build = jdict["packages"][ggd_recipe]["identifiers"]["genome-build"]
        version = jdict["packages"][ggd_recipe]["version"]
        final_files = jdict["packages"][ggd_recipe]["tags"]["final-files"]
        path = os.path.join(conda_root(),"share","ggd",species,build,ggd_recipe,version,"*")
        assert sorted(glob.glob(path)) == sorted([os.path.join(path.replace("*",""),x) for x in final_files])


    #### Check that the ggd metadata channeldata file contains new recipes
    for ggd_recipe in recipes:
        version = pkg_info[ggd_recipe]["version"]
        build = pkg_info[ggd_recipe]["build"]
        assert os.path.exists(os.path.join(utils.conda_root(),"share","ggd_info","noarch"))
        assert os.path.exists(os.path.join(utils.conda_root(),"share","ggd_info","noarch",ggd_recipe+"-{}-{}.tar.bz2".format(version,build)))
        assert os.path.exists(os.path.join(utils.conda_root(),"share","ggd_info","channeldata.json"))
        with open(os.path.join(utils.conda_root(),"share","ggd_info","channeldata.json")) as jfile:
            channeldata = json.load(jfile)
            assert ggd_recipe in channeldata["packages"]


    ## Test uninstall 
    args = Namespace(channel='genomics', command='uninstall', names=recipes)
    assert uninstall.uninstall((),args) == True

    #### Check that the recipe are uninstalled by conda 
    pkg_info = get_conda_package_list(utils.conda_root())
    for recipe in recipes:
        assert recipe not in pkg_info.keys()

    #### Get jdict 
    ggd_channel = "genomics"
    jdict = uninstall.get_channeldata(recipes,ggd_channel)

    #### Check data files are removed
    for ggd_recipe in recipes:
        species = jdict["packages"][ggd_recipe]["identifiers"]["species"]
        build = jdict["packages"][ggd_recipe]["identifiers"]["genome-build"]
        version = jdict["packages"][ggd_recipe]["version"]
        final_files = jdict["packages"][ggd_recipe]["tags"]["final-files"]
        path = os.path.join(conda_root(),"share","ggd",species,build,ggd_recipe,version)
        assert glob.glob(path) == []

    #### Check that the ggd metadata channeldata file does not contain the packages
    for ggd_recipe in recipes:
        assert os.path.exists(os.path.join(utils.conda_root(),"share","ggd_info","noarch"))
        assert os.path.exists(os.path.join(utils.conda_root(),"share","ggd_info","noarch",ggd_recipe+"-{}-{}.tar.bz2".format(version,build))) == False
        assert os.path.exists(os.path.join(utils.conda_root(),"share","ggd_info","channeldata.json"))
        with open(os.path.join(utils.conda_root(),"share","ggd_info","channeldata.json")) as jfile:
            channeldata = json.load(jfile)
            assert ggd_recipe not in channeldata["packages"]