reframe-hpc / reframe

A powerful Python framework for writing and running portable regression tests and benchmarks for HPC systems.
https://reframe-hpc.readthedocs.org
BSD 3-Clause "New" or "Revised" License
214 stars 101 forks source link

[feat] Enable multiple inheritance of test variables #3113

Closed vkarak closed 6 months ago

vkarak commented 6 months ago

Currently, multiple inheritance of test or mixin variables is prohibited leads to a test load error. This is restrictive, especially in case of mixins, which may be inherited multiple times in a complex setup. For example, the following would cause an error when reframe is processing the Z class:

    class Mixin(rfm.RegressionMixin):
        x = variable(typ.List[int], value=[])

    class X(Mixin):
        x = [3, 4]

    class Y(Mixin):
        x = [10, 1]

    class Z(X, Y):
        pass

This PR introduces a new variable argument, merge_func, that defines how the default values of the parent variables can be combined in case of multiple inheritance. Since merge_func=None by default, the default behaviour of variables does not change. It just that we now offer the extra flexibility to users to define the variable behaviour in case of multiple inheritance.

In the example above, if we define x as follows:

    class Mixin(rfm.RegressionMixin):
        x = variable(typ.List[int], value=[],
                     merge_func=lambda x, y: list(map(max, zip(x, y))))

    class X(Mixin):
        x = [3, 4]

    class Y(Mixin):
        x = [10, 1]

    class Z(X, Y):
        pass

its value in Z class will be [10, 4].

Todos

pep8speaks commented 6 months ago

Hello @vkarak, Thank you for updating!

Cheers! There are no PEP8 issues in this Pull Request!Do see the ReFrame Coding Style Guide

Comment last updated at 2024-02-19 20:17:18 UTC
codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (791b57c) 86.64% compared to head (ed2526d) 86.66%.

:exclamation: Current head ed2526d differs from pull request most recent head 479a013. Consider uploading reports for the commit 479a013 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #3113 +/- ## =========================================== + Coverage 86.64% 86.66% +0.02% =========================================== Files 61 61 Lines 12052 12066 +14 =========================================== + Hits 10442 10457 +15 + Misses 1610 1609 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.