예제 #1
0
def test_install_primitives(install_path):
    installation_dir = get_installation_dir()
    custom_max_file = os.path.join(installation_dir, "custom_max.py")
    custom_mean_file = os.path.join(installation_dir, "custom_mean.py")
    custom_sum_file = os.path.join(installation_dir, "custom_sum.py")

    # make sure primitive files aren't there e.g from a failed run
    for p in [custom_max_file, custom_mean_file, custom_sum_file]:
        try:
            os.unlink(p)
        except Exception:
            pass

    # handle install via command line as a special case
    if install_path == "INSTALL_VIA_CLI":
        subprocess.check_output(['featuretools', 'install', '--no-prompt', primitives_to_install_dir(this_dir())])
    elif install_path == "INSTALL_VIA_MODULE":
        subprocess.check_output(['python', '-m', 'featuretools', 'install', '--no-prompt', primitives_to_install_dir(this_dir())])
    else:
        featuretools.primitives.install.install_primitives(install_path, prompt=False)

    # must reload submodule for it to work
    reload(featuretools.primitives.installed)
    from featuretools.primitives.installed import CustomMax, CustomSum, CustomMean  # noqa: F401

    files = list_primitive_files(installation_dir)
    assert set(files) == {custom_max_file, custom_mean_file, custom_sum_file}

    files = list_primitive_files(installation_dir)
    # then delete to clean up
    for f in files:
        os.unlink(f)
def test_install_primitives(install_path, primitives_to_install_dir):
    installation_dir = get_installation_dir()
    data_dir = featuretools.config.get("primitive_data_folder")
    custom_max_file = os.path.join(installation_dir, "custom_max.py")
    custom_mean_file = os.path.join(installation_dir, "custom_mean.py")
    custom_sum_file = os.path.join(installation_dir, "custom_sum.py")
    data_file = os.path.join(data_dir, "_pytest_test.csv")
    data_subfolder = os.path.join(data_dir, "pytest_folder")

    # make sure primitive files aren't there e.g from a failed run
    old_files = [
        custom_max_file, custom_mean_file, custom_sum_file, data_file,
        data_subfolder
    ]
    remove_test_files(old_files)

    # handle install via command line as a special case
    if install_path == "INSTALL_VIA_CLI":
        subprocess.check_output([
            'featuretools', 'install', '--no-prompt', primitives_to_install_dir
        ])
    elif install_path == "INSTALL_VIA_MODULE":
        subprocess.check_output([
            'python', '-m', 'featuretools', 'install', '--no-prompt',
            primitives_to_install_dir
        ])
    else:
        install_primitives(install_path, prompt=False)

    # must reload submodule for it to work
    reload(featuretools.primitives.installed)
    from featuretools.primitives.installed import CustomMax, CustomSum, CustomMean  # noqa: F401

    files = list_primitive_files(installation_dir)
    assert {custom_max_file, custom_mean_file,
            custom_sum_file}.issubset(set(files))
    assert os.path.exists(data_file)
    os.unlink(data_file)
    assert os.path.exists(data_subfolder)
    assert os.path.exists(os.path.join(data_subfolder, "hello.txt"))
    shutil.rmtree(data_subfolder)

    # then delete to clean up
    for f in [custom_max_file, custom_mean_file, custom_sum_file]:
        os.unlink(f)
def test_fails_if_data_would_be_overwritten(primitives_to_install_dir):
    installation_dir = get_installation_dir()
    data_dir = featuretools.config.get("primitive_data_folder")
    custom_max_file = os.path.join(installation_dir, "custom_max.py")
    custom_mean_file = os.path.join(installation_dir, "custom_mean.py")
    custom_sum_file = os.path.join(installation_dir, "custom_sum.py")
    data_file = os.path.join(data_dir, "_pytest_test.csv")
    data_subfolder = os.path.join(data_dir, "pytest_folder")

    # make sure primitive files aren't there e.g from a failed run
    # make sure primitive files aren't there e.g from a failed run
    old_files = [
        custom_max_file, custom_mean_file, custom_sum_file, data_file,
        data_subfolder
    ]
    remove_test_files(old_files)

    install_primitives(primitives_to_install_dir, prompt=False)
    # should fail second time when trying to copy files that already exist
    with pytest.raises(OSError):
        install_primitives(primitives_to_install_dir, prompt=False)
def test_install_packages_from_requirements(primitives_to_install_dir):
    def pip_freeze():
        output = subprocess.check_output(['pip', 'freeze'])
        if not isinstance(output, str):
            output = output.decode()
        return output

    # make sure dummy module isn't installed
    if "featuretools-pip-tester" in pip_freeze():
        subprocess.check_call(
            ["pip", "uninstall", "-y", "featuretools-pip-tester"])
    assert "featuretools-pip-tester" not in pip_freeze()

    # generate requirements file with correct path
    requirements_path = os.path.join(primitives_to_install_dir,
                                     "requirements.txt")
    package_path = os.path.join(primitives_to_install_dir,
                                "featuretools_pip_tester")
    with open(requirements_path, 'w') as f:
        f.write(package_path)

    tar_path = os.path.join(os.path.dirname(primitives_to_install_dir),
                            "test_install_primitives.tar.gz")
    if os.path.exists(tar_path):
        os.unlink(tar_path)

    with tarfile.open(tar_path, "w:gz") as tar:
        tar.add(requirements_path, arcname="requirements.txt")
        tar.add(os.path.join(primitives_to_install_dir, "info.json"),
                arcname="info.json")
        tar.add(os.path.join(primitives_to_install_dir, "custom_max.py"),
                arcname="custom_max.py")
        tar.add(os.path.join(primitives_to_install_dir, "custom_mean.py"),
                arcname="custom_mean.py")
        tar.add(os.path.join(primitives_to_install_dir, "custom_sum.py"),
                arcname="custom_sum.py")
        tar.add(os.path.join(primitives_to_install_dir, "data"),
                arcname="data")

    installation_dir = get_installation_dir()
    data_dir = featuretools.config.get("primitive_data_folder")
    custom_max_file = os.path.join(installation_dir, "custom_max.py")
    custom_mean_file = os.path.join(installation_dir, "custom_mean.py")
    custom_sum_file = os.path.join(installation_dir, "custom_sum.py")
    data_file = os.path.join(data_dir, "_pytest_test.csv")
    data_subfolder = os.path.join(data_dir, "pytest_folder")

    # make sure primitive files aren't there e.g from a failed run
    old_files = [
        custom_max_file, custom_mean_file, custom_sum_file, data_file,
        data_subfolder
    ]
    remove_test_files(old_files)

    install_primitives(tar_path, prompt=False)

    # must reload submodule for it to work
    reload(featuretools.primitives.installed)
    from featuretools.primitives.installed import CustomMax, CustomSum, CustomMean  # noqa: F401

    files = list_primitive_files(installation_dir)
    assert {custom_max_file, custom_mean_file,
            custom_sum_file}.issubset(set(files))
    assert os.path.exists(data_file)
    os.unlink(data_file)
    os.unlink(requirements_path)
    assert os.path.exists(data_subfolder)
    assert os.path.exists(os.path.join(data_subfolder, "hello.txt"))
    shutil.rmtree(data_subfolder)
    os.unlink(tar_path)

    # then delete to clean up
    for f in [custom_max_file, custom_mean_file, custom_sum_file]:
        os.unlink(f)

    assert "featuretools-pip-tester" in pip_freeze()
    subprocess.check_call(
        ["pip", "uninstall", "-y", "featuretools-pip-tester"])