def test_install_runtests_all(monkeypatch, mock_packages, install_mockery): def check(pkg): assert pkg.run_tests monkeypatch.setattr(spack.package.PackageBase, 'unit_test_check', check) install('--test=all', 'a') install('--run-tests', 'a')
def test_junit_output_with_errors( exc_typename, msg, mock_packages, mock_archive, mock_fetch, install_mockery, config, tmpdir, monkeypatch): def just_throw(*args, **kwargs): exc_type = getattr(builtins, exc_typename) raise exc_type(msg) monkeypatch.setattr(spack.package.PackageBase, 'do_install', just_throw) with tmpdir.as_cwd(): install('--log-format=junit', '--log-file=test.xml', 'libdwarf') files = tmpdir.listdir() filename = tmpdir.join('test.xml') assert filename in files content = filename.open().read() # Count failures and errors correctly assert 'tests="1"' in content assert 'failures="0"' in content assert 'errors="1"' in content # We want to have both stdout and stderr assert '<system-out>' in content assert msg in content
def test_install_with_source( mock_packages, mock_archive, mock_fetch, config, install_mockery): """Verify that source has been copied into place.""" install('--source', '--keep-stage', 'trivial-install-test-package') spec = Spec('trivial-install-test-package').concretized() src = os.path.join( spec.prefix.share, 'trivial-install-test-package', 'src') assert filecmp.cmp(os.path.join(mock_archive.path, 'configure'), os.path.join(src, 'configure'))
def test_build_warning_output(tmpdir, mock_fetch, install_mockery, capfd): with capfd.disabled(): msg = '' try: install('build-warnings') except spack.build_environment.ChildError as e: msg = e.long_message assert 'WARNING: ALL CAPITAL WARNING!' in msg assert 'foo.c:89: warning: some weird warning!' in msg
def test_build_error_output(tmpdir, mock_fetch, install_mockery, capfd): with capfd.disabled(): msg = '' try: install('build-error') assert False, "no exception was raised!" except spack.build_environment.ChildError as e: msg = e.long_message assert 'configure: error: in /path/to/some/file:' in msg assert 'configure: error: cannot run C compiled programs.' in msg
def test_install_overwrite( mock_packages, mock_archive, mock_fetch, config, install_mockery ): # It's not possible to overwrite something that is not yet installed with pytest.raises(AssertionError): install('--overwrite', 'libdwarf') # --overwrite requires a single spec with pytest.raises(AssertionError): install('--overwrite', 'libdwarf', 'libelf') # Try to install a spec and then to reinstall it. spec = Spec('libdwarf') spec.concretize() install('libdwarf') assert os.path.exists(spec.prefix) expected_md5 = fs.hash_directory(spec.prefix) # Modify the first installation to be sure the content is not the same # as the one after we reinstalled with open(os.path.join(spec.prefix, 'only_in_old'), 'w') as f: f.write('This content is here to differentiate installations.') bad_md5 = fs.hash_directory(spec.prefix) assert bad_md5 != expected_md5 install('--overwrite', '-y', 'libdwarf') assert os.path.exists(spec.prefix) assert fs.hash_directory(spec.prefix) == expected_md5 assert fs.hash_directory(spec.prefix) != bad_md5
def test_install_mix_cli_and_files(clispecs, filespecs, tmpdir): args = clispecs for spec in filespecs: filepath = tmpdir.join(spec + '.yaml') args = ['-f', str(filepath)] + args s = Spec(spec) s.concretize() with filepath.open('w') as f: s.to_yaml(f) install(*args, fail_on_error=False) assert install.returncode == 0
def test_install_package_and_dependency( tmpdir, mock_packages, mock_archive, mock_fetch, config, install_mockery): with tmpdir.as_cwd(): install('--log-format=junit', '--log-file=test.xml', 'libdwarf') files = tmpdir.listdir() filename = tmpdir.join('test.xml') assert filename in files content = filename.open().read() assert 'tests="2"' in content assert 'failures="0"' in content assert 'errors="0"' in content
def test_extra_files_are_archived(mock_packages, mock_archive, mock_fetch, config, install_mockery): s = Spec('archive-files') s.concretize() install('archive-files') archive_dir = os.path.join( spack.store.layout.metadata_path(s), 'archived-files' ) config_log = os.path.join(archive_dir, 'config.log') assert os.path.exists(config_log) errors_txt = os.path.join(archive_dir, 'errors.txt') assert os.path.exists(errors_txt)
def test_cdash_upload_clean_build(tmpdir, mock_fetch, install_mockery, capfd): # capfd interferes with Spack's capturing with capfd.disabled(): with tmpdir.as_cwd(): with pytest.raises((HTTPError, URLError)): install( '--log-file=cdash_reports', '--cdash-upload-url=http://localhost/fakeurl/submit.php?project=Spack', 'a') report_dir = tmpdir.join('cdash_reports') assert report_dir in tmpdir.listdir() report_file = report_dir.join('Build.xml') assert report_file in report_dir.listdir() content = report_file.open().read() assert '</Build>' in content assert '<Text>' not in content
def test_cdash_report_concretization_error(tmpdir, mock_fetch, install_mockery, capfd, conflict_spec): # capfd interferes with Spack's capturing with capfd.disabled(): with tmpdir.as_cwd(): with pytest.raises(SpackError): install( '--log-format=cdash', '--log-file=cdash_reports', conflict_spec) report_dir = tmpdir.join('cdash_reports') assert report_dir in tmpdir.listdir() report_file = report_dir.join('Update.xml') assert report_file in report_dir.listdir() content = report_file.open().read() assert '<UpdateReturnStatus>Conflicts in concretized spec' \ in content
def test_cdash_upload_build_error(tmpdir, mock_fetch, install_mockery, capfd): # capfd interferes with Spack's capturing with capfd.disabled(): with tmpdir.as_cwd(): with pytest.raises((HTTPError, URLError)): install( '--log-format=cdash', '--log-file=cdash_reports', '--cdash-upload-url=http://localhost/fakeurl/submit.php?project=Spack', 'build-error') report_dir = tmpdir.join('cdash_reports') assert report_dir in tmpdir.listdir() report_file = report_dir.join('Build.xml') assert report_file in report_dir.listdir() content = report_file.open().read() assert '<Text>configure: error: in /path/to/some/file:</Text>' in content
def test_install_output_on_build_error(mock_packages, mock_archive, mock_fetch, config, install_mockery, capfd): # capfd interferes with Spack's capturing with capfd.disabled(): out = install('build-error', fail_on_error=False) assert isinstance(install.error, spack.build_environment.ChildError) assert install.error.name == 'ProcessError' assert 'configure: error: in /path/to/some/file:' in out assert 'configure: error: cannot run C compiled programs.' in out
def test_install_from_file(spec, concretize, error_code, tmpdir): if concretize: spec.concretize() specfile = tmpdir.join('spec.yaml') with specfile.open('w') as f: spec.to_yaml(f) # Relative path to specfile (regression for #6906) with fs.working_dir(specfile.dirname): # A non-concrete spec will fail to be installed install('-f', specfile.basename, fail_on_error=False) assert install.returncode == error_code # Absolute path to specfile (regression for #6983) install('-f', str(specfile), fail_on_error=False) assert install.returncode == error_code
def test_install_package_already_installed( tmpdir, mock_packages, mock_archive, mock_fetch, config, install_mockery): with tmpdir.as_cwd(): install('libdwarf') install('--log-format=junit', '--log-file=test.xml', 'libdwarf') files = tmpdir.listdir() filename = tmpdir.join('test.xml') assert filename in files content = filename.open().read() assert 'tests="2"' in content assert 'failures="0"' in content assert 'errors="0"' in content skipped = [line for line in content.split('\n') if 'skipped' in line] assert len(skipped) == 2
def test_show_log_on_error(mock_packages, mock_archive, mock_fetch, config, install_mockery, capfd): """Make sure --show-log-on-error works.""" with capfd.disabled(): out = install('--show-log-on-error', 'build-error', fail_on_error=False) assert isinstance(install.error, spack.build_environment.ChildError) assert install.error.pkg.name == 'build-error' assert 'Full build log:' in out errors = [line for line in out.split('\n') if 'configure: error: cannot run C compiled programs' in line] assert len(errors) == 2
def test_cdash_report_concretization_error(tmpdir, mock_fetch, install_mockery, capfd, conflict_spec): # capfd interferes with Spack's capturing with capfd.disabled(): with tmpdir.as_cwd(): with pytest.raises(SpackError): install( '--log-format=cdash', '--log-file=cdash_reports', conflict_spec) report_dir = tmpdir.join('cdash_reports') assert report_dir in tmpdir.listdir() report_file = report_dir.join('Update.xml') assert report_file in report_dir.listdir() content = report_file.open().read() assert '<UpdateReturnStatus>' in content # The message is different based on using the # new or the old concretizer expected_messages = ( 'Conflicts in concretized spec', 'A conflict was triggered', ) assert any(x in content for x in expected_messages)
def test_cache_only_fails(tmpdir, mock_fetch, install_mockery, capfd): # libelf from cache fails to install, which automatically removes the # the libdwarf build task with capfd.disabled(): out = install('--cache-only', 'libdwarf', fail_on_error=False) assert 'Failed to install libelf' in out assert 'Skipping build of libdwarf' in out assert 'was not installed' in out # Check that failure prefix locks are still cached failure_lock_prefixes = ','.join(spack.store.db._prefix_failures.keys()) assert 'libelf' in failure_lock_prefixes assert 'libdwarf' in failure_lock_prefixes
def test_show_log_on_error(mock_packages, mock_archive, mock_fetch, config, install_mockery, capfd): """Make sure --show-log-on-error works.""" with capfd.disabled(): out = install('--show-log-on-error', 'build-error', fail_on_error=False) assert isinstance(install.error, spack.build_environment.ChildError) assert install.error.pkg.name == 'build-error' assert 'Full build log:' in out # Message shows up for ProcessError (1), ChildError (1), and output (1) errors = [line for line in out.split('\n') if 'configure: error: cannot run C compiled programs' in line] assert len(errors) == 3
def test_junit_output_with_failures(tmpdir, exc_typename, msg): with tmpdir.as_cwd(): install( '--log-format=junit', '--log-file=test.xml', 'raiser', 'exc_type={0}'.format(exc_typename), 'msg="{0}"'.format(msg) ) files = tmpdir.listdir() filename = tmpdir.join('test.xml') assert filename in files content = filename.open().read() # Count failures and errors correctly assert 'tests="1"' in content assert 'failures="1"' in content assert 'errors="0"' in content # We want to have both stdout and stderr assert '<system-out>' in content assert msg in content
def test_show_log_on_error(mock_packages, mock_archive, mock_fetch, config, install_mockery, capfd): """ Make sure --show-log-on-error works. """ with capfd.disabled(): out = install('--show-log-on-error', 'build-error', fail_on_error=False) assert isinstance(install.error, spack.build_environment.ChildError) assert install.error.pkg.name == 'build-error' assert '==> Installing build-error' in out assert 'See build log for details:' in out
def test_install_from_file(spec, concretize, error_code, tmpdir): if concretize: spec.concretize() specfile = tmpdir.join('spec.yaml') with specfile.open('w') as f: spec.to_yaml(f) err_msg = 'does not contain a concrete spec' if error_code else '' # Relative path to specfile (regression for #6906) with fs.working_dir(specfile.dirname): # A non-concrete spec will fail to be installed out = install('-f', specfile.basename, fail_on_error=False) assert install.returncode == error_code assert err_msg in out # Absolute path to specfile (regression for #6983) out = install('-f', str(specfile), fail_on_error=False) assert install.returncode == error_code assert err_msg in out
def test_junit_output_with_errors(exc_typename, expected_exc, msg, mock_packages, mock_archive, mock_fetch, install_mockery, config, tmpdir, monkeypatch): def just_throw(*args, **kwargs): exc_type = getattr(builtins, exc_typename) raise exc_type(msg) monkeypatch.setattr(spack.installer.PackageInstaller, '_install_task', just_throw) with tmpdir.as_cwd(): install('--log-format=junit', '--log-file=test.xml', 'libdwarf', fail_on_error=False) assert isinstance(install.error, expected_exc) files = tmpdir.listdir() filename = tmpdir.join('test.xml') assert filename in files content = filename.open().read() # Only libelf error is reported (through libdwarf root spec). libdwarf # install is skipped and it is not an error. assert 'tests="1"' in content assert 'failures="0"' in content assert 'errors="1"' in content # Nothing should have succeeded assert 'errors="0"' not in content # We want to have both stdout and stderr assert '<system-out>' in content assert 'error message="{0}"'.format(msg) in content
def test_junit_output_with_failures(tmpdir, mock_test_stage, pkg_name, msgs): install(pkg_name) with tmpdir.as_cwd(): spack_test('run', '--log-format=junit', '--log-file=test.xml', pkg_name, fail_on_error=False) files = tmpdir.listdir() filename = tmpdir.join('test.xml') assert filename in files content = filename.open().read() # Count failures and errors correctly assert 'tests="1"' in content assert 'failures="1"' in content assert 'errors="0"' in content # We want to have both stdout and stderr assert '<system-out>' in content for msg in msgs: assert msg in content
def test_test_output(mock_test_stage, mock_packages, mock_archive, mock_fetch, install_mockery_mutable_config): """Ensure output printed from pkgs is captured by output redirection.""" install('printing-package') spack_test('run', '--alias', 'printpkg', 'printing-package') stage_files = os.listdir(mock_test_stage) assert len(stage_files) == 1 # Grab test stage directory contents testdir = os.path.join(mock_test_stage, stage_files[0]) testdir_files = os.listdir(testdir) # Grab the output from the test log testlog = list( filter(lambda x: x.endswith('out.txt') and x != 'results.txt', testdir_files)) outfile = os.path.join(testdir, testlog[0]) with open(outfile, 'r') as f: output = f.read() assert "BEFORE TEST" in output assert "true: expect command status in [" in output assert "AFTER TEST" in output assert "FAILED" not in output
def test_install_overwrite(mock_packages, mock_archive, mock_fetch, config, install_mockery): # Try to install a spec and then to reinstall it. spec = Spec('libdwarf') spec.concretize() install('libdwarf') assert os.path.exists(spec.prefix) expected_md5 = fs.hash_directory(spec.prefix) # Modify the first installation to be sure the content is not the same # as the one after we reinstalled with open(os.path.join(spec.prefix, 'only_in_old'), 'w') as f: f.write('This content is here to differentiate installations.') bad_md5 = fs.hash_directory(spec.prefix) assert bad_md5 != expected_md5 install('--overwrite', '-y', 'libdwarf') assert os.path.exists(spec.prefix) assert fs.hash_directory(spec.prefix) == expected_md5 assert fs.hash_directory(spec.prefix) != bad_md5
def test_install_overwrite_multiple( mock_packages, mock_archive, mock_fetch, config, install_mockery ): # Try to install a spec and then to reinstall it. libdwarf = Spec('libdwarf') libdwarf.concretize() install('libdwarf') cmake = Spec('cmake') cmake.concretize() install('cmake') ld_manifest = os.path.join(libdwarf.prefix, spack.store.layout.metadata_dir, spack.store.layout.manifest_file_name) ld_ignores = [ld_manifest, libdwarf.package.times_log_path] assert os.path.exists(libdwarf.prefix) expected_libdwarf_md5 = fs.hash_directory(libdwarf.prefix, ignore=ld_ignores) cm_manifest = os.path.join(cmake.prefix, spack.store.layout.metadata_dir, spack.store.layout.manifest_file_name) cm_ignores = [cm_manifest, cmake.package.times_log_path] assert os.path.exists(cmake.prefix) expected_cmake_md5 = fs.hash_directory(cmake.prefix, ignore=cm_ignores) # Modify the first installation to be sure the content is not the same # as the one after we reinstalled with open(os.path.join(libdwarf.prefix, 'only_in_old'), 'w') as f: f.write('This content is here to differentiate installations.') with open(os.path.join(cmake.prefix, 'only_in_old'), 'w') as f: f.write('This content is here to differentiate installations.') bad_libdwarf_md5 = fs.hash_directory(libdwarf.prefix, ignore=ld_ignores) bad_cmake_md5 = fs.hash_directory(cmake.prefix, ignore=cm_ignores) assert bad_libdwarf_md5 != expected_libdwarf_md5 assert bad_cmake_md5 != expected_cmake_md5 install('--overwrite', '-y', 'libdwarf', 'cmake') assert os.path.exists(libdwarf.prefix) assert os.path.exists(cmake.prefix) ld_hash = fs.hash_directory(libdwarf.prefix, ignore=ld_ignores) cm_hash = fs.hash_directory(cmake.prefix, ignore=cm_ignores) assert ld_hash == expected_libdwarf_md5 assert cm_hash == expected_cmake_md5 assert ld_hash != bad_libdwarf_md5 assert cm_hash != bad_cmake_md5
def test_install_runtests(): assert not spack.package_testing._test_all assert not spack.package_testing.packages_to_test install('--test=root', 'dttop') assert not spack.package_testing._test_all assert spack.package_testing.packages_to_test == set(['dttop']) spack.package_testing.clear() install('--test=all', 'a') assert spack.package_testing._test_all assert not spack.package_testing.packages_to_test spack.package_testing.clear() install('--run-tests', 'a') assert spack.package_testing._test_all assert not spack.package_testing.packages_to_test spack.package_testing.clear() assert not spack.package_testing._test_all assert not spack.package_testing.packages_to_test
def test_compiler_bootstrap_from_binary_mirror(install_mockery_mutable_config, mock_packages, mock_fetch, mock_archive, mutable_config, monkeypatch, tmpdir): """ Make sure installing compiler from buildcache registers compiler """ # Create a temp mirror directory for buildcache usage mirror_dir = tmpdir.join('mirror_dir') mirror_url = 'file://{0}'.format(mirror_dir.strpath) # Install a compiler, because we want to put it in a buildcache install('[email protected]') # Put installed compiler in the buildcache buildcache('create', '-u', '-a', '-f', '-d', mirror_dir.strpath, '[email protected]') # Now uninstall the compiler uninstall('-y', '[email protected]') monkeypatch.setattr(spack.concretize.Concretizer, 'check_for_compiler_existence', False) spack.config.set('config:install_missing_compilers', True) assert CompilerSpec('[email protected]') not in compilers.all_compiler_specs() # Configure the mirror where we put that buildcache w/ the compiler mirror('add', 'test-mirror', mirror_url) # Now make sure that when the compiler is installed from binary mirror, # it also gets configured as a compiler. Test succeeds if it does not # raise an error install('--no-check-signature', '--cache-only', '--only', 'dependencies', 'b%[email protected]') install('--no-cache', '--only', 'package', 'b%[email protected]')
def test_install_invalid_spec(invalid_spec): # Make sure that invalid specs raise a SpackError with pytest.raises(SpackError, match='Unexpected token'): install(invalid_spec)
def test_install_runtests_root(monkeypatch, mock_packages, install_mockery): def check(pkg): assert pkg.run_tests == (pkg.name == 'dttop') monkeypatch.setattr(spack.package.PackageBase, 'unit_test_check', check) install('--test=root', 'dttop')
def test_install_no_add_in_env(tmpdir, mock_fetch, install_mockery, mutable_mock_env_path): # To test behavior of --no-add option, we create the following environment: # # mpileaks # ^callpath # ^dyninst # ^[email protected] # or latest, really # ^libdwarf # ^mpich # [email protected] # a~bvv # ^b # a # ^b e = ev.create('test') e.add('mpileaks') e.add('[email protected]') # so env has both root and dep libelf specs e.add('a') e.add('a ~bvv') e.concretize() env_specs = e.all_specs() a_spec = None b_spec = None mpi_spec = None # First find and remember some target concrete specs in the environment for e_spec in env_specs: if e_spec.satisfies(Spec('a ~bvv')): a_spec = e_spec elif e_spec.name == 'b': b_spec = e_spec elif e_spec.satisfies(Spec('mpi')): mpi_spec = e_spec assert (a_spec) assert (a_spec.concrete) assert (b_spec) assert (b_spec.concrete) assert (b_spec not in e.roots()) assert (mpi_spec) assert (mpi_spec.concrete) # Activate the environment with e: # Assert using --no-add with a spec not in the env fails inst_out = install('--no-add', 'boost', fail_on_error=False, output=str) assert ('no such spec exists in environment' in inst_out) # Ensure using --no-add with an ambiguous spec fails with pytest.raises(ev.SpackEnvironmentError) as err: inst_out = install('--no-add', 'a', output=str) assert ('a matches multiple specs in the env' in str(err)) # With "--no-add", install an unambiguous dependency spec (that already # exists as a dep in the environment) using --no-add and make sure it # gets installed (w/ deps), but is not added to the environment. install('--no-add', 'dyninst') find_output = find('-l', output=str) assert ('dyninst' in find_output) assert ('libdwarf' in find_output) assert ('libelf' in find_output) assert ('callpath' not in find_output) post_install_specs = e.all_specs() assert all([s in env_specs for s in post_install_specs]) # Make sure we can install a concrete dependency spec from a spec.yaml # file on disk, using the ``--no-add` option, and the spec is installed # but not added as a root mpi_spec_yaml_path = tmpdir.join('{0}.yaml'.format(mpi_spec.name)) with open(mpi_spec_yaml_path.strpath, 'w') as fd: fd.write(mpi_spec.to_yaml(hash=ht.full_hash)) install('--no-add', '-f', mpi_spec_yaml_path.strpath) assert (mpi_spec not in e.roots()) find_output = find('-l', output=str) assert (mpi_spec.name in find_output) # Without "--no-add", install an unambiguous depependency spec (that # already exists as a dep in the environment) without --no-add and make # sure it is added as a root of the environment as well as installed. assert (b_spec not in e.roots()) install('b') assert (b_spec in e.roots()) assert (b_spec not in e.uninstalled_specs()) # Without "--no-add", install a novel spec and make sure it is added # as a root and installed. install('bowtie') assert (any([s.name == 'bowtie' for s in e.roots()])) assert (not any([s.name == 'bowtie' for s in e.uninstalled_specs()]))
def test_install_conflicts(conflict_spec): # Make sure that spec with conflicts raises a SpackError with pytest.raises(SpackError): install(conflict_spec)
def test_install_runtests_notests(monkeypatch, mock_packages, install_mockery): def check(pkg): assert not pkg.run_tests monkeypatch.setattr(spack.package.PackageBase, 'unit_test_check', check) install('-v', 'dttop')
def test_install_output_on_python_error(mock_packages, mock_archive, mock_fetch, config, install_mockery): out = install('failing-build', fail_on_error=False) assert isinstance(install.error, spack.build_environment.ChildError) assert install.error.name == 'InstallError' assert 'raise InstallError("Expected failure.")' in out
def test_install_env_variables(mock_packages, mock_archive, mock_fetch, config, install_mockery): spec = Spec('libdwarf') spec.concretize() install('libdwarf') assert os.path.isfile(spec.package.install_env_path)
def test_install_help_does_not_show_cdash_options(capsys): """Make sure `spack install --help` does not describe CDash arguments""" with pytest.raises(SystemExit): install('--help') captured = capsys.readouterr() assert 'CDash URL' not in captured.out
def test_install_output_on_python_error( mock_packages, mock_archive, mock_fetch, config, install_mockery): out = install('failing-build', fail_on_error=False) assert isinstance(install.error, spack.build_environment.ChildError) assert install.error.name == 'InstallError' assert 'raise InstallError("Expected failure.")' in out
def test_test_list(mock_packages, mock_archive, mock_fetch, install_mockery_mutable_config): pkg_with_tests = 'printing-package' install(pkg_with_tests) output = spack_test("list") assert pkg_with_tests in output
def test_install_runtests_all(monkeypatch, mock_packages, install_mockery): def check(pkg): assert pkg.run_tests monkeypatch.setattr(spack.package.PackageBase, 'unit_test_check', check) install('--test=all', 'a')
def test_install_callbacks_fail(install_mockery, mock_fetch, name, method): output = install('--test=root', '--no-cache', name, fail_on_error=False) assert output.count(method) == 2 assert output.count('method not implemented') == 1 assert output.count('TestFailure: 1 tests failed') == 1