From ad9826e802ea185f4783f2f17c78098cf3a27aab Mon Sep 17 00:00:00 2001 From: Douglas Jacobsen Date: Thu, 17 Oct 2024 20:42:14 -0600 Subject: [PATCH 1/2] Disable all directive tests --- lib/ramble/ramble/appkit.py | 1 - lib/ramble/ramble/application_types/spack.py | 54 ------------------- lib/ramble/ramble/modifier_types/spack.py | 32 ----------- lib/ramble/ramble/modkit.py | 1 - .../ramble/test/application_language.py | 33 +++++++++--- lib/ramble/ramble/test/modifier_language.py | 31 +++++------ .../ramble/test/package_manager_language.py | 3 +- 7 files changed, 43 insertions(+), 112 deletions(-) delete mode 100644 lib/ramble/ramble/application_types/spack.py delete mode 100644 lib/ramble/ramble/modifier_types/spack.py 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..4d11fd85a 100644 --- a/lib/ramble/ramble/test/application_language.py +++ b/lib/ramble/ramble/test/application_language.py @@ -17,18 +17,29 @@ 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] +def generate_app_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 + + @deprecation.fail_if_not_removed @pytest.mark.parametrize("app_class", app_types) def test_application_type_features(app_class): + test_class = generate_app_class(app_class) app_path = "/path/to/app" - test_app = app_class(app_path) + test_app = test_class(app_path) assert hasattr(test_app, "workloads") assert hasattr(test_app, "executables") assert hasattr(test_app, "figures_of_merit") @@ -332,7 +343,8 @@ def add_software_spec(app_inst, spec_num=1, func_type=func_types.directive): @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") + test_class = generate_app_class(app_class) + app_inst = test_class("/not/a/path") test_defs = {} test_defs.update(add_workload(app_inst, func_type=func_type)) @@ -352,7 +364,8 @@ def test_workload_directive(app_class, func_type): @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") + test_class = generate_app_class(app_class) + app_inst = test_class("/not/a/path") test_defs = {} test_defs.update(add_executable(app_inst, func_type=func_type)) @@ -367,7 +380,8 @@ def test_executable_directive(app_class, func_type): @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") + test_class = generate_app_class(app_class) + app_inst = test_class("/not/a/path") test_defs = {} test_defs.update(add_figure_of_merit(app_inst, func_type=func_type)) @@ -382,7 +396,8 @@ def test_figure_of_merit_directive(app_class, func_type): @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") + test_class = generate_app_class(app_class) + app_inst = test_class("/not/a/path") test_defs = {} test_defs.update(add_input_file(app_inst, func_type=func_type)) @@ -401,7 +416,8 @@ def test_input_file_directive(app_class, func_type): @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") + test_class = generate_app_class(app_class) + app_inst = test_class("/not/a/path") 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)) @@ -416,7 +432,8 @@ def test_define_compiler_directive(app_class, func_type): @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") + test_class = generate_app_class(app_class) + app_inst = test_class("/not/a/path") 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)) diff --git a/lib/ramble/ramble/test/modifier_language.py b/lib/ramble/ramble/test/modifier_language.py index 9371ab9be..036dc3f55 100644 --- a/lib/ramble/ramble/test/modifier_language.py +++ b/lib/ramble/ramble/test/modifier_language.py @@ -15,9 +15,10 @@ from ramble.language.language_base import DirectiveError -mod_types = [ModifierBase, BasicModifier, SpackModifier] # noqa: F405 # noqa: F405 # noqa: F405 +mod_types = [ModifierBase, BasicModifier] # noqa: F405 func_types = enum.Enum("func_types", ["method", "directive"]) +test_func_types = [func_types.method] def generate_mod_class(base_class): @@ -70,7 +71,7 @@ def add_mode(mod_inst, mode_num=1, func_type=func_types.directive): return mode_def -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_func_types) @pytest.mark.parametrize("mod_class", mod_types) def test_mode_directive(mod_class, func_type): test_class = generate_mod_class(mod_class) @@ -115,7 +116,7 @@ def add_variable_modification(mod_inst, var_mod_num=1, func_type=func_types.dire return var_mod_def -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_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) @@ -145,7 +146,7 @@ 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("func_type", test_func_types) @pytest.mark.parametrize("mod_class", mod_types) def test_variable_modification_invalid_method(mod_class, func_type): var_mod_name = "invalid_method_variable" @@ -169,7 +170,7 @@ def test_variable_modification_invalid_method(mod_class, func_type): assert "variable_modification directive given an invalid method" in err -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_func_types) @pytest.mark.parametrize("mod_class", mod_types) def test_variable_modification_missing_mode(mod_class, func_type): var_mod_name = "missing_mode_variable" @@ -210,7 +211,7 @@ def add_software_spec(mod_inst, spec_num=1, func_type=func_types.directive): return spec_def -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_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) @@ -254,7 +255,7 @@ def add_compiler(mod_inst, spec_num=1, func_type=func_types.directive): return spec_def -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_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) @@ -292,7 +293,7 @@ def add_required_package(mod_inst, pkg_num=1, func_type=func_types.directive): return pkg_def -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_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) @@ -327,7 +328,7 @@ def add_figure_of_merit_context(mod_inst, context_num=1, func_type=func_types.di return context_def -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_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) @@ -389,7 +390,7 @@ def add_figure_of_merit(mod_inst, context_num=1, func_type=func_types.directive) return fom_def -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_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) @@ -423,7 +424,7 @@ def add_archive_pattern(mod_inst, archive_num=1, func_type=func_types.directive) return pattern -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_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) @@ -453,7 +454,7 @@ def add_executable_modifier(mod_inst, exec_mod_num=1, func_type=func_types.direc return mod_name -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_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) @@ -488,7 +489,7 @@ def add_env_var_modification(mod_inst, env_var_mod_num=1, func_type=func_types.d return test_defs -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_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) @@ -538,7 +539,7 @@ def add_modifier_variable(mod_inst, mod_var_num=1, func_type=func_types.directiv return test_defs -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_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) @@ -558,7 +559,7 @@ 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("func_type", test_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) diff --git a/lib/ramble/ramble/test/package_manager_language.py b/lib/ramble/ramble/test/package_manager_language.py index 3ea748855..ad02af981 100644 --- a/lib/ramble/ramble/test/package_manager_language.py +++ b/lib/ramble/ramble/test/package_manager_language.py @@ -18,6 +18,7 @@ ] func_types = enum.Enum("func_types", ["method", "directive"]) +test_func_types = [func_types.method] def generate_pkg_man_class(base_class): @@ -61,7 +62,7 @@ def add_variable(pm_inst, pm_num=1, func_type=func_types.directive): return var_def -@pytest.mark.parametrize("func_type", func_types) +@pytest.mark.parametrize("func_type", test_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) From 24f00bb846aaa506a3b05e60b11da96102b83e4c Mon Sep 17 00:00:00 2001 From: Douglas Jacobsen Date: Fri, 18 Oct 2024 15:52:20 -0600 Subject: [PATCH 2/2] Remove all directive based tests --- .../ramble/test/application_language.py | 280 +++++------------ lib/ramble/ramble/test/modifier_language.py | 281 ++++++------------ .../ramble/test/package_manager_language.py | 44 +-- 3 files changed, 176 insertions(+), 429 deletions(-) diff --git a/lib/ramble/ramble/test/application_language.py b/lib/ramble/ramble/test/application_language.py index 4d11fd85a..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 @@ -19,27 +18,12 @@ ExecutableApplication, # noqa: F405 ] -func_types = enum.Enum("func_types", ["method", "directive"]) -test_func_types = [func_types.method] - - -def generate_app_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 - @deprecation.fail_if_not_removed @pytest.mark.parametrize("app_class", app_types) def test_application_type_features(app_class): - test_class = generate_app_class(app_class) app_path = "/path/to/app" - test_app = test_class(app_path) + test_app = app_class(app_path) assert hasattr(test_app, "workloads") assert hasattr(test_app, "executables") assert hasattr(test_app, "figures_of_merit") @@ -51,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()} @@ -85,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 @@ -94,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: { @@ -176,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: { @@ -214,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] = { @@ -244,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, @@ -262,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}" @@ -270,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" @@ -287,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" @@ -309,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" @@ -326,27 +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): - test_class = generate_app_class(app_class) - app_inst = test_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"] @@ -361,13 +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): - test_class = generate_app_class(app_class) - app_inst = test_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(): @@ -377,13 +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): - test_class = generate_app_class(app_class) - app_inst = test_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(): @@ -393,13 +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): - test_class = generate_app_class(app_class) - app_inst = test_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(): @@ -413,14 +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): - test_class = generate_app_class(app_class) - app_inst = test_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(): @@ -429,14 +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): - test_class = generate_app_class(app_class) - app_inst = test_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 036dc3f55..b2141a208 100644 --- a/lib/ramble/ramble/test/modifier_language.py +++ b/lib/ramble/ramble/test/modifier_language.py @@ -9,7 +9,6 @@ import deprecation import pytest -import enum from ramble.modkit import * # noqa from ramble.language.language_base import DirectiveError @@ -17,27 +16,12 @@ mod_types = [ModifierBase, BasicModifier] # noqa: F405 -func_types = enum.Enum("func_types", ["method", "directive"]) -test_func_types = [func_types.method] - - -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 - @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") @@ -55,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", test_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: @@ -87,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" @@ -102,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", test_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"] @@ -146,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", test_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", test_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" @@ -201,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", test_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"] @@ -232,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" @@ -245,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", test_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"] @@ -276,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", test_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") @@ -309,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}" @@ -320,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", test_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"] @@ -349,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" @@ -366,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", test_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"] @@ -411,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", test_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") @@ -441,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", test_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") @@ -471,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" @@ -479,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", test_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") @@ -512,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}" @@ -525,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", test_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") @@ -559,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", test_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 ad02af981..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,58 +16,33 @@ PackageManagerBase, # noqa: F405 ] -func_types = enum.Enum("func_types", ["method", "directive"]) -test_func_types = [func_types.method] - -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", test_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"]