-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: Add default for
output_file
in computer and code export comman…
…ds (#6486)
- Loading branch information
Showing
14 changed files
with
336 additions
and
81 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
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 |
---|---|---|
|
@@ -92,6 +92,7 @@ | |
'REPOSITORY_PATH', | ||
'SCHEDULER', | ||
'SILENT', | ||
'SORT', | ||
'TIMEOUT', | ||
'TRAJECTORY_INDEX', | ||
'TRANSPORT', | ||
|
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
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 |
---|---|---|
|
@@ -259,8 +259,8 @@ def test_code_duplicate_ignore(run_cli_command, aiida_code_installed, non_intera | |
|
||
|
||
@pytest.mark.usefixtures('aiida_profile_clean') | ||
@pytest.mark.parametrize('sort', (True, False)) | ||
def test_code_export(run_cli_command, aiida_code_installed, tmp_path, file_regression, sort): | ||
@pytest.mark.parametrize('sort_option', ('--sort', '--no-sort')) | ||
def test_code_export(run_cli_command, aiida_code_installed, tmp_path, file_regression, sort_option): | ||
"""Test export the code setup to str.""" | ||
prepend_text = 'module load something\n some command' | ||
code = aiida_code_installed( | ||
|
@@ -271,14 +271,11 @@ def test_code_export(run_cli_command, aiida_code_installed, tmp_path, file_regre | |
) | ||
filepath = tmp_path / 'code.yml' | ||
|
||
options = [str(code.pk), str(filepath)] | ||
options.append('--sort' if sort else '--no-sort') | ||
|
||
run_cli_command(cmd_code.export, options) | ||
|
||
options = [str(code.pk), str(filepath), sort_option] | ||
result = run_cli_command(cmd_code.export, options) | ||
assert str(filepath) in result.output, 'Filename should be in terminal output but was not found.' | ||
# file regression check | ||
with open(filepath, 'r', encoding='utf-8') as fhandle: | ||
content = fhandle.read() | ||
content = filepath.read_text() | ||
file_regression.check(content, extension='.yml') | ||
|
||
# round trip test by create code from the config file | ||
|
@@ -292,6 +289,65 @@ def test_code_export(run_cli_command, aiida_code_installed, tmp_path, file_regre | |
assert isinstance(new_code, InstalledCode) | ||
|
||
|
||
@pytest.mark.usefixtures('aiida_profile_clean') | ||
def test_code_export_overwrite(run_cli_command, aiida_code_installed, tmp_path): | ||
prepend_text = 'module load something\n some command' | ||
code = aiida_code_installed( | ||
default_calc_job_plugin='core.arithmetic.add', | ||
filepath_executable='/bin/cat', | ||
label='code', | ||
prepend_text=prepend_text, | ||
) | ||
filepath = tmp_path / 'code.yml' | ||
|
||
options = [str(code.pk), str(filepath)] | ||
|
||
# Create directory with the same name and check that command fails | ||
filepath.mkdir() | ||
result = run_cli_command(cmd_code.export, options, raises=True) | ||
assert f'A directory with the name `{filepath}` already exists' in result.output | ||
filepath.rmdir() | ||
|
||
# Export fails if file already exists and overwrite set to False | ||
filepath.touch() | ||
result = run_cli_command(cmd_code.export, options, raises=True) | ||
assert f'File `{filepath}` already exists' in result.output | ||
|
||
# Check that overwrite actually overwrites the exported Code config with the new data | ||
code_echo = aiida_code_installed( | ||
default_calc_job_plugin='core.arithmetic.add', | ||
filepath_executable='/bin/echo', | ||
# Need to set different label, therefore manually specify the same output filename | ||
label='code_echo', | ||
prepend_text=prepend_text, | ||
) | ||
|
||
options = [str(code_echo.pk), str(filepath), '--overwrite'] | ||
run_cli_command(cmd_code.export, options) | ||
|
||
content = filepath.read_text() | ||
assert '/bin/echo' in content | ||
|
||
|
||
@pytest.mark.usefixtures('aiida_profile_clean') | ||
@pytest.mark.usefixtures('chdir_tmp_path') | ||
def test_code_export_default_filename(run_cli_command, aiida_code_installed): | ||
"""Test default filename being created if no argument passed.""" | ||
|
||
prepend_text = 'module load something\n some command' | ||
code = aiida_code_installed( | ||
default_calc_job_plugin='core.arithmetic.add', | ||
filepath_executable='/bin/cat', | ||
label='code', | ||
prepend_text=prepend_text, | ||
) | ||
|
||
options = [str(code.pk)] | ||
run_cli_command(cmd_code.export, options) | ||
|
||
assert pathlib.Path('[email protected]').is_file() | ||
|
||
|
||
@pytest.mark.parametrize('non_interactive_editor', ('vim -cwq',), indirect=True) | ||
def test_from_config_local_file(non_interactive_editor, run_cli_command, aiida_localhost): | ||
"""Test setting up a code from a config file on disk.""" | ||
|
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.