summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/cmd/repo.py
blob: 7fa5027699e580047e13c1b38c89700f5c2eff24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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.path

import pytest

import spack.main

repo = spack.main.SpackCommand('repo')


def test_help_option():
    # Test 'spack repo --help' to check basic import works
    # and the command exits successfully
    with pytest.raises(SystemExit):
        repo('--help')
    assert repo.returncode in (None, 0)


def test_create_add_list_remove(mutable_config, tmpdir):
    # Create a new repository and check that the expected
    # files are there
    repo('create', str(tmpdir), 'mockrepo')
    assert os.path.exists(os.path.join(str(tmpdir), 'repo.yaml'))

    # Add the new repository and check it appears in the list output
    repo('add', '--scope=site', str(tmpdir))
    output = repo('list', '--scope=site', output=str)
    assert 'mockrepo' in output

    # Then remove it and check it's not there
    repo('remove', '--scope=site', str(tmpdir))
    output = repo('list', '--scope=site', output=str)
    assert 'mockrepo' not in output