Exemple #1
0
def test_pip_deps():
    with TestDir(__file__):
        env = environment.EnvironmentFile("pip_deps.yml")
        assert env.name == "conda_hooks_pip_deps"
        assert env.dependencies == ["numpy", "pip"]
        assert env.pip_dependencies == ["matplotlib", "mypy"]

        with pytest.raises(errors.InvalidEnvFile):
            environment.EnvironmentFile("invalid_pip_deps.yml")
Exemple #2
0
def test_default_path():
    with TestDir(__file__):
        env = environment.EnvironmentFile()
        assert env.name == "conda_hooks_default"
        assert env.env_file_path == Path("environment.yml")

        os.remove("environment.yml")
        with pytest.raises(errors.NoEnvFileError):
            env = environment.EnvironmentFile()
Exemple #3
0
def test_write():
    with TestDir(__file__):
        # write file
        env = environment.EnvironmentFile("write.yml")
        env.write()

        # read file back
        env_new = environment.EnvironmentFile("write.yml")
        assert env.env_file_path == env_new.env_file_path
        assert env.name == env_new.name
        assert env.dependencies == env_new.dependencies
        assert env.pip_dependencies == env_new.pip_dependencies
        assert env.channels == env_new.channels
Exemple #4
0
def test_empty_env_file():
    with TestDir(__file__):
        env = environment.EnvironmentFile("empty.yml")
        assert env.name == "conda_hooks_empty"
        assert env.dependencies == []
        assert env.pip_dependencies == []
        assert env.channels == []
Exemple #5
0
def test_get_installed_dependencies():
    with TestDir(__file__):
        env = environment.EnvironmentFile("export.yml")
        env.remove()
        env.create()
        assert env.get_installed_dependencies() == ["black", "mypy", "python"]

        exe = util.find_conda_executable(allow_mamba=False)
        subprocess.run(
            [
                str(exe),
                "install",
                "-n",
                env.name,
                "-q",
                "-y",
                "jinja2",
            ],
            check=True,
        )
        assert env.get_installed_dependencies() == [
            "black", "jinja2", "mypy", "python"
        ]

        env.remove()
def test_main():
    with TestDir(__file__):
        stored_env = environment.EnvironmentFile()
        stored_env.create()

        env_store.main([])
        new_env = environment.EnvironmentFile()
        assert stored_env.name == new_env.name
        assert stored_env.env_file_path == new_env.env_file_path
        assert stored_env.channels == new_env.channels
        assert stored_env.dependencies == new_env.dependencies
        assert stored_env.pip_dependencies == new_env.pip_dependencies

        subprocess.run(
            [
                str(util.find_conda_executable()),
                "install",
                "-n",
                stored_env.name,
                "-q",
                "-y",
                "jinja2",
            ],
            check=True,
        )
        env_store.main([])
        new_env = environment.EnvironmentFile()
        assert stored_env.name == new_env.name
        assert stored_env.env_file_path == new_env.env_file_path
        assert stored_env.channels == new_env.channels
        assert stored_env.pip_dependencies == new_env.pip_dependencies

        new_deps = [
            dep for dep in new_env.dependencies
            if dep not in stored_env.dependencies
        ]
        assert new_deps == [
            "jinja2",
        ]

        stored_env.remove()
        os.remove("environment.yml")
        env_store.main([])
Exemple #7
0
def test_create_remove():
    with TestDir(__file__):
        env = environment.EnvironmentFile("small.yml")
        env.remove()

        assert not env.exists()

        env.create()
        assert env.exists()
        env.create()

        env.remove()
        assert not env.exists()
        env.remove()
Exemple #8
0
def test_require_env_exists():
    with TestDir(__file__):
        env = environment.EnvironmentFile("non_existent_env.yml")
        with pytest.raises(errors.EnvDoesNotExistError):
            env.require_env_exists()
Exemple #9
0
def test_channels():
    with TestDir(__file__):
        env = environment.EnvironmentFile("channels.yml")
        assert env.channels == ["nvidia", "pytorch", "conda-forge"]
Exemple #10
0
def test_unsorted_deps():
    with TestDir(__file__):
        env = environment.EnvironmentFile("unsorted_deps.yml")
        assert env.name == "conda_hooks_unsorted_deps"
        assert env.dependencies == ["absl", "matplotlib", "numpy"]
Exemple #11
0
def test_missing_name():
    with TestDir(__file__):
        with pytest.raises(errors.InvalidEnvFile):
            environment.EnvironmentFile("missing_name.yml")
Exemple #12
0
def test_missing_file():
    with TestDir(__file__):
        with pytest.raises(errors.NoEnvFileError):
            environment.EnvironmentFile("this_file_does_not_exist.yml")