From f7b49938105cafec256c1261ed19970a4f0f9aeb Mon Sep 17 00:00:00 2001 From: psakiev Date: Wed, 7 Dec 2022 14:25:12 -0700 Subject: [PATCH] Address reviewer comments --- lib/spack/spack/test/cmd/env.py | 39 ++++++++++++++++++++++++++++++++ lib/spack/spack/test/config.py | 39 -------------------------------- lib/spack/spack/test/conftest.py | 2 +- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py index 64aaf3c2251..c7e91d66107 100644 --- a/lib/spack/spack/test/cmd/env.py +++ b/lib/spack/spack/test/cmd/env.py @@ -3181,3 +3181,42 @@ def test_env_include_packages_url( cfg = spack.config.get("packages") assert "openmpi" in cfg["all"]["providers"]["mpi"] + + +def test_config_file_read_invalid_yaml(tmpdir, mutable_empty_config): + """Test reading a configuration file with invalid (unparseable) YAML + raises a ConfigFileError.""" + filename = join_path(tmpdir.strpath, "test.yaml") + with open(filename, "w") as f: + f.write("spack:\nview") + + with pytest.raises(spack.config.ConfigFileError, match="parsing yaml"): + spack.config.read_config_file(filename) + + +def test_environment_created_in_users_location(mutable_config, tmpdir): + """Test that an environment is created in a location based on the config""" + spack.config.set("config:environments_root", str(tmpdir.join("envs"))) + env_dir = spack.config.get("config:environments_root") + + assert tmpdir.strpath in env_dir + assert not os.path.isdir(env_dir) + + os.makedirs(env_dir) + env("create", "test") + out = env("list") + + assert "test" in out + assert env_dir in ev.root("test") + assert os.path.isdir(os.path.join(env_dir, "test")) + + +def test_environment_errors_if_root_missing(mutable_config, tmpdir): + spack.config.set("config:environments_root", str(tmpdir.join("envs"))) + env_dir = spack.config.get("config:environments_root") + + assert tmpdir.strpath in env_dir + assert not os.path.isdir(env_dir) + + with pytest.raises(ev.SpackEnvironmentError, match=env_dir): + env("create", "test") diff --git a/lib/spack/spack/test/config.py b/lib/spack/spack/test/config.py index 1a38764308b..7988f261bef 100644 --- a/lib/spack/spack/test/config.py +++ b/lib/spack/spack/test/config.py @@ -1451,42 +1451,3 @@ def test_config_file_read_perms_failure(tmpdir, mutable_empty_config): with pytest.raises(spack.config.ConfigFileError, match="not readable"): spack.config.read_config_file(filename) - - -def test_config_file_read_invalid_yaml(tmpdir, mutable_empty_config): - """Test reading a configuration file with invalid (unparseable) YAML - raises a ConfigFileError.""" - filename = join_path(tmpdir.strpath, "test.yaml") - with open(filename, "w") as f: - f.write("spack:\nview") - - with pytest.raises(spack.config.ConfigFileError, match="parsing yaml"): - spack.config.read_config_file(filename) - - -def test_environment_created_in_users_location(mutable_config, tmpdir): - """Test that an environment is created in a location based on the config""" - spack.config.set("config:environments_root", str(tmpdir.join("envs"))) - env_dir = spack.config.get("config:environments_root") - - assert tmpdir.strpath in env_dir - assert not os.path.isdir(env_dir) - - os.makedirs(env_dir) - env("create", "test") - out = env("list") - - assert "test" in out - assert env_dir in ev.root("test") - assert os.path.isdir(os.path.join(env_dir, "test")) - - -def test_environment_errors_if_root_missing(mutable_config, tmpdir): - spack.config.set("config:environments_root", str(tmpdir.join("envs"))) - env_dir = spack.config.get("config:environments_root") - - assert tmpdir.strpath in env_dir - assert not os.path.isdir(env_dir) - - with pytest.raises(ev.SpackEnvironmentError, match=env_dir): - env("create", "test") diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py index f56fbd54490..70851a45cb9 100644 --- a/lib/spack/spack/test/conftest.py +++ b/lib/spack/spack/test/conftest.py @@ -1527,7 +1527,7 @@ def get_rev(): @pytest.fixture() -def mutable_mock_env_path(tmpdir_factory): +def mutable_mock_env_path(tmpdir_factory, mutable_config): """Fixture for mocking the internal spack environments directory.""" saved_path = ev.environment.default_env_path mock_path = tmpdir_factory.mktemp("mock-env-path")