
Fixup common tests * Remove requirement for Python 2.6 * Skip new failing test Windows: Update url util to handle Windows paths (#27959) * update url util to handle windows paths * Update tests to handle fixed url handling * canonicalize path only when the path type matches the host platform * Skip some url tests on Windows Co-authored-by: Omar Padron <omar.padron@kitware.com> Use threading.TIMEOUT_MAX when available (#24246) This value was introduced in Python 3.2. Specifying a timeout greater than this value will raise an OverflowError. Co-authored-by: Lou Lawrence <lou.lawrence@kitware.com> Co-authored-by: John Parent <john.parent@kitware.com> Co-authored-by: Betsy McPhail <betsy.mcphail@kitware.com>
95 lines
2.7 KiB
Python
95 lines
2.7 KiB
Python
# 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)
|
|
|
|
"""Tests for the `spack verify` command"""
|
|
import os
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
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')
|
|
|
|
|
|
@pytest.mark.skipif(sys.platform == 'win32', reason="Error on Win")
|
|
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")
|
|
|
|
data = spack.verify.create_manifest_entry(filepath)
|
|
|
|
manifest_file = os.path.join(metadir,
|
|
spack.store.layout.manifest_file_name)
|
|
|
|
with open(manifest_file, 'w') as f:
|
|
sjson.dump({filepath: data}, f)
|
|
|
|
results = verify('-f', filepath, fail_on_error=False)
|
|
print(results)
|
|
assert not results
|
|
|
|
os.utime(filepath, (0, 0))
|
|
with open(filepath, 'w') as f:
|
|
f.write("I changed.")
|
|
|
|
results = verify('-f', filepath, fail_on_error=False)
|
|
|
|
expected = ['hash']
|
|
mtime = os.stat(filepath).st_mtime
|
|
if mtime != data['time']:
|
|
expected.append('mtime')
|
|
|
|
assert results
|
|
assert filepath in results
|
|
assert all(x in results for x in expected)
|
|
|
|
results = verify('-fj', filepath, fail_on_error=False)
|
|
res = sjson.load(results)
|
|
assert len(res) == 1
|
|
errors = res.pop(filepath)
|
|
assert sorted(errors) == sorted(expected)
|
|
|
|
|
|
@pytest.mark.skipif(sys.platform == 'win32', reason="Error on Win")
|
|
def test_single_spec_verify_cmd(tmpdir, mock_packages, mock_archive,
|
|
mock_fetch, config, install_mockery):
|
|
# Test the verify command interface to verify a single spec
|
|
install('libelf')
|
|
s = spack.spec.Spec('libelf').concretized()
|
|
prefix = s.prefix
|
|
hash = s.dag_hash()
|
|
|
|
results = verify('/%s' % hash, fail_on_error=False)
|
|
assert not results
|
|
|
|
new_file = os.path.join(prefix, 'new_file_for_verify_test')
|
|
with open(new_file, 'w') as f:
|
|
f.write('New file')
|
|
|
|
results = verify('/%s' % hash, fail_on_error=False)
|
|
assert new_file in results
|
|
assert 'added' in results
|
|
|
|
results = verify('-j', '/%s' % hash, fail_on_error=False)
|
|
res = sjson.load(results)
|
|
assert len(res) == 1
|
|
assert res[new_file] == ['added']
|