# 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
import pytest
from llnl.util.filesystem import mkdirp, touch, working_dir
import spack.config
import spack.repo
from spack.fetch_strategy import CvsFetchStrategy
from spack.spec import Spec
from spack.stage import Stage
from spack.util.executable import which
from spack.version import ver
pytestmark = pytest.mark.skipif(
not which('cvs'),
reason='requires CVS to be installed')
[docs]@pytest.mark.parametrize("type_of_test", ['default', 'branch', 'date'])
def test_fetch(
type_of_test,
mock_cvs_repository,
config,
mutable_mock_repo
):
"""Tries to:
1. Fetch the repo using a fetch strategy constructed with
supplied args (they depend on type_of_test).
2. Check whether the checkout is on the correct branch or date
3. Check if the test_file is in the checked out repository.
4. Add and remove some files, then reset the repo, and
ensure it's all there again.
CVS does not have the notion of a unique branch; branches and revisions
are managed separately for every file.
"""
# Retrieve the right test parameters
test = mock_cvs_repository.checks[type_of_test]
get_branch = mock_cvs_repository.get_branch
get_date = mock_cvs_repository.get_date
# Construct the package under test
spec = Spec('cvs-test')
spec.concretize()
pkg = spack.repo.get(spec)
pkg.versions[ver('cvs')] = test.args
# Enter the stage directory and check some properties
with pkg.stage:
pkg.do_stage()
with working_dir(pkg.stage.source_path):
# Check branch
if test.branch is not None:
assert get_branch() == test.branch
# Check date
if test.date is not None:
assert get_date() <= test.date
file_path = os.path.join(pkg.stage.source_path, test.file)
assert os.path.isdir(pkg.stage.source_path)
assert os.path.isfile(file_path)
os.unlink(file_path)
assert not os.path.isfile(file_path)
untracked_file = 'foobarbaz'
touch(untracked_file)
assert os.path.isfile(untracked_file)
pkg.do_restage()
assert not os.path.isfile(untracked_file)
assert os.path.isdir(pkg.stage.source_path)
assert os.path.isfile(file_path)