diff --git a/lib/ramble/ramble/appkit.py b/lib/ramble/ramble/appkit.py index beef381df..757d3bbd6 100644 --- a/lib/ramble/ramble/appkit.py +++ b/lib/ramble/ramble/appkit.py @@ -17,7 +17,6 @@ from ramble.application import ApplicationBase from ramble.application_types.executable import ExecutableApplication -from ramble.application_types.spack import SpackApplication from ramble.spec import Spec import ramble.language.application_language diff --git a/lib/ramble/ramble/application_types/spack.py b/lib/ramble/ramble/application_types/spack.py deleted file mode 100644 index 014f5e42b..000000000 --- a/lib/ramble/ramble/application_types/spack.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2022-2024 The Ramble Authors -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -import deprecation -from ramble.application import ApplicationBase -import ramble.keywords - -header_color = "@*b" -level1_color = "@*g" -plain_format = "@." - - -def section_title(s): - return header_color + s + plain_format - - -def subsection_title(s): - return level1_color + s + plain_format - - -class SpackApplication(ApplicationBase): - """Specialized class for applications that are installed from spack. - - This class can be used to set up an application that will be installed - via spack. - - It currently only utilizes phases defined in the base class. - """ - - _spec_groups = [ - ("compilers", "Compilers"), - ("mpi_libraries", "MPI Libraries"), - ("software_specs", "Software Specs"), - ] - _spec_keys = ["pkg_spec", "compiler_spec", "compiler"] - - @deprecation.deprecated( - deprecated_in="0.5.0", - removed_in="0.6.0", - current_version=str(ramble.ramble_version), - details="The SpackApplication class is deprecated. " - + "Convert instances to ExecutableApplication instead", - ) - def __init__(self, file_path): - super().__init__(file_path) - - self.keywords = ramble.keywords.keywords - - self.application_class = "SpackApplication" diff --git a/lib/ramble/ramble/modifier_types/spack.py b/lib/ramble/ramble/modifier_types/spack.py deleted file mode 100644 index 21a7189ac..000000000 --- a/lib/ramble/ramble/modifier_types/spack.py +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2022-2024 The Ramble Authors -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -import ramble -import deprecation - -from ramble.modifier import ModifierBase - - -class SpackModifier(ModifierBase): - """Specialized class for modifiers that use spack. - - This class can be used to set up a modifier that uses spack to install - software for the modifier to work. - """ - - modifier_class = "SpackModifier" - - @deprecation.deprecated( - deprecated_in="0.5.0", - removed_in="0.6.0", - current_version=str(ramble.ramble_version), - details="The SpackModifier class is deprecated. " - + "Convert instances to BasicModifier instead", - ) - def __init__(self, file_path): - super().__init__(file_path) diff --git a/lib/ramble/ramble/modkit.py b/lib/ramble/ramble/modkit.py index cea06b653..e6c47cd0b 100644 --- a/lib/ramble/ramble/modkit.py +++ b/lib/ramble/ramble/modkit.py @@ -20,7 +20,6 @@ from ramble.modifier import ModifierBase from ramble.modifier_types.basic import BasicModifier -from ramble.modifier_types.spack import SpackModifier from ramble.spec import Spec import ramble.language.modifier_language diff --git a/lib/ramble/ramble/test/application_language.py b/lib/ramble/ramble/test/application_language.py index 22bbfcf4f..706eb318c 100644 --- a/lib/ramble/ramble/test/application_language.py +++ b/lib/ramble/ramble/test/application_language.py @@ -8,7 +8,6 @@ """Perform tests of the Application class""" import pytest -import enum import deprecation from ramble.appkit import * # noqa @@ -17,12 +16,8 @@ app_types = [ ApplicationBase, # noqa: F405 ExecutableApplication, # noqa: F405 - SpackApplication, # noqa: F405 ] -func_types = enum.Enum("func_types", ["method", "directive"]) -test_func_types = [func_types.method] - @deprecation.fail_if_not_removed @pytest.mark.parametrize("app_class", app_types) @@ -40,31 +35,20 @@ def test_application_type_features(app_class): assert hasattr(test_app, "package_manager_configs") -def add_workload(app_inst, wl_num=1, func_type=func_types.directive): +def add_workload(app_inst, wl_num=1): wl_name = "TestWorkload%s" % wl_num exec_list = ["Workload%sExec1" % wl_num] exec_var = "Workload%sExec2" % wl_num inpt_list = ["Workload%sInput1" % wl_num] inpt_var = "Workload%sInput2" % wl_num - if func_type == func_types.directive: - workload( - wl_name, - executables=exec_list, - executable=exec_var, # noqa: F405 - inputs=inpt_list, - input=inpt_var, - )(app_inst) - elif func_type == func_types.method: - app_inst.workload( - wl_name, - executables=exec_list, - executable=exec_var, # noqa: F405 - inputs=inpt_list, - input=inpt_var, - ) - else: - assert False + app_inst.workload( + wl_name, + executables=exec_list, + executable=exec_var, # noqa: F405 + inputs=inpt_list, + input=inpt_var, + ) workload_def = {"name": wl_name, "executables": exec_list.copy(), "inputs": inpt_list.copy()} @@ -74,7 +58,7 @@ def add_workload(app_inst, wl_num=1, func_type=func_types.directive): return workload_def -def add_executable(app_inst, exe_num=1, func_type=func_types.directive): +def add_executable(app_inst, exe_num=1): nompi_bg_exec_name = "SerialExe%s" % exe_num mpi_exec_name = "MpiExe%s" % exe_num nompi_list_exec_name = "MultiLineSerialExe%s" % exe_num @@ -83,58 +67,30 @@ def add_executable(app_inst, exe_num=1, func_type=func_types.directive): redirect_test = "{output_file}" output_capture = ">>" - if func_type == func_types.directive: - executable( - nompi_bg_exec_name, - template, # noqa: F405 - use_mpi=False, - redirect=redirect_test, - output_capture=output_capture, - run_in_background=True, - )(app_inst) - - executable(mpi_exec_name, template, use_mpi=True)(app_inst) # noqa: F405 - - executable( - nompi_list_exec_name, # noqa: F405 - template=[template, template, template], - use_mpi=False, - redirect=None, - )(app_inst) - - executable( - mpi_list_exec_name, - template=[template, template], # noqa: F405 - use_mpi=True, - redirect=redirect_test, - )(app_inst) - elif func_type == func_types.method: - app_inst.executable( - nompi_bg_exec_name, - template, # noqa: F405 - use_mpi=False, - redirect=redirect_test, - output_capture=output_capture, - run_in_background=True, - ) - - app_inst.executable(mpi_exec_name, template, use_mpi=True) # noqa: F405 - - app_inst.executable( - nompi_list_exec_name, # noqa: F405 - template=[template, template, template], - use_mpi=False, - redirect=None, - ) - - app_inst.executable( - mpi_list_exec_name, - template=[template, template], # noqa: F405 - use_mpi=True, - redirect=redirect_test, - ) - else: - assert False + app_inst.executable( + nompi_bg_exec_name, + template, # noqa: F405 + use_mpi=False, + redirect=redirect_test, + output_capture=output_capture, + run_in_background=True, + ) + + app_inst.executable(mpi_exec_name, template, use_mpi=True) # noqa: F405 + + app_inst.executable( + nompi_list_exec_name, # noqa: F405 + template=[template, template, template], + use_mpi=False, + redirect=None, + ) + + app_inst.executable( + mpi_list_exec_name, + template=[template, template], # noqa: F405 + use_mpi=True, + redirect=redirect_test, + ) exec_def = { nompi_bg_exec_name: { @@ -165,31 +121,20 @@ def add_executable(app_inst, exe_num=1, func_type=func_types.directive): return exec_def -def add_figure_of_merit(app_inst, fom_num=1, func_type=func_types.directive): +def add_figure_of_merit(app_inst, fom_num=1): fom_name = "TestFom%s" % fom_num fom_log = "{log_file}" fom_regex = ".*(?P[0-9]+).*" % fom_num fom_group = "fom%s_val" % fom_num fom_units = "(s)" - if func_type == func_types.directive: - figure_of_merit( - fom_name, - log_file=fom_log, - fom_regex=fom_regex, # noqa: F405 - group_name=fom_group, - units=fom_units, - )(app_inst) - elif func_type == func_types.method: - app_inst.figure_of_merit( - fom_name, - log_file=fom_log, - fom_regex=fom_regex, # noqa: F405 - group_name=fom_group, - units=fom_units, - ) - else: - assert False + app_inst.figure_of_merit( + fom_name, + log_file=fom_log, + fom_regex=fom_regex, # noqa: F405 + group_name=fom_group, + units=fom_units, + ) fom_def = { fom_name: { @@ -203,23 +148,14 @@ def add_figure_of_merit(app_inst, fom_num=1, func_type=func_types.directive): return fom_def -def add_input_file(app_inst, input_num=1, func_type=func_types.directive): +def add_input_file(app_inst, input_num=1): input_name = "MainTestInput%s" % input_num input_url = "https://input%s.com/file.tar.gz" % input_num input_desc = "This is a test input file #%s" % input_num input_target = "{application_input_dir}/test_dir%s" % input_num # Add an input with a target dir - if func_type == func_types.directive: - input_file(input_name, input_url, input_desc, target_dir=input_target)( # noqa: F405 - app_inst - ) - elif func_type == func_types.method: - app_inst.input_file( - input_name, input_url, input_desc, target_dir=input_target # noqa: F405 - ) - else: - assert False + app_inst.input_file(input_name, input_url, input_desc, target_dir=input_target) # noqa: F405 input_defs = {} input_defs[input_name] = { @@ -233,12 +169,7 @@ def add_input_file(app_inst, input_num=1, func_type=func_types.directive): input_desc = "This is a test secondary input file #%s" % input_num # Add an input without a target dir - if func_type == func_types.directive: - input_file(input_name, input_url, input_desc)(app_inst) # noqa: F405 - elif func_type == func_types.method: - app_inst.input_file(input_name, input_url, input_desc) # noqa: F405 - else: - assert False + app_inst.input_file(input_name, input_url, input_desc) # noqa: F405 input_defs[input_name] = { "url": input_url, @@ -251,7 +182,7 @@ def add_input_file(app_inst, input_num=1, func_type=func_types.directive): # TODO: can this be dried with the modifier language add_compiler? @deprecation.fail_if_not_removed -def add_compiler(app_inst, spec_num=1, func_type=func_types.directive): +def add_compiler(app_inst, spec_num=1): spec_name = "Compiler%spec_num" spec_pkg_spec = f"compiler_base@{spec_num}.0 +var1 ~var2" spec_compiler_spec = "compiler1_base@{spec_num}" @@ -259,16 +190,9 @@ def add_compiler(app_inst, spec_num=1, func_type=func_types.directive): spec_defs = {} spec_defs[spec_name] = {"pkg_spec": spec_pkg_spec, "compiler_spec": spec_compiler_spec} - if func_type == func_types.directive: - define_compiler( - spec_name, pkg_spec=spec_pkg_spec, compiler_spec=spec_compiler_spec # noqa: F405 - )(app_inst) - elif func_type == func_types.method: - app_inst.define_compiler( - spec_name, pkg_spec=spec_pkg_spec, compiler_spec=spec_compiler_spec # noqa: F405 - ) - else: - assert False + app_inst.define_compiler( + spec_name, pkg_spec=spec_pkg_spec, compiler_spec=spec_compiler_spec # noqa: F405 + ) spec_name = "OtherCompiler%spec_num" spec_pkg_spec = f"compiler_base@{spec_num}.1 +var1 ~var2 target=x86_64" @@ -276,21 +200,14 @@ def add_compiler(app_inst, spec_num=1, func_type=func_types.directive): spec_defs[spec_name] = {"pkg_spec": spec_pkg_spec, "compiler_spec": spec_compiler_spec} - if func_type == func_types.directive: - define_compiler( - spec_name, pkg_spec=spec_pkg_spec, compiler_spec=spec_compiler_spec # noqa: f405 - )(app_inst) - elif func_type == func_types.method: - app_inst.define_compiler( - spec_name, pkg_spec=spec_pkg_spec, compiler_spec=spec_compiler_spec # noqa: F405 - ) - else: - assert False + app_inst.define_compiler( + spec_name, pkg_spec=spec_pkg_spec, compiler_spec=spec_compiler_spec # noqa: F405 + ) return spec_defs -def add_software_spec(app_inst, spec_num=1, func_type=func_types.directive): +def add_software_spec(app_inst, spec_num=1): spec_name = "NoMPISpec%s" % spec_num spec_pkg_spec = f"NoMPISpec@{spec_num} +var1 ~var2 target=x86_64" spec_compiler = "spec_compiler1@1.1" @@ -298,16 +215,7 @@ def add_software_spec(app_inst, spec_num=1, func_type=func_types.directive): spec_defs = {} spec_defs[spec_name] = {"pkg_spec": spec_pkg_spec, "compiler": spec_compiler} - if func_type == func_types.directive: - software_spec(spec_name, pkg_spec=spec_pkg_spec, compiler=spec_compiler)( # noqa: F405 - app_inst - ) - elif func_type == func_types.method: - app_inst.software_spec( - spec_name, pkg_spec=spec_pkg_spec, compiler=spec_compiler # noqa: F405 - ) - else: - assert False + app_inst.software_spec(spec_name, pkg_spec=spec_pkg_spec, compiler=spec_compiler) # noqa: F405 spec_name = "MPISpec%s" % spec_num spec_pkg_spec = f"MPISpec@{spec_num} +var1 ~var2 target=x86_64" @@ -315,26 +223,17 @@ def add_software_spec(app_inst, spec_num=1, func_type=func_types.directive): spec_defs[spec_name] = {"pkg_spec": spec_pkg_spec, "compiler": spec_compiler} - if func_type == func_types.directive: - software_spec(spec_name, pkg_spec=spec_pkg_spec, compiler=spec_compiler)( # noqa: F405 - app_inst - ) - elif func_type == func_types.method: - app_inst.software_spec( - spec_name, pkg_spec=spec_pkg_spec, compiler=spec_compiler # noqa: F405 - ) - else: - assert False + app_inst.software_spec(spec_name, pkg_spec=spec_pkg_spec, compiler=spec_compiler) # noqa: F405 return spec_defs -@pytest.mark.parametrize("func_type", test_func_types) @pytest.mark.parametrize("app_class", app_types) -def test_workload_directive(app_class, func_type): - app_inst = app_class("/not/a/path") +def test_workload_directive(app_class): test_defs = {} - test_defs.update(add_workload(app_inst, func_type=func_type)) + + app_inst = app_class("/not/a/path") + test_defs.update(add_workload(app_inst)) wl_name = test_defs["name"] @@ -349,12 +248,12 @@ def test_workload_directive(app_class, func_type): assert app_inst.workloads[wl_name].find_input(test) is not None -@pytest.mark.parametrize("func_type", test_func_types) @pytest.mark.parametrize("app_class", app_types) -def test_executable_directive(app_class, func_type): - app_inst = app_class("/not/a/path") +def test_executable_directive(app_class): test_defs = {} - test_defs.update(add_executable(app_inst, func_type=func_type)) + + app_inst = app_class("/not/a/path") + test_defs.update(add_executable(app_inst)) assert hasattr(app_inst, "executables") for exe_name, conf in test_defs.items(): @@ -364,12 +263,12 @@ def test_executable_directive(app_class, func_type): assert conf_val == getattr(app_inst.executables[exe_name], conf_name) -@pytest.mark.parametrize("func_type", test_func_types) @pytest.mark.parametrize("app_class", app_types) -def test_figure_of_merit_directive(app_class, func_type): - app_inst = app_class("/not/a/path") +def test_figure_of_merit_directive(app_class): test_defs = {} - test_defs.update(add_figure_of_merit(app_inst, func_type=func_type)) + + app_inst = app_class("/not/a/path") + test_defs.update(add_figure_of_merit(app_inst)) assert hasattr(app_inst, "figures_of_merit") for fom_name, conf in test_defs.items(): @@ -379,12 +278,12 @@ def test_figure_of_merit_directive(app_class, func_type): assert app_inst.figures_of_merit[fom_name][conf_name] == conf_val -@pytest.mark.parametrize("func_type", test_func_types) @pytest.mark.parametrize("app_class", app_types) -def test_input_file_directive(app_class, func_type): - app_inst = app_class("/not/a/path") +def test_input_file_directive(app_class): test_defs = {} - test_defs.update(add_input_file(app_inst, func_type=func_type)) + + app_inst = app_class("/not/a/path") + test_defs.update(add_input_file(app_inst)) assert hasattr(app_inst, "inputs") for input_name, conf in test_defs.items(): @@ -398,13 +297,13 @@ def test_input_file_directive(app_class, func_type): assert "expand" in app_inst.inputs[input_name] -@pytest.mark.parametrize("func_type", test_func_types) @pytest.mark.parametrize("app_class", app_types) -def test_define_compiler_directive(app_class, func_type): - app_inst = app_class("/not/a/path") +def test_define_compiler_directive(app_class): test_defs = {} - test_defs.update(add_compiler(app_inst, 1, func_type=func_type)) - test_defs.update(add_compiler(app_inst, 2, func_type=func_type)) + + app_inst = app_class("/not/a/path") + test_defs.update(add_compiler(app_inst, 1)) + test_defs.update(add_compiler(app_inst, 2)) assert hasattr(app_inst, "compilers") for name, info in test_defs.items(): @@ -413,13 +312,13 @@ def test_define_compiler_directive(app_class, func_type): assert app_inst.compilers[name][key] == value -@pytest.mark.parametrize("func_type", test_func_types) @pytest.mark.parametrize("app_class", app_types) -def test_software_spec_directive(app_class, func_type): - app_inst = app_class("/not/a/path") +def test_software_spec_directive(app_class): test_defs = {} - test_defs.update(add_software_spec(app_inst, 1, func_type=func_type)) - test_defs.update(add_software_spec(app_inst, 2, func_type=func_type)) + + app_inst = app_class("/not/a/path") + test_defs.update(add_software_spec(app_inst, 1)) + test_defs.update(add_software_spec(app_inst, 2)) assert hasattr(app_inst, "software_specs") for name, info in test_defs.items(): diff --git a/lib/ramble/ramble/test/modifier_language.py b/lib/ramble/ramble/test/modifier_language.py index 9371ab9be..b2141a208 100644 --- a/lib/ramble/ramble/test/modifier_language.py +++ b/lib/ramble/ramble/test/modifier_language.py @@ -9,34 +9,19 @@ import deprecation import pytest -import enum from ramble.modkit import * # noqa from ramble.language.language_base import DirectiveError -mod_types = [ModifierBase, BasicModifier, SpackModifier] # noqa: F405 # noqa: F405 # noqa: F405 - -func_types = enum.Enum("func_types", ["method", "directive"]) - - -def generate_mod_class(base_class): - - class GeneratedClass(base_class): - _language_classes = base_class._language_classes.copy() - - def __init__(self, file_path): - super().__init__(file_path) - - return GeneratedClass +mod_types = [ModifierBase, BasicModifier] # noqa: F405 @deprecation.fail_if_not_removed @pytest.mark.parametrize("mod_class", mod_types) def test_modifier_type_features(mod_class): - test_class = generate_mod_class(mod_class) mod_path = "/path/to/mod" - test_mod = test_class(mod_path) + test_mod = mod_class(mod_path) assert hasattr(test_mod, "figure_of_merit_contexts") assert hasattr(test_mod, "archive_patterns") assert hasattr(test_mod, "figures_of_merit") @@ -54,29 +39,23 @@ def test_modifier_type_features(mod_class): assert hasattr(test_mod, "package_manager_configs") -def add_mode(mod_inst, mode_num=1, func_type=func_types.directive): +def add_mode(mod_inst, mode_num=1): mode_name = "TestMode%s" % mode_num mode_desc = "This is a test mode" - if func_type == func_types.directive: - mode(mode_name, description=mode_desc)(mod_inst) # noqa: F405 - elif func_type == func_types.method: - mod_inst.mode(mode_name, description=mode_desc) # noqa: F405 - else: - assert False + mod_inst.mode(mode_name, description=mode_desc) # noqa: F405 mode_def = {"name": mode_name, "description": mode_desc} return mode_def -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_mode_directive(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_mode_directive(mod_class): test_defs = [] - test_defs.append(add_mode(mod_inst, func_type=func_type).copy()) + + mod_inst = mod_class("/not/a/path") + test_defs.append(add_mode(mod_inst).copy()) assert hasattr(mod_inst, "modes") for test_def in test_defs: @@ -86,7 +65,7 @@ def test_mode_directive(mod_class, func_type): assert mod_inst.modes[mode_name]["description"] == test_def["description"] -def add_variable_modification(mod_inst, var_mod_num=1, func_type=func_types.directive): +def add_variable_modification(mod_inst, var_mod_num=1): var_mod_name = f"variable_{var_mod_num}" var_mod_mod = "test_append" var_mod_method = "append" @@ -101,27 +80,19 @@ def add_variable_modification(mod_inst, var_mod_num=1, func_type=func_types.dire "modes": var_mod_modes.copy(), } - if func_type == func_types.directive: - variable_modification( - var_mod_name, var_mod_mod, var_mod_method, mode=var_mod_mode, modes=var_mod_modes - )(mod_inst) - elif func_type == func_types.method: - mod_inst.variable_modification( - var_mod_name, var_mod_mod, var_mod_method, mode=var_mod_mode, modes=var_mod_modes - ) - else: - assert False + mod_inst.variable_modification( + var_mod_name, var_mod_mod, var_mod_method, mode=var_mod_mode, modes=var_mod_modes + ) return var_mod_def -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_variable_modification_directive(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_variable_modification_directive(mod_class): test_defs = [] - test_defs.append(add_variable_modification(mod_inst, func_type=func_type).copy()) + + mod_inst = mod_class("/not/a/path") + test_defs.append(add_variable_modification(mod_inst).copy()) expected_attrs = ["modification", "method"] @@ -145,49 +116,35 @@ def test_variable_modification_directive(mod_class, func_type): assert test_def[attr] == mod_inst.variable_modifications[mode_name][var_name][attr] -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_variable_modification_invalid_method(mod_class, func_type): +def test_variable_modification_invalid_method(mod_class): var_mod_name = "invalid_method_variable" var_mod_mod = "invalid_method_mod" var_mod_method = "invalid" var_mod_mode = "invalid_method_mode" - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") with pytest.raises(DirectiveError) as err: - if func_type == func_types.directive: - variable_modification(var_mod_name, var_mod_mod, var_mod_method, mode=var_mod_mode)( - mod_inst - ) - elif func_type == func_types.method: - mod_inst.variable_modification( - var_mod_name, var_mod_mod, var_mod_method, mode=var_mod_mode - ) - else: - assert False + mod_inst = mod_class("/not/a/path") + mod_inst.variable_modification( + var_mod_name, var_mod_mod, var_mod_method, mode=var_mod_mode + ) assert "variable_modification directive given an invalid method" in err -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_variable_modification_missing_mode(mod_class, func_type): +def test_variable_modification_missing_mode(mod_class): var_mod_name = "missing_mode_variable" var_mod_mod = "missing_mode_mod" var_mod_method = "set" - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") with pytest.raises(DirectiveError) as err: - if func_type == func_types.directive: - variable_modification(var_mod_name, var_mod_mod, var_mod_method)(mod_inst) - elif func_type == func_types.method: - mod_inst.variable_modification(var_mod_name, var_mod_mod, var_mod_method) + mod_inst = mod_class("/not/a/path") + mod_inst.variable_modification(var_mod_name, var_mod_mod, var_mod_method) assert "variable_modification directive requires:" in err assert "mode or modes to be defined." in err -def add_software_spec(mod_inst, spec_num=1, func_type=func_types.directive): +def add_software_spec(mod_inst, spec_num=1): spec_name = f"SoftwarePackage{spec_num}" pkg_spec = "pkg@1.1 target=x86_64" compiler_spec = "pkg@1.1" @@ -200,23 +157,17 @@ def add_software_spec(mod_inst, spec_num=1, func_type=func_types.directive): "compiler": compiler, } - if func_type == func_types.directive: - software_spec(spec_name, pkg_spec, compiler_spec, compiler)(mod_inst) - elif func_type == func_types.method: - mod_inst.software_spec(spec_name, pkg_spec, compiler_spec, compiler) - else: - assert False + mod_inst.software_spec(spec_name, pkg_spec, compiler_spec, compiler) return spec_def -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_software_spec_directive(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_software_spec_directive(mod_class): test_defs = [] - test_defs.append(add_software_spec(mod_inst, func_type=func_type).copy()) + + mod_inst = mod_class("/not/a/path") + test_defs.append(add_software_spec(mod_inst).copy()) expected_attrs = ["pkg_spec", "compiler_spec", "compiler"] @@ -231,7 +182,7 @@ def test_software_spec_directive(mod_class, func_type): assert test_def[attr] == mod_inst.software_specs[spec_name][attr] -def add_compiler(mod_inst, spec_num=1, func_type=func_types.directive): +def add_compiler(mod_inst, spec_num=1): spec_name = f"CompilerPackage{spec_num}" pkg_spec = "compiler@1.1 target=x86_64" compiler_spec = "compiler@1.1" @@ -244,23 +195,17 @@ def add_compiler(mod_inst, spec_num=1, func_type=func_types.directive): "compiler": compiler, } - if func_type == func_types.directive: - define_compiler(spec_name, pkg_spec, compiler_spec, compiler)(mod_inst) - elif func_type == func_types.method: - mod_inst.define_compiler(spec_name, pkg_spec, compiler_spec, compiler) - else: - assert False + mod_inst.define_compiler(spec_name, pkg_spec, compiler_spec, compiler) return spec_def -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_define_compiler_directive(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_define_compiler_directive(mod_class): test_defs = [] - test_defs.append(add_compiler(mod_inst, func_type=func_type).copy()) + + mod_inst = mod_class("/not/a/path") + test_defs.append(add_compiler(mod_inst).copy()) expected_attrs = ["pkg_spec", "compiler_spec", "compiler"] @@ -275,30 +220,24 @@ def test_define_compiler_directive(mod_class, func_type): assert test_def[attr] == mod_inst.compilers[spec_name][attr] -def add_required_package(mod_inst, pkg_num=1, func_type=func_types.directive): +def add_required_package(mod_inst, pkg_num=1): pkg_name = f"RequiredPackage{pkg_num}" pkg_def = { "name": pkg_name, } - if func_type == func_types.directive: - required_package(pkg_name)(mod_inst) - elif func_type == func_types.method: - mod_inst.required_package(pkg_name) - else: - assert False + mod_inst.required_package(pkg_name) return pkg_def -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_required_package_directive(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_required_package_directive(mod_class): test_defs = [] - test_defs.append(add_required_package(mod_inst, func_type=func_type).copy()) + + mod_inst = mod_class("/not/a/path") + test_defs.append(add_required_package(mod_inst).copy()) assert hasattr(mod_inst, "required_packages") @@ -308,7 +247,7 @@ def test_required_package_directive(mod_class, func_type): assert pkg_name in mod_inst.required_packages -def add_figure_of_merit_context(mod_inst, context_num=1, func_type=func_types.directive): +def add_figure_of_merit_context(mod_inst, context_num=1): name = f"FOMContext{context_num}" regex = "test(?P[fom]+)regex" output_format = "{test}" @@ -319,21 +258,17 @@ def add_figure_of_merit_context(mod_inst, context_num=1, func_type=func_types.di "output_format": output_format, } - if func_type == func_types.directive: - figure_of_merit_context(name, regex, output_format)(mod_inst) - elif func_type == func_types.method: - mod_inst.figure_of_merit_context(name, regex, output_format) + mod_inst.figure_of_merit_context(name, regex, output_format) return context_def -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_figure_of_merit_context_directive(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_figure_of_merit_context_directive(mod_class): test_defs = [] - test_defs.append(add_figure_of_merit_context(mod_inst, func_type=func_type).copy()) + + mod_inst = mod_class("/not/a/path") + test_defs.append(add_figure_of_merit_context(mod_inst).copy()) expected_attrs = ["regex", "output_format"] @@ -348,7 +283,7 @@ def test_figure_of_merit_context_directive(mod_class, func_type): assert test_def[attr] == mod_inst.figure_of_merit_contexts[name][attr] -def add_figure_of_merit(mod_inst, context_num=1, func_type=func_types.directive): +def add_figure_of_merit(mod_inst, context_num=1): name = f"FOM{context_num}" log_file = "{log_file}" fom_regex = "test(?P[fom]+)regex" @@ -365,37 +300,24 @@ def add_figure_of_merit(mod_inst, context_num=1, func_type=func_types.directive) "contexts": contexts.copy(), } - if func_type == func_types.directive: - figure_of_merit( - name, - fom_regex=fom_regex, - group_name=group_name, - units=units, - log_file=log_file, - contexts=contexts, - )(mod_inst) - elif func_type == func_types.method: - mod_inst.figure_of_merit( - name, - fom_regex=fom_regex, - group_name=group_name, - units=units, - log_file=log_file, - contexts=contexts, - ) - else: - assert False + mod_inst.figure_of_merit( + name, + fom_regex=fom_regex, + group_name=group_name, + units=units, + log_file=log_file, + contexts=contexts, + ) return fom_def -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_figure_of_merit_directive(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_figure_of_merit_directive(mod_class): test_defs = [] - test_defs.append(add_figure_of_merit(mod_inst, func_type=func_type).copy()) + + mod_inst = mod_class("/not/a/path") + test_defs.append(add_figure_of_merit(mod_inst).copy()) expected_attrs = ["log_file", "regex", "group_name", "units", "contexts"] @@ -410,26 +332,20 @@ def test_figure_of_merit_directive(mod_class, func_type): assert test_def[attr] == mod_inst.figures_of_merit[name][attr] -def add_archive_pattern(mod_inst, archive_num=1, func_type=func_types.directive): +def add_archive_pattern(mod_inst, archive_num=1): pattern = f"my_archive{archive_num}.*" - if func_type == func_types.directive: - archive_pattern(pattern)(mod_inst) - elif func_type == func_types.method: - mod_inst.archive_pattern(pattern) - else: - assert False + mod_inst.archive_pattern(pattern) return pattern -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_archive_pattern_directive(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_archive_pattern_directive(mod_class): test_defs = [] - test_defs.append(add_archive_pattern(mod_inst, func_type=func_type)) + + mod_inst = mod_class("/not/a/path") + test_defs.append(add_archive_pattern(mod_inst)) assert hasattr(mod_inst, "archive_patterns") @@ -440,26 +356,20 @@ def test_archive_pattern_directive(mod_class, func_type): assert pattern == mod_inst.archive_patterns[pattern] -def add_executable_modifier(mod_inst, exec_mod_num=1, func_type=func_types.directive): +def add_executable_modifier(mod_inst, exec_mod_num=1): mod_name = f"exec_mod{exec_mod_num}" - if func_type == func_type.directive: - executable_modifier(mod_name)(mod_inst) - elif func_type == func_type.method: - mod_inst.executable_modifier(mod_name) - else: - assert False + mod_inst.executable_modifier(mod_name) return mod_name -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_executable_modifier_directive(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_executable_modifier_directive(mod_class): test_defs = [] - test_defs.append(add_executable_modifier(mod_inst, func_type)) + + mod_inst = mod_class("/not/a/path") + test_defs.append(add_executable_modifier(mod_inst)) assert hasattr(mod_inst, "executable_modifiers") @@ -470,7 +380,7 @@ def test_executable_modifier_directive(mod_class, func_type): assert mod_name == mod_inst.executable_modifiers[mod_name] -def add_env_var_modification(mod_inst, env_var_mod_num=1, func_type=func_types.directive): +def add_env_var_modification(mod_inst, env_var_mod_num=1): mod_name = f"env_var_mod_{env_var_mod_num}" mod_val = f"value_{env_var_mod_num}" mod_method = "set" @@ -478,23 +388,17 @@ def add_env_var_modification(mod_inst, env_var_mod_num=1, func_type=func_types.d test_defs = {"name": mod_name, "modification": mod_val, "method": mod_method, "mode": mod_mode} - if func_type == func_types.directive: - env_var_modification(mod_name, mod_val, mode=mod_mode)(mod_inst) - elif func_type == func_types.method: - mod_inst.env_var_modification(mod_name, mod_val, mode=mod_mode) - else: - assert False + mod_inst.env_var_modification(mod_name, mod_val, mode=mod_mode) return test_defs -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_env_var_modification_directive(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_env_var_modification_directive(mod_class): test_defs = [] - test_defs.append(add_env_var_modification(mod_inst, func_type)) + + mod_inst = mod_class("/not/a/path") + test_defs.append(add_env_var_modification(mod_inst)) assert hasattr(mod_inst, "env_var_modifications") @@ -511,7 +415,7 @@ def test_env_var_modification_directive(mod_class, func_type): ) -def add_modifier_variable(mod_inst, mod_var_num=1, func_type=func_types.directive): +def add_modifier_variable(mod_inst, mod_var_num=1): var_name = f"mod_var_{mod_var_num}" var_default = f"default_{mod_var_num}" var_desc = f"Test variable {mod_var_num}" @@ -524,27 +428,17 @@ def add_modifier_variable(mod_inst, mod_var_num=1, func_type=func_types.directiv "mode": var_mode, } - if func_type == func_types.directive: - modifier_variable(var_name, default=var_default, description=var_desc, mode=var_mode)( - mod_inst - ) - elif func_type == func_types.method: - mod_inst.modifier_variable( - var_name, default=var_default, description=var_desc, mode=var_mode - ) - else: - assert False + mod_inst.modifier_variable(var_name, default=var_default, description=var_desc, mode=var_mode) return test_defs -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_modifier_variable_directive(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_modifier_variable_directive(mod_class): test_defs = [] - test_defs.append(add_modifier_variable(mod_inst, func_type)) + + mod_inst = mod_class("/not/a/path") + test_defs.append(add_modifier_variable(mod_inst)) assert hasattr(mod_inst, "modifier_variables") @@ -558,11 +452,9 @@ def test_modifier_variable_directive(mod_class, func_type): assert test_def["default"] == mod_inst.modifier_variables[mode][var_name].default -@pytest.mark.parametrize("func_type", func_types) @pytest.mark.parametrize("mod_class", mod_types) -def test_modifier_class_attributes(mod_class, func_type): - test_class = generate_mod_class(mod_class) - mod_inst = test_class("/not/a/path") +def test_modifier_class_attributes(mod_class): + mod_inst = mod_class("/not/a/path") mod_copy = mod_inst.copy() mod_copy.mode("added_mode", description="Mode added to test attributes") diff --git a/lib/ramble/ramble/test/package_manager_language.py b/lib/ramble/ramble/test/package_manager_language.py index 3ea748855..b722070e0 100644 --- a/lib/ramble/ramble/test/package_manager_language.py +++ b/lib/ramble/ramble/test/package_manager_language.py @@ -8,7 +8,6 @@ """Perform tests of the package manager class""" import pytest -import enum from ramble.pkgmankit import * # noqa @@ -17,57 +16,33 @@ PackageManagerBase, # noqa: F405 ] -func_types = enum.Enum("func_types", ["method", "directive"]) - -def generate_pkg_man_class(base_class): - - class GeneratedClass(base_class): - _language_classes = base_class._language_classes.copy() - - def __init__(self, file_path): - super().__init__(file_path) - - return GeneratedClass - - -@pytest.mark.parametrize("base_class", pm_types) -def test_pkg_man_type_features(base_class): +@pytest.mark.parametrize("pm_class", pm_types) +def test_pkg_man_type_features(pm_class): pm_path = "/path/to/pm" - pm_class = generate_pkg_man_class(base_class) test_pm = pm_class(pm_path) assert hasattr(test_pm, "package_manager_variable") assert hasattr(test_pm, "maintainers") -def add_variable(pm_inst, pm_num=1, func_type=func_types.directive): +def add_variable(pm_inst, pm_num=1): var_name = f"TestVariable{pm_num}" var_default = f"DefaultValue{pm_num}" var_description = f"Description{pm_num}" - if func_type == func_types.directive: - package_manager_variable(var_name, default=var_default, description=var_description)( - pm_inst - ) - elif func_type == func_types.method: - pm_inst.package_manager_variable( - var_name, default=var_default, description=var_description - ) - else: - return False + pm_inst.package_manager_variable(var_name, default=var_default, description=var_description) var_def = {"name": var_name, "default": var_default, "description": var_description} return var_def -@pytest.mark.parametrize("func_type", func_types) -@pytest.mark.parametrize("base_class", pm_types) -def test_pkg_man_variables(base_class, func_type): - pm_class = generate_pkg_man_class(base_class) - pm_inst = pm_class("/not/a/path") +@pytest.mark.parametrize("pm_class", pm_types) +def test_pkg_man_variables(pm_class): test_defs = {} - test_defs.update(add_variable(pm_inst, func_type=func_type)) + + pm_inst = pm_class("/not/a/path") + test_defs.update(add_variable(pm_inst)) var_name = test_defs["name"]