def test_fetch_in_env(tmpdir, mock_archive, mock_stage, mock_fetch, install_mockery): SpackCommand("env")("create", "test") with ev.read("test"): SpackCommand("add")("python") with pytest.raises(SpackCommandError): SpackCommand("fetch")() SpackCommand("concretize")() SpackCommand("fetch")()
def test_spec_concretizer_args(mutable_config, mutable_database): """End-to-end test of CLI concretizer prefs. It's here to make sure that everything works from CLI options to `solver.py`, and that config options are not lost along the way. """ if spack.config.get('config:concretizer') == 'original': pytest.xfail('Known failure of the original concretizer') # remove two non-preferred mpileaks installations # so that reuse will pick up the zmpi one uninstall = SpackCommand("uninstall") uninstall("-y", "mpileaks^mpich") uninstall("-y", "mpileaks^mpich2") # get the hash of mpileaks^zmpi mpileaks_zmpi = spack.store.db.query_one("mpileaks^zmpi") h = mpileaks_zmpi.dag_hash()[:7] output = spec("--fresh", "-l", "mpileaks") assert h not in output output = spec("--reuse", "-l", "mpileaks") assert h in output
def test_env_install_single_spec(install_mockery, mock_fetch): env('create', 'test') install = SpackCommand('install') e = ev.read('test') with e: install('cmake-client') e = ev.read('test') assert e.user_specs[0].name == 'cmake-client' assert e.concretized_user_specs[0].name == 'cmake-client' assert e.specs_by_hash[e.concretized_order[0]].name == 'cmake-client'
def test_reuse_after_help(): """Test `spack help` can be called twice with the same SpackCommand.""" help_cmd = SpackCommand('help') help_cmd() # This second invocation will somehow fail because the parser no # longer works after add_all_commands() is called in # SpackArgumentParser.format_help_sections(). # # TODO: figure out why this doesn't work properly and change this # test to use a single SpackCommand. # # It seems that parse_known_args() finds "too few arguments" the # second time through b/c add_all_commands() ends up leaving extra # positionals in the parser. But this used to work before we loaded # commands lazily. help_cmd()
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import platform import pytest import spack from spack.main import SpackCommand python = SpackCommand('python') def test_python(): out = python('-c', 'import spack; print(spack.spack_version)') assert out.strip() == spack.spack_version def test_python_version(): out = python('-V') assert platform.python_version() in out def test_python_with_module(): # pytest rewrites a lot of modules, which interferes with runpy, so # it's hard to test this. Trying to import a module like sys, that # has no code associated with it, raises an error reliably in python # 2 and 3, which indicates we successfully ran runpy.run_module. with pytest.raises(ImportError, match="No code object"):
# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import pytest from spack.main import SpackCommand import spack.store from spack.database import InstallStatuses install = SpackCommand('install') uninstall = SpackCommand('uninstall') deprecate = SpackCommand('deprecate') find = SpackCommand('find') activate = SpackCommand('activate') def test_deprecate(mock_packages, mock_archive, mock_fetch, install_mockery): install('[email protected]') install('[email protected]') all_installed = spack.store.db.query() assert len(all_installed) == 2 deprecate('-y', '[email protected]', '[email protected]') non_deprecated = spack.store.db.query() all_available = spack.store.db.query(installed=any) assert all_available == all_installed assert non_deprecated == spack.store.db.query('[email protected]')
import llnl.util.filesystem as fs import spack.config import spack.compilers as compilers import spack.hash_types as ht import spack.package import spack.cmd.install from spack.error import SpackError from spack.spec import Spec, CompilerSpec from spack.main import SpackCommand import spack.environment as ev from six.moves.urllib.error import HTTPError, URLError install = SpackCommand('install') env = SpackCommand('env') add = SpackCommand('add') @pytest.fixture() def noop_install(monkeypatch): def noop(*args, **kwargs): pass monkeypatch.setattr(spack.package.PackageBase, 'do_install', noop) def test_install_package_and_dependency(tmpdir, mock_packages, mock_archive, mock_fetch, config, install_mockery):
import spack.environment as ev from spack.cmd.env import _env_create from spack.spec import Spec from spack.main import SpackCommand from spack.stage import stage_prefix from spack.spec_list import SpecListError from spack.test.conftest import MockPackage, MockPackageMultiRepo import spack.util.spack_json as sjson # everything here uses the mock_env_path pytestmark = pytest.mark.usefixtures('mutable_mock_env_path', 'config', 'mutable_mock_repo') env = SpackCommand('env') install = SpackCommand('install') add = SpackCommand('add') remove = SpackCommand('remove') concretize = SpackCommand('concretize') stage = SpackCommand('stage') uninstall = SpackCommand('uninstall') find = SpackCommand('find') def check_mpileaks_and_deps_in_view(viewdir): """Check that the expected install directories exist.""" assert os.path.exists(str(viewdir.join('.spack', 'mpileaks'))) assert os.path.exists(str(viewdir.join('.spack', 'libdwarf')))
import spack.cmd.uninstall as uninstall import spack.cmd.mirror as mirror from spack.main import SpackCommand import spack.mirror import spack.util.gpg from spack.directory_layout import YamlDirectoryLayout from spack.spec import Spec def_install_path_scheme = '${ARCHITECTURE}/${COMPILERNAME}-${COMPILERVER}/${PACKAGE}-${VERSION}-${HASH}' # noqa: E501 ndef_install_path_scheme = '${PACKAGE}/${VERSION}/${ARCHITECTURE}-${COMPILERNAME}-${COMPILERVER}-${HASH}' # noqa: E501 mirror_path_def = None mirror_path_rel = None mirror_cmd = SpackCommand('mirror') install_cmd = SpackCommand('install') uninstall_cmd = SpackCommand('uninstall') buildcache_cmd = SpackCommand('buildcache') @pytest.fixture(scope='function') def cache_directory(tmpdir): old_cache_path = spack.caches.fetch_cache tmpdir.ensure('fetch_cache', dir=True) fsc = spack.fetch_strategy.FsCache(str(tmpdir.join('fetch_cache'))) spack.config.caches = fsc yield spack.config.caches tmpdir.join('fetch_cache').remove() spack.config.caches = old_cache_path
from six.moves import builtins import llnl.util.filesystem as fs import spack.cmd.install import spack.compilers as compilers import spack.config import spack.environment as ev import spack.hash_types as ht import spack.package import spack.util.executable from spack.error import SpackError from spack.main import SpackCommand from spack.spec import CompilerSpec, Spec install = SpackCommand('install') env = SpackCommand('env') add = SpackCommand('add') mirror = SpackCommand('mirror') uninstall = SpackCommand('uninstall') buildcache = SpackCommand('buildcache') find = SpackCommand('find') @pytest.fixture() def noop_install(monkeypatch): def noop(*args, **kwargs): pass monkeypatch.setattr(spack.installer.PackageInstaller, 'install', noop)
# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import argparse import json import pytest import spack.cmd as cmd import spack.cmd.find from spack.main import SpackCommand from spack.spec import Spec from spack.util.pattern import Bunch find = SpackCommand('find') base32_alphabet = 'abcdefghijklmnopqrstuvwxyz234567' @pytest.fixture(scope='module') def parser(): """Returns the parser for the module command""" prs = argparse.ArgumentParser() spack.cmd.find.setup_parser(prs) return prs @pytest.fixture() def specs(): s = []
def test_help_spec(): """Test the spack help --spec flag""" help_cmd = SpackCommand('help') out = help_cmd('--spec') assert 'spec expression syntax:' in out
# Copyright 2013-2022 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import re import sys import pytest import spack.repo from spack.cmd.url import name_parsed_correctly, url_summary, version_parsed_correctly from spack.main import SpackCommand from spack.url import UndetectableVersionError url = SpackCommand('url') class MyPackage: def __init__(self, name, versions): self.name = name self.versions = versions def test_name_parsed_correctly(): # Expected True assert name_parsed_correctly(MyPackage('netcdf', []), 'netcdf') assert name_parsed_correctly(MyPackage('r-devtools', []), 'devtools') assert name_parsed_correctly(MyPackage('py-numpy', []), 'numpy') assert name_parsed_correctly(MyPackage('octave-splines', []), 'splines') assert name_parsed_correctly(MyPackage('th-data', []), 'TH.data') assert name_parsed_correctly(MyPackage('imagemagick', []), 'ImageMagick')
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import argparse import os import pytest import spack.config import spack.package import spack.cmd.install from spack.main import SpackCommand install = SpackCommand('install') spack_test = SpackCommand('test') def test_test_package_not_installed( tmpdir, mock_packages, mock_archive, mock_fetch, config, install_mockery_mutable_config, mock_test_stage): output = spack_test('run', 'libdwarf') assert "No installed packages match spec libdwarf" in output @pytest.mark.parametrize('arguments,expected', [ (['run'], spack.config.get('config:dirty')), # default from config file (['run', '--clean'], False),
def test_help(): """Sanity check the help command to make sure it works.""" help_cmd = SpackCommand('help') out = help_cmd() assert 'These are common spack commands:' in out
# Copyright 2013-2018 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import pytest from spack.main import SpackCommand, SpackCommandError info = SpackCommand('env') @pytest.mark.parametrize('pkg', [('zlib', ), ('zlib', '--')]) @pytest.mark.usefixtures('config') def test_it_just_runs(pkg): info(*pkg) @pytest.mark.parametrize('pkg,error_cls', [('zlib libszip', SpackCommandError), ('', IndexError)]) @pytest.mark.usefixtures('config') def test_it_just_fails(pkg, error_cls): with pytest.raises(error_cls): info(pkg)
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import re import pytest from llnl.util.tty.color import color_when import spack.store from spack.main import SpackCommand dependencies = SpackCommand('dependencies') mpis = ['mpich', 'mpich2', 'multi-provider-mpi', 'zmpi'] mpi_deps = ['fake'] def test_direct_dependencies(mock_packages): out = dependencies('mpileaks') actual = set(re.split(r'\s+', out.strip())) expected = set(['callpath'] + mpis) assert expected == actual def test_transitive_dependencies(mock_packages): out = dependencies('--transitive', 'mpileaks') actual = set(re.split(r'\s+', out.strip())) expected = set(['callpath', 'dyninst', 'libdwarf', 'libelf'] + mpis +
import pytest from llnl.util.filesystem import working_dir import spack.cmd import spack.paths import spack.util.spack_json as sjson from spack.main import SpackCommand from spack.util.executable import which pytestmark = pytest.mark.skipif(not which('git') or not spack.cmd.spack_is_git_repo(), reason="needs git") blame = SpackCommand('blame') def test_blame_by_modtime(mock_packages): """Sanity check the blame command to make sure it works.""" out = blame('--time', 'mpich') assert 'LAST_COMMIT' in out assert 'AUTHOR' in out assert 'EMAIL' in out def test_blame_by_percent(mock_packages): """Sanity check the blame command to make sure it works.""" out = blame('--percent', 'mpich') assert 'LAST_COMMIT' in out assert 'AUTHOR' in out
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import os import pytest import llnl.util.filesystem as fs import spack.environment as ev import spack.spec from spack.main import SpackCommand dev_build = SpackCommand('dev-build') install = SpackCommand('install') env = SpackCommand('env') def test_dev_build_basics(tmpdir, mock_packages, install_mockery): spec = spack.spec.Spec('[email protected] dev_path=%s' % tmpdir) spec.concretize() assert 'dev_path' in spec.variants with tmpdir.as_cwd(): with open(spec.package.filename, 'w') as f: f.write(spec.package.original_string) dev_build('[email protected]')
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import pytest import os from llnl.util.filesystem import mkdirp import spack.config import spack.environment as ev from spack.main import SpackCommand config = SpackCommand('config') env = SpackCommand('env') def test_get_config_scope(mock_low_high_config): assert config('get', 'compilers').strip() == 'compilers: {}' def test_get_config_scope_merged(mock_low_high_config): low_path = mock_low_high_config.scopes['low'].path high_path = mock_low_high_config.scopes['high'].path mkdirp(low_path) mkdirp(high_path) with open(os.path.join(low_path, 'repos.yaml'), 'w') as f: f.write('''\ repos:
def test_help_all(): """Test the spack help --all flag""" help_cmd = SpackCommand('help') out = help_cmd('--all') assert 'Complete list of spack commands:' in out
cmake_cfg = pkgs_cfg['cmake'] cmake_externals = cmake_cfg['externals'] assert {'spec': '*****@*****.**', 'prefix': '/x/y1/'} in cmake_externals assert {'spec': '[email protected]', 'prefix': '/x/y2/'} in cmake_externals def test_get_executables(working_env, mock_executable): cmake_path1 = mock_executable("cmake", output="echo cmake version 1.foo") os.environ['PATH'] = ':'.join([os.path.dirname(cmake_path1)]) path_to_exe = spack.cmd.external._get_system_executables() assert path_to_exe[cmake_path1] == 'cmake' external = SpackCommand('external') def test_find_external_cmd(mutable_config, working_env, mock_executable): """Test invoking 'spack external find' with additional package arguments, which restricts the set of packages that Spack looks for. """ cmake_path1 = mock_executable("cmake", output="echo cmake version 1.foo") prefix = os.path.dirname(os.path.dirname(cmake_path1)) os.environ['PATH'] = ':'.join([os.path.dirname(cmake_path1)]) external('find', 'cmake') pkgs_cfg = spack.config.get('packages') cmake_cfg = pkgs_cfg['cmake'] cmake_externals = cmake_cfg['externals']
def test_help_subcommand(): """Test the spack help subcommand argument""" help_cmd = SpackCommand('help') out = help_cmd('help') assert 'get help on spack and its commands' in out
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) from spack.main import SpackCommand list = SpackCommand('list') def test_list(): output = list() assert 'cloverleaf3d' in output assert 'hdf5' in output def test_list_filter(mock_packages): output = list('py-*') assert 'py-extension1' in output assert 'py-extension2' in output assert 'py-extension3' in output assert 'python' not in output assert 'mpich' not in output output = list('py') assert 'py-extension1' in output assert 'py-extension2' in output assert 'py-extension3' in output assert 'python' in output assert 'mpich' not in output
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and # conditions of the GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## import argparse import pytest import spack.cmd.info from spack.main import SpackCommand info = SpackCommand('info') @pytest.fixture(scope='module') def parser(): """Returns the parser for the module command""" prs = argparse.ArgumentParser() spack.cmd.info.setup_parser(prs) return prs @pytest.fixture() def info_lines(): lines = [] return lines
# Copyright 2013-2022 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import os from spack.main import SpackCommand spack_test = SpackCommand('unit-test') cmd_test_py = os.path.join('lib', 'spack', 'spack', 'test', 'cmd', 'unit_test.py') def test_list(): output = spack_test('--list') assert "unit_test.py" in output assert "spec_semantics.py" in output assert "test_list" not in output def test_list_with_pytest_arg(): output = spack_test('--list', cmd_test_py) assert output.strip() == cmd_test_py def test_list_with_keywords(): # Here we removed querying with a "/" to separate directories # since the behavior is inconsistent across different pytest # versions, see https://stackoverflow.com/a/48814787/771663 output = spack_test('--list', '-k', 'unit_test.py')
def test_install_help_cdash(capsys): """Make sure `spack install --help-cdash` describes CDash arguments""" install_cmd = SpackCommand('install') out = install_cmd('--help-cdash') assert 'CDash URL' in out
# Copyright 2013-2022 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) from spack.main import SpackCommand cd = SpackCommand('cd') def test_cd(): """Sanity check the cd command to make sure it works.""" out = cd() assert "To set up shell support" in out
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import pytest import spack.store from spack.main import SpackCommand, SpackCommandError gc = SpackCommand('gc') mark = SpackCommand('mark') install = SpackCommand('install') uninstall = SpackCommand('uninstall') @pytest.mark.db def test_mark_mode_required(mutable_database): with pytest.raises(SystemExit): mark('-a') @pytest.mark.db def test_mark_spec_required(mutable_database): with pytest.raises(SpackCommandError): mark('-i') @pytest.mark.db def test_mark_all_explicit(mutable_database): mark('-e', '-a') gc('-y')
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) """Tests for the `spack verify` command""" import os import llnl.util.filesystem as fs import spack.spec import spack.store import spack.util.spack_json as sjson import spack.verify from spack.main import SpackCommand verify = SpackCommand('verify') install = SpackCommand('install') def test_single_file_verify_cmd(tmpdir): # Test the verify command interface to verifying a single file. filedir = os.path.join(str(tmpdir), 'a', 'b', 'c', 'd') filepath = os.path.join(filedir, 'file') metadir = os.path.join(str(tmpdir), spack.store.layout.metadata_dir) fs.mkdirp(filedir) fs.mkdirp(metadir) with open(filepath, 'w') as f: f.write("I'm a file")