Esempio n. 1
0
def test_get_similar_pkg_installed_by_conda():
    """
    Test the get_similar_pkg_installed_by_conda function 
    """
    pytest_enable_socket()

    ## Test a non similar package name
    not_installed = "Not_an_installed_package"
    assert uninstall.get_similar_pkg_installed_by_conda(not_installed) == ""

    
    installed_requirement = "request"
    output = uninstall.get_similar_pkg_installed_by_conda(installed_requirement)
    assert "requests" in output
    assert "pyyaml" not in output

    installed_requirement = "yaml"
    output = uninstall.get_similar_pkg_installed_by_conda(installed_requirement)
    assert "pyyaml" in output
    assert "oyaml" in output
    assert "requests" not in output
    
    ## Make sure hg19-gaps-v1 is installed
    ggd_recipe = "hg19-gaps-ucsc-v1"
    list_files_args = Namespace(channel='genomics', command='list-files', genome_build=None, name=ggd_recipe, pattern=None, prefix=None, species=None, version=None)
    try:
        list_files.list_files((),list_files_args)
    except SystemExit as e:
        if str(e) == "1": ## If exit code is 1, implying that there were not files found
            install_hg19_gaps_ucsc_v1()

    ggd_recipe = "hg19-gaps"
    output = uninstall.get_similar_pkg_installed_by_conda(ggd_recipe)
    assert "hg19-gaps-ucsc-v1" in output
Esempio n. 2
0
def test_list_files_internet_free():
    """
    test the list_files function in list-files in an internet free context
        (list-files)
    """

    ## 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 list-files
    ggd_package = "hg19-gaps-ucsc-v1"
    file1 = "{}.bed.gz".format(ggd_package)
    file2 = "{}.bed.gz.tbi".format(ggd_package)

    ##Test that the correct file paths are returned
    args = Namespace(channel='genomics',
                     command='list-files',
                     genome_build=None,
                     name=ggd_package,
                     pattern=None,
                     prefix=None,
                     species=None,
                     version=None)

    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_files.list_files((), args)
    output = str(temp_stdout.getvalue().strip())
    assert re.search(file1 + "$", sorted(output.split("\n"))[0])
    assert re.search(file2 + "$", sorted(output.split("\n"))[1])
    assert len(output.split("\n")) == 2

    ##Test that the correct file paths are returned with the genome_build key set
    args = Namespace(channel='genomics',
                     command='list-files',
                     genome_build="hg19",
                     name=ggd_package,
                     pattern=None,
                     prefix=None,
                     species=None,
                     version=None)

    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_files.list_files((), args)
    output = str(temp_stdout.getvalue().strip())
    assert re.search(file1 + "$", sorted(output.split("\n"))[0])
    assert re.search(file2 + "$", sorted(output.split("\n"))[1])
    assert len(output.split("\n")) == 2

    ##Test that the correct file paths are returned with the species key set
    args = Namespace(channel='genomics',
                     command='list-files',
                     genome_build=None,
                     name=ggd_package,
                     pattern=None,
                     prefix=None,
                     species="Homo_sapiens",
                     version=None)

    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_files.list_files((), args)
    output = str(temp_stdout.getvalue().strip())
    assert re.search(file1 + "$", sorted(output.split("\n"))[0])
    assert re.search(file2 + "$", sorted(output.split("\n"))[1])
    assert len(output.split("\n")) == 2

    ##Test that the correct file paths are returned with version  key set
    args = Namespace(channel='genomics',
                     command='list-files',
                     genome_build=None,
                     name=ggd_package,
                     pattern=None,
                     prefix=None,
                     species=None,
                     version="1")

    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_files.list_files((), args)
    output = str(temp_stdout.getvalue().strip())
    assert re.search(file1 + "$", sorted(output.split("\n"))[0])
    assert re.search(file2 + "$", sorted(output.split("\n"))[1])
    assert len(output.split("\n")) == 2

    ## Test that nothing is returned when a bad ggd package name is given
    args = Namespace(channel='genomics',
                     command='list-files',
                     genome_build=None,
                     name="NOT_a_real_package_name",
                     pattern=None,
                     prefix=None,
                     species=None,
                     version=None)

    with pytest.raises(SystemExit) as pytest_wrapped_e:
        list_files.list_files((), args)
    assert "SystemExit" in str(pytest_wrapped_e.exconly(
    ))  ## test that systemexit was raised by sys.exit()
    assert pytest_wrapped_e.match("2")  ## check that the exit code is 1

    ##Test that the function exits if a bad genome build is given
    args = Namespace(channel='genomics',
                     command='list-files',
                     genome_build="Bad_Build",
                     name=ggd_package,
                     pattern=None,
                     species=None,
                     prefix=None,
                     version=None)

    with pytest.raises(SystemExit) as pytest_wrapped_e:
        list_files.list_files((), args)
    assert "SystemExit" in str(pytest_wrapped_e.exconly(
    ))  ## test that systemexit was raised by sys.exit()
    assert pytest_wrapped_e.match("3")  ## check that the exit code is 1

    ##Test that the function exits if a bad species is given
    args = Namespace(channel='genomics',
                     command='list-files',
                     genome_build=None,
                     name=ggd_package,
                     pattern=None,
                     prefix=None,
                     species="Mus_musculus",
                     version=None)

    with pytest.raises(SystemExit) as pytest_wrapped_e:
        list_files.list_files((), args)
    assert "SystemExit" in str(pytest_wrapped_e.exconly(
    ))  ## test that systemexit was raised by sys.exit()
    assert pytest_wrapped_e.match("3")  ## check that the exit code is 1

    ##Test that the function exits if a bad version is given
    args = Namespace(channel='genomics',
                     command='list-files',
                     genome_build=None,
                     name=ggd_package,
                     pattern=None,
                     prefix=None,
                     species=None,
                     version="99999")

    with pytest.raises(SystemExit) as pytest_wrapped_e:
        list_files.list_files((), args)
    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

    ##Test that the function exits if a bad pattern is given
    args = Namespace(channel='genomics',
                     command='list-files',
                     genome_build=None,
                     name=ggd_package,
                     pattern="BAD_PATTERN",
                     prefix=None,
                     species=None,
                     version=None)

    with pytest.raises(SystemExit) as pytest_wrapped_e:
        list_files.list_files((), args)
    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

    ##Test that the function exits if a bad channel is given
    args = Namespace(channel='bad-channel',
                     command='list-files',
                     genome_build=None,
                     name=ggd_package,
                     pattern=None,
                     prefix=None,
                     species=None,
                     version=None)

    with pytest.raises(SystemExit) as pytest_wrapped_e:
        list_files.list_files((), args)
    assert "SystemExit" in str(pytest_wrapped_e.exconly(
    ))  ## test that systemexit was raised by sys.exit()
    assert pytest_wrapped_e.match("2")  ## check that the exit code is 1
Esempio n. 3
0
def test_list_file_with_prefix_internet_free():
    """
    test the --prefix flag of list-files in a internet free context
        (list-files --prefix)
    """

    ## enable socket
    pytest_enable_socket()
    ## Temp conda environment
    temp_env = os.path.join(utils.conda_root(), "envs",
                            "temp_env_internet_free")
    ### Remove temp env if it already exists
    sp.check_output(
        ["conda", "env", "remove", "--name", "temp_env_internet_free"])
    try:
        shutil.rmtree(temp_env)
    except Exception:
        pass
    ## Create conda environmnet
    sp.check_output(["conda", "create", "--name", "temp_env_internet_free"])

    ## Install ggd recipe using conda into temp_env
    ggd_package = "hg19-pfam-domains-ucsc-v1"
    install_args = Namespace(channel='genomics',
                             command='install',
                             debug=False,
                             name=[ggd_package],
                             file=[],
                             prefix=temp_env,
                             id=None)
    assert install.install((), install_args) == True

    ## 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 the list-files method can access info from the files in a different prefix
    args = Namespace(channel='genomics',
                     command='list-files',
                     genome_build=None,
                     name=ggd_package,
                     pattern=None,
                     prefix=temp_env,
                     species=None,
                     version=None)

    file1 = "{}.bed12.bed.gz".format(ggd_package)
    file2 = "{}.bed12.bed.gz.tbi".format(ggd_package)
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_files.list_files((), args)
    output = str(temp_stdout.getvalue().strip())
    assert file1 in output
    assert file2 in output
    assert temp_env in output
    assert len(output.split("\n")) == 2

    ## Check output has correct file path
    ### Enable socket
    pytest_enable_socket()
    jdict = install.check_ggd_recipe(ggd_package, "genomics")
    species = jdict["packages"][ggd_package]["identifiers"]["species"]
    build = jdict["packages"][ggd_package]["identifiers"]["genome-build"]
    version = jdict["packages"][ggd_package]["version"]
    assert os.path.join(temp_env, "share", "ggd", species, build, ggd_package,
                        version, file1) in output
    assert os.path.join(temp_env, "share", "ggd", species, build, ggd_package,
                        version, file2) in output
    assert os.path.exists(
        os.path.join(temp_env, "share", "ggd", species, build, ggd_package,
                     version, file1))
    assert os.path.exists(
        os.path.join(temp_env, "share", "ggd", species, build, ggd_package,
                     version, file2))

    ## Remove temp env
    sp.check_output(
        ["conda", "env", "remove", "--name", "temp_env_internet_free"])
    try:
        shutil.rmtree(temp_env)
    except Exception:
        pass
    assert os.path.exists(temp_env) == False
Esempio n. 4
0
def test_list_files():
    """
    Test the main method of list-files 
    """

    ggd_package = "hg19-gaps-v1"
    file1 = "{}.bed.gz".format(ggd_package)
    file2 = "{}.bed.gz.tbi".format(ggd_package)

    ##Test that the correct file paths are returned 
    args = Namespace(channel='genomics', command='list-files', genome_build=None, name=ggd_package, pattern=None, species=None, version=None)
    
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_files.list_files((),args)
    output = str(temp_stdout.getvalue().strip()) 
    assert re.search(file1+"$", sorted(output.split("\n"))[0])
    assert re.search(file2+"$", sorted(output.split("\n"))[1])
    assert len(output.split("\n")) == 2

    ##Test that the correct file paths are returned with the genome_build key set
    args = Namespace(channel='genomics', command='list-files', genome_build="hg19", name=ggd_package, pattern=None, species=None, version=None)
    
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_files.list_files((),args)
    output = str(temp_stdout.getvalue().strip()) 
    assert re.search(file1+"$", sorted(output.split("\n"))[0])
    assert re.search(file2+"$", sorted(output.split("\n"))[1])
    assert len(output.split("\n")) == 2

    ##Test that the correct file paths are returned with the species key set
    args = Namespace(channel='genomics', command='list-files', genome_build=None, name=ggd_package, pattern=None, species="Homo_sapiens", version=None)
    
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_files.list_files((),args)
    output = str(temp_stdout.getvalue().strip()) 
    assert re.search(file1+"$", sorted(output.split("\n"))[0])
    assert re.search(file2+"$", sorted(output.split("\n"))[1])
    assert len(output.split("\n")) == 2

    ##Test that the correct file paths are returned with version  key set
    args = Namespace(channel='genomics', command='list-files', genome_build=None, name=ggd_package, pattern=None, species=None, version="1")
    
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_files.list_files((),args)
    output = str(temp_stdout.getvalue().strip()) 
    assert re.search(file1+"$", sorted(output.split("\n"))[0])
    assert re.search(file2+"$", sorted(output.split("\n"))[1])
    assert len(output.split("\n")) == 2

    ##Test that the correct file paths are returned with the patterns key set  key set
    args = Namespace(channel='genomics', command='list-files', genome_build=None, name=ggd_package, pattern=file1, species=None, version=None)
    
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_files.list_files((),args)
    output = str(temp_stdout.getvalue().strip()) 
    assert re.search(file1+"$", output)
    assert re.search(file2+"$", output) == None
    assert len(output.split("\n")) == 1

    args = Namespace(channel='genomics', command='list-files', genome_build=None, name=ggd_package, pattern=file2, species=None, version=None)
    
    temp_stdout = StringIO()
    with redirect_stdout(temp_stdout):
        list_files.list_files((),args)
    output = str(temp_stdout.getvalue().strip()) 
    assert re.search(file1+"$", output) == None
    assert re.search(file2+"$", output)
    assert len(output.split("\n")) == 1

    ## Test that nothing is returned when a bad ggd package name is given
    args = Namespace(channel='genomics', command='list-files', genome_build=None, name="NOT_a_real_package_name", pattern=None, species=None, version=None)
    
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        list_files.list_files((), args)
    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

    ##Test that the function exits if a bad genome build is given
    args = Namespace(channel='genomics', command='list-files', genome_build="Bad_Build", name=ggd_package, pattern=None, species=None, version=None)
    
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        list_files.list_files((), args)
    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

    ##Test that the function exits if a bad species is given
    args = Namespace(channel='genomics', command='list-files', genome_build=None, name=ggd_package, pattern=None, species="Mus_musculus", version=None)
    
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        list_files.list_files((), args)
    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

    ##Test that the function exits if a bad version is given
    args = Namespace(channel='genomics', command='list-files', genome_build=None, name=ggd_package, pattern=None, species=None, version="99999")
    
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        list_files.list_files((), args)
    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

    ##Test that the function exits if a bad pattern is given
    args = Namespace(channel='genomics', command='list-files', genome_build=None, name=ggd_package, pattern="BAD_PATTERN", species=None, version=None)
    
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        list_files.list_files((), args)
    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