Skip to content

Commit 6120afc

Browse files
committed
tests: move the test to modules/common.py
1 parent 9810f1b commit 6120afc

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/spack/spack/test/install.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import spack.store
1717
from spack.spec import Spec
1818
from spack.package import _spack_build_envfile, _spack_build_logfile
19-
import spack.modules.common
2019

2120

2221
def test_install_and_uninstall(install_mockery, mock_fetch, monkeypatch):
@@ -40,8 +39,6 @@ def find_nothing(*args):
4039
with pytest.raises(spack.repo.UnknownPackageError):
4140
spec.package
4241

43-
module_path = spack.modules.common.get_module('tcl', spec, True)
44-
assert module_path
4542
pkg.do_uninstall()
4643
except Exception:
4744
pkg.remove_prefix()

lib/spack/spack/test/modules/common.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import spack.spec
1212
import spack.modules.tcl
1313
from spack.modules.common import UpstreamModuleIndex
14+
from spack.spec import Spec
1415

1516
import spack.error
1617

@@ -183,3 +184,31 @@ def test_get_module_upstream():
183184
assert m1_path == '/path/to/a'
184185
finally:
185186
spack.modules.common.upstream_module_index = old_index
187+
188+
def test_load_installed_package_not_in_repo(install_mockery, mock_fetch, monkeypatch):
189+
# Get a basic concrete spec for the trivial install package.
190+
spec = Spec('trivial-install-test-package')
191+
spec.concretize()
192+
assert spec.concrete
193+
194+
# Get the package
195+
pkg = spec.package
196+
197+
def find_nothing(*args):
198+
raise spack.repo.UnknownPackageError(
199+
'Repo package access is disabled for test')
200+
201+
try:
202+
pkg.do_install()
203+
204+
spec._package = None
205+
monkeypatch.setattr(spack.repo, 'get', find_nothing)
206+
with pytest.raises(spack.repo.UnknownPackageError):
207+
spec.package
208+
209+
module_path = spack.modules.common.get_module('tcl', spec, True)
210+
assert module_path
211+
pkg.do_uninstall()
212+
except Exception:
213+
pkg.remove_prefix()
214+
raise

0 commit comments

Comments
 (0)