diff --git a/pyproject.toml b/pyproject.toml index 49caa4c5490294be7c77eef427cb233227dcbbb3..197079a826feafb3aecff7b3e9f2ae967fc0b7d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "mpsd_software_manager" authors = [{name = "SSU-Computational Science (Fangohr et al)", email = "ssu-cs@mpsd.mpg.de"}] license = {file = "LICENSE"} classifiers = ["License :: OSI Approved :: MIT License"] -version = "2023.6.27" +version = "2023.7.6" readme = "README.rst" requires-python = ">=3.9" dependencies = [ diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index 2247271f311c4e8dc687e833fe9243c7a27ec1bb..56893967da39d631042d5de74da8b41e059aa8a0 100755 --- a/src/mpsd_software_manager/mpsd_software.py +++ b/src/mpsd_software_manager/mpsd_software.py @@ -1394,7 +1394,7 @@ def main(): root_dir = get_root_dir() # set up logging filename: we record activities that change the installation - if args.action in ["init", "install", "reinstall", "remove"]: + if args.action in ["init", "install", "prepare", "reinstall", "remove"]: log_file = get_log_file_path( args.release, args.action, diff --git a/tests/test_mpsd_software.py b/tests/test_mpsd_software.py index 982a0a9c1d39090ef4b8f1f5ec07726a3579631a..087c81e73046f6b74190a95ff2faa052d668280a 100644 --- a/tests/test_mpsd_software.py +++ b/tests/test_mpsd_software.py @@ -572,6 +572,90 @@ def test_get_available_releases(): assert isinstance(release, str) +def test_argument_parsing_logic(mocker): + """Test to find errors in argparse logic. + + Strategy: + + In each of the tests below, we are setting the sys.argv to simulate the + input from the command line, and in each instance, we ensure that the + mocked function get the arguments as expected. The function is mocked not + to carry out any activity. + + """ + + # pretend we have a rootdir defined + mock = mocker.patch( + "mpsd_software_manager.mpsd_software.get_root_dir", return_value=Path(".") + ) + + sys.argv = ["mpsd-software-tests", "init"] + mock = mocker.patch( + "mpsd_software_manager.mpsd_software.initialise_environment", return_value=None + ) + with pytest.raises(SystemExit): + mod.main() + call_argument = mock.call_args[0][0] + assert isinstance(call_argument, Path) + + ### available + sys.argv = ["mpsd-software-tests", "available"] + mock = mocker.patch( + "mpsd_software_manager.mpsd_software.get_available_releases", return_value=None + ) + with pytest.raises(SystemExit): + mod.main() + + sys.argv = ["mpsd-software-tests", "available", "dev-23a"] + mock = mocker.patch( + "mpsd_software_manager.mpsd_software.get_available_package_sets", + return_value=None, + ) + mod.main() + call_argument = mock.call_args[0][0] + assert call_argument == "dev-23a" + + ### prepare + sys.argv = ["mpsd-software-tests", "prepare", "dev-23a"] + mock = mocker.patch( + "mpsd_software_manager.mpsd_software.prepare_environment", return_value=None + ) + mod.main() + call_argument = mock.call_args[0][0] + assert call_argument == "dev-23a" + + ### install + mock = mocker.patch( + "mpsd_software_manager.mpsd_software.install_environment", return_value=None + ) + sys.argv = ["mpsd-software-tests", "install", "dev-23a", "foss2022a-mpi"] + mod.main() + assert mock.call_args[0][0] == "dev-23a" + assert mock.call_args[0][1] == ["foss2022a-mpi"] + + sys.argv = [ + "mpsd-software-tests", + "install", + "23b", + "foss2022a-mpi", + "foss2022a-serial", + ] + mod.main() + assert mock.call_args[0][0] == "23b" + assert mock.call_args[0][1] == ["foss2022a-mpi", "foss2022a-serial"] + + ### status + mock = mocker.patch( + "mpsd_software_manager.mpsd_software.environment_status", return_value=None + ) + sys.argv = ["mpsd-software-tests", "status", "dev-23a"] + mod.main() + assert mock.call_args[0][0] == "dev-23a" + + ### remove (argparse doesn't allow this yet. + ### Copy from 'install' when the time has come.) + + def test_interface(tmp_path): """Test other things (not implemented yet).""" pass