diff options
author | Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> | 2019-07-12 11:22:09 -0700 |
---|---|---|
committer | Peter Scheibel <scheibel1@llnl.gov> | 2019-07-12 11:22:09 -0700 |
commit | d615d0a1ec26aca94f7bbb6fd6881527b27d9b47 (patch) | |
tree | e1fcc2d9dd2f36f8337617e9b65a9a6909bc6194 /lib | |
parent | 505ad8960e6d9760ef6b7fd28ce231ae57a207b5 (diff) | |
download | spack-d615d0a1ec26aca94f7bbb6fd6881527b27d9b47.tar.gz spack-d615d0a1ec26aca94f7bbb6fd6881527b27d9b47.tar.bz2 spack-d615d0a1ec26aca94f7bbb6fd6881527b27d9b47.tar.xz spack-d615d0a1ec26aca94f7bbb6fd6881527b27d9b47.zip |
Add template creation test, --skip-editor option (#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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/create.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/create.py | 57 |
2 files changed, 63 insertions, 2 deletions
diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py index e41a51ce76..792a437f29 100644 --- a/lib/spack/spack/cmd/create.py +++ b/lib/spack/spack/cmd/create.py @@ -393,6 +393,9 @@ def setup_parser(subparser): subparser.add_argument( '-f', '--force', action='store_true', help="overwrite any existing package file with the same name") + subparser.add_argument( + '--skip-editor', action='store_true', + help="skip the edit session for the package (e.g., automation)") class BuildSystemGuesser: @@ -671,5 +674,6 @@ def create(parser, args): package.write(pkg_path) tty.msg("Created package file: {0}".format(pkg_path)) - # Open up the new package file in your $EDITOR - editor(pkg_path) + # Optionally open up the new package file in your $EDITOR + if not args.skip_editor: + editor(pkg_path) diff --git a/lib/spack/spack/test/cmd/create.py b/lib/spack/spack/test/cmd/create.py new file mode 100644 index 0000000000..d3da1cce2f --- /dev/null +++ b/lib/spack/spack/test/cmd/create.py @@ -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 |