def test_download_one_file_to_the_right_place(tmpdir, caplog, links):
    """Test for downloader.get_file

    Assertions:
      file stored to the right place or exception exists in log
      file stored with right md5 sum

    """
    link = links[0]
    output_dir = str(tmpdir.mkdir("download"))
    downloader.get_file(link, output_dir)
    caplog.setLevel(logging.ERROR)
    out = caplog.records()[0]
    listdir = os.listdir(output_dir)
    assert len(listdir) == 1 or link in out.message
    if listdir:
        name = listdir[0]
        assert name == link.split("/")[-1]
Exemplo n.º 2
0
def _assert_dataset_existence(directory, dataset_filename, dataset_url):
    """ Check if a dataset exists inside the given directory. If it doesn't, offer the user to download it. Returns a bool """
    if _file_exists(directory, dataset_filename):
        return True

    print "Parece que no tienes el dataset adecuado ("+dataset_filename+") en la carpeta '"+directory+"'"
    should_download = (raw_input('¿Deseas descargar el dataset? [si|no]: ')).lower() == "si"
    if not should_download:
        print "No se descargara el archivo."
        return False

    print "Comenzará la descarga. Para cancelar, presiona control+c."

    downloaded_filename = get_file(directory, dataset_url, dataset_filename)
    return downloaded_filename != ""