diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/environment.py | 9 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/env.py | 11 | ||||
-rw-r--r-- | lib/spack/spack/test/conftest.py | 5 |
3 files changed, 20 insertions, 5 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index 18bf998438..ad95949d90 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -232,10 +232,15 @@ def get_env(args, cmd_name, required=False): ' spack -e ENV %s ...' % cmd_name) +def _root(name): + """Non-validating version of root(), to be used internally.""" + return os.path.join(env_path, name) + + def root(name): """Get the root directory for an environment by name.""" validate_env_name(name) - return os.path.join(env_path, name) + return _root(name) def exists(name): @@ -288,7 +293,7 @@ def all_environment_names(): candidates = sorted(os.listdir(env_path)) names = [] for candidate in candidates: - yaml_path = os.path.join(root(candidate), manifest_name) + yaml_path = os.path.join(_root(candidate), manifest_name) if valid_env_name(candidate) and os.path.exists(yaml_path): names.append(candidate) return names diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py index 76210bc562..7085373392 100644 --- a/lib/spack/spack/test/cmd/env.py +++ b/lib/spack/spack/test/cmd/env.py @@ -37,7 +37,7 @@ def test_add(): assert Spec('mpileaks') in e.user_specs -def test_env_list(): +def test_env_list(mutable_mock_env_path): env('create', 'foo') env('create', 'bar') env('create', 'baz') @@ -48,6 +48,15 @@ def test_env_list(): assert 'bar' in out assert 'baz' in out + # make sure `spack env list` skips invalid things in var/spack/env + mutable_mock_env_path.join('.DS_Store').ensure(file=True) + out = env('list') + + assert 'foo' in out + assert 'bar' in out + assert 'baz' in out + assert '.DS_Store' not in out + def test_env_remove(capfd): env('create', 'foo') diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py index ad0644da3e..afa210a87a 100644 --- a/lib/spack/spack/test/conftest.py +++ b/lib/spack/spack/test/conftest.py @@ -703,8 +703,9 @@ def mock_svn_repository(tmpdir_factory): def mutable_mock_env_path(tmpdir_factory): """Fixture for mocking the internal spack environments directory.""" saved_path = spack.environment.env_path - spack.environment.env_path = str(tmpdir_factory.mktemp('mock-env-path')) - yield spack.environment.env_path + mock_path = tmpdir_factory.mktemp('mock-env-path') + spack.environment.env_path = str(mock_path) + yield mock_path spack.environment.env_path = saved_path |