Make env (de)activate error with -e, -E, -D flags (#25625)
* Make sure that spack -e. env activate b and spack -e. env deactivate error * Add a test
This commit is contained in:
parent
f5d4f5bdac
commit
74389472ab
@ -88,6 +88,11 @@ def env_activate(args):
|
|||||||
)
|
)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
# Error out when -e, -E, -D flags are given, cause they are ambiguous.
|
||||||
|
if args.env or args.no_env or args.env_dir:
|
||||||
|
tty.die('Calling spack env activate with --env, --env-dir and --no-env '
|
||||||
|
'is ambiguous')
|
||||||
|
|
||||||
if ev.exists(env) and not args.dir:
|
if ev.exists(env) and not args.dir:
|
||||||
spack_env = ev.root(env)
|
spack_env = ev.root(env)
|
||||||
short_name = env
|
short_name = env
|
||||||
@ -137,6 +142,11 @@ def env_deactivate(args):
|
|||||||
)
|
)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
# Error out when -e, -E, -D flags are given, cause they are ambiguous.
|
||||||
|
if args.env or args.no_env or args.env_dir:
|
||||||
|
tty.die('Calling spack env deactivate with --env, --env-dir and --no-env '
|
||||||
|
'is ambiguous')
|
||||||
|
|
||||||
if 'SPACK_ENV' not in os.environ:
|
if 'SPACK_ENV' not in os.environ:
|
||||||
tty.die('No environment is currently active.')
|
tty.die('No environment is currently active.')
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
|
from argparse import Namespace
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from six import StringIO
|
from six import StringIO
|
||||||
@ -11,6 +12,7 @@
|
|||||||
import llnl.util.filesystem as fs
|
import llnl.util.filesystem as fs
|
||||||
import llnl.util.link_tree
|
import llnl.util.link_tree
|
||||||
|
|
||||||
|
import spack.cmd.env
|
||||||
import spack.environment as ev
|
import spack.environment as ev
|
||||||
import spack.hash_types as ht
|
import spack.hash_types as ht
|
||||||
import spack.modules
|
import spack.modules
|
||||||
@ -2632,3 +2634,24 @@ def test_query_develop_specs():
|
|||||||
|
|
||||||
assert e.is_develop(Spec('mpich'))
|
assert e.is_develop(Spec('mpich'))
|
||||||
assert not e.is_develop(Spec('mpileaks'))
|
assert not e.is_develop(Spec('mpileaks'))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('method', [
|
||||||
|
spack.cmd.env.env_activate,
|
||||||
|
spack.cmd.env.env_deactivate
|
||||||
|
])
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'env,no_env,env_dir',
|
||||||
|
[
|
||||||
|
('b', False, None),
|
||||||
|
(None, True, None),
|
||||||
|
(None, False, 'path/'),
|
||||||
|
])
|
||||||
|
def test_activation_and_deactiviation_ambiguities(method, env, no_env, env_dir, capsys):
|
||||||
|
"""spack [-e x | -E | -D x/] env [activate | deactivate] y are ambiguous"""
|
||||||
|
args = Namespace(shell='sh', activate_env='a',
|
||||||
|
env=env, no_env=no_env, env_dir=env_dir)
|
||||||
|
with pytest.raises(SystemExit):
|
||||||
|
method(args)
|
||||||
|
_, err = capsys.readouterr()
|
||||||
|
assert 'is ambiguous' in err
|
||||||
|
Loading…
Reference in New Issue
Block a user