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
This commit is contained in:
		 Tamara Dahlgren
					Tamara Dahlgren
				
			
				
					committed by
					
						 Peter Scheibel
						Peter Scheibel
					
				
			
			
				
	
			
			
			 Peter Scheibel
						Peter Scheibel
					
				
			
						parent
						
							505ad8960e
						
					
				
				
					commit
					d615d0a1ec
				
			| @@ -393,6 +393,9 @@ def setup_parser(subparser): | |||||||
|     subparser.add_argument( |     subparser.add_argument( | ||||||
|         '-f', '--force', action='store_true', |         '-f', '--force', action='store_true', | ||||||
|         help="overwrite any existing package file with the same name") |         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: | class BuildSystemGuesser: | ||||||
| @@ -671,5 +674,6 @@ def create(parser, args): | |||||||
|     package.write(pkg_path) |     package.write(pkg_path) | ||||||
|     tty.msg("Created package file: {0}".format(pkg_path)) |     tty.msg("Created package file: {0}".format(pkg_path)) | ||||||
|  |  | ||||||
|     # Open up the new package file in your $EDITOR |     # Optionally open up the new package file in your $EDITOR | ||||||
|     editor(pkg_path) |     if not args.skip_editor: | ||||||
|  |         editor(pkg_path) | ||||||
|   | |||||||
							
								
								
									
										57
									
								
								lib/spack/spack/test/cmd/create.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								lib/spack/spack/test/cmd/create.py
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||||
| @@ -352,7 +352,7 @@ function _spack_create { | |||||||
|     if $list_options |     if $list_options | ||||||
|     then |     then | ||||||
|         compgen -W "-h --help --keep-stage -n --name -t --template -r --repo |         compgen -W "-h --help --keep-stage -n --name -t --template -r --repo | ||||||
|                     -N --namespace -f --force" -- "$cur" |                     -N --namespace -f --force --skip-editor" -- "$cur" | ||||||
|     fi |     fi | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user