forked from spack/spack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add template creation test, --skip-editor option (spack#11970)
* Add template creation test * Added --skip-editor option to "spack create": normally "spack create" opens an editor for the user after generating a package file; when the --skip-editor option is used, "spack create" only generates the package file and does not open an editor * Added --skip-editor option to bash completion
- Loading branch information
1 parent
505ad89
commit d615d0a
Showing
3 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# 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 os | ||
import pytest | ||
|
||
import spack.cmd.create | ||
import spack.util.editor | ||
|
||
from spack.main import SpackCommand | ||
|
||
|
||
create = SpackCommand('create') | ||
|
||
|
||
@pytest.fixture("module") | ||
def cmd_create_repo(tmpdir_factory): | ||
repo_namespace = 'cmd_create_repo' | ||
repodir = tmpdir_factory.mktemp(repo_namespace) | ||
repodir.ensure(spack.repo.packages_dir_name, dir=True) | ||
yaml = repodir.join('repo.yaml') | ||
yaml.write(""" | ||
repo: | ||
namespace: cmd_create_repo | ||
""") | ||
|
||
repo = spack.repo.RepoPath(str(repodir)) | ||
with spack.repo.swap(repo): | ||
yield repo, repodir | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def parser(): | ||
"""Returns the parser for the module""" | ||
prs = argparse.ArgumentParser() | ||
spack.cmd.create.setup_parser(prs) | ||
return prs | ||
|
||
|
||
def test_create_template(parser, cmd_create_repo): | ||
"""Test template creation.""" | ||
repo, repodir = cmd_create_repo | ||
|
||
name = 'test-package' | ||
args = parser.parse_args(['--skip-editor', name]) | ||
spack.cmd.create.create(parser, args) | ||
|
||
filename = repo.filename_for_package_name(name) | ||
assert os.path.exists(filename) | ||
|
||
with open(filename, 'r') as package_file: | ||
content = ' '.join(package_file.readlines()) | ||
for entry in [r'TestPackage(Package)', r'def install(self']: | ||
assert content.find(entry) > -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters