From c79349b92b898a8537ca33559fff396947f2e3ff Mon Sep 17 00:00:00 2001 From: Javier Otero Date: Mon, 2 Nov 2020 15:55:30 +0100 Subject: [PATCH 1/6] Add support for base reframe tests. --- reframe/core/pipeline.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/reframe/core/pipeline.py b/reframe/core/pipeline.py index 0b6292646f..952ca209f6 100644 --- a/reframe/core/pipeline.py +++ b/reframe/core/pipeline.py @@ -717,10 +717,14 @@ def __new__(cls, *args, **kwargs): try: prefix = cls._rfm_custom_prefix except AttributeError: - if osext.is_interactive(): - prefix = os.getcwd() - else: - prefix = os.path.abspath(os.path.dirname(inspect.getfile(cls))) + try: + prefix = cls._rfm_base_test_prefix + except AttributeError: + if osext.is_interactive(): + prefix = os.getcwd() + else: + prefix = os.path.abspath( + os.path.dirname(inspect.getfile(cls))) obj._rfm_init(name, prefix) return obj @@ -729,10 +733,16 @@ def __init__(self): pass @classmethod - def __init_subclass__(cls, *, special=False, **kwargs): + def __init_subclass__(cls, *, special=False, base_test=False, **kwargs): super().__init_subclass__(**kwargs) cls._rfm_special_test = special + # Insert the base test path as the prefix if the class is marked + # as a base test. + if base_test: + cls._rfm_base_test_prefix = os.path.abspath( + os.path.dirname(inspect.getfile(cls))) + def _rfm_init(self, name=None, prefix=None): if name is not None: self.name = name From 10c03da49dc3430125b512230dd21bc071f52240 Mon Sep 17 00:00:00 2001 From: Javier Otero Date: Tue, 3 Nov 2020 14:48:24 +0100 Subject: [PATCH 2/6] Add unit test for base tests. --- unittests/resources/checks/hellocheck_base.py | 18 ++++++++++++++++++ unittests/test_pipeline.py | 8 ++++++++ 2 files changed, 26 insertions(+) create mode 100644 unittests/resources/checks/hellocheck_base.py diff --git a/unittests/resources/checks/hellocheck_base.py b/unittests/resources/checks/hellocheck_base.py new file mode 100644 index 0000000000..a2b2719c21 --- /dev/null +++ b/unittests/resources/checks/hellocheck_base.py @@ -0,0 +1,18 @@ +# Copyright 2016-2020 Swiss National Supercomputing Centre (CSCS/ETH Zurich) +# ReFrame Project Developers. See the top-level LICENSE file for details. +# +# SPDX-License-Identifier: BSD-3-Clause + +import reframe as rfm +import reframe.utility.sanity as sn + +class HelloBaseTest(rfm.RunOnlyRegressionTest, base_test=True): + def __init__(self): + self.executable = './hello.sh' + self.executable_opts = ['Hello, World!'] + self.local = True + self.valid_prog_environs = ['*'] + self.valid_systems = ['*'] + self.sanity_patterns = sn.assert_found( + r'Hello, World\!', self.stdout) + diff --git a/unittests/test_pipeline.py b/unittests/test_pipeline.py index 22cbc887d7..4ab5143ffa 100644 --- a/unittests/test_pipeline.py +++ b/unittests/test_pipeline.py @@ -18,6 +18,7 @@ SanityError) from reframe.frontend.loader import RegressionCheckLoader from unittests.resources.checks.hellocheck import HelloTest +from unittests.resources.checks.hellocheck_base import HelloBaseTest def _run(test, partition, prgenv): @@ -246,6 +247,13 @@ def __init__(self): _run(MyTest(), *local_exec_ctx) +def test_base_test(local_exec_ctx): + class MyTest(HelloBaseTest): + pass + + _run(MyTest(), *local_exec_ctx) + + def test_supports_system(hellotest, testsys_system): hellotest.valid_systems = ['*'] assert hellotest.supports_system('gpu') From cf8a684398bf13087284c4a42342b917a9a1e221 Mon Sep 17 00:00:00 2001 From: Javier Otero Date: Tue, 3 Nov 2020 14:50:41 +0100 Subject: [PATCH 3/6] Fix PEP8 issues. --- unittests/resources/checks/hellocheck_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/resources/checks/hellocheck_base.py b/unittests/resources/checks/hellocheck_base.py index a2b2719c21..e98f250d4a 100644 --- a/unittests/resources/checks/hellocheck_base.py +++ b/unittests/resources/checks/hellocheck_base.py @@ -6,6 +6,7 @@ import reframe as rfm import reframe.utility.sanity as sn + class HelloBaseTest(rfm.RunOnlyRegressionTest, base_test=True): def __init__(self): self.executable = './hello.sh' @@ -15,4 +16,3 @@ def __init__(self): self.valid_systems = ['*'] self.sanity_patterns = sn.assert_found( r'Hello, World\!', self.stdout) - From eb727e959d20a00ca5eeac3b9f9f1be10036b076 Mon Sep 17 00:00:00 2001 From: "Javier J. Otero Perez" Date: Mon, 16 Nov 2020 11:36:21 +0100 Subject: [PATCH 4/6] Change base_test argument to pin_prefix --- reframe/core/pipeline.py | 22 +++++++++---------- unittests/resources/checks/hellocheck_base.py | 18 --------------- unittests/resources/checks/pinnedcheck.py | 11 ++++++++++ unittests/test_pipeline.py | 8 +++---- 4 files changed, 26 insertions(+), 33 deletions(-) delete mode 100644 unittests/resources/checks/hellocheck_base.py create mode 100644 unittests/resources/checks/pinnedcheck.py diff --git a/reframe/core/pipeline.py b/reframe/core/pipeline.py index 7addd3e9d9..27cc699206 100644 --- a/reframe/core/pipeline.py +++ b/reframe/core/pipeline.py @@ -722,12 +722,12 @@ def __new__(cls, *args, **kwargs): try: prefix = cls._rfm_custom_prefix except AttributeError: - try: - prefix = cls._rfm_base_test_prefix - except AttributeError: - if osext.is_interactive(): - prefix = os.getcwd() - else: + if osext.is_interactive(): + prefix = os.getcwd() + else: + try: + prefix = cls._rfm_pinned_prefix + except AttributeError: prefix = os.path.abspath( os.path.dirname(inspect.getfile(cls))) @@ -738,14 +738,14 @@ def __init__(self): pass @classmethod - def __init_subclass__(cls, *, special=False, base_test=False, **kwargs): + def __init_subclass__(cls, *, special=False, pin_prefix=False, **kwargs): super().__init_subclass__(**kwargs) cls._rfm_special_test = special - # Insert the base test path as the prefix if the class is marked - # as a base test. - if base_test: - cls._rfm_base_test_prefix = os.path.abspath( + # Insert the prefix to pin the test to if the test lives in a test + # library with resources in it. + if pin_prefix: + cls._rfm_pinned_prefix = os.path.abspath( os.path.dirname(inspect.getfile(cls))) def _rfm_init(self, name=None, prefix=None): diff --git a/unittests/resources/checks/hellocheck_base.py b/unittests/resources/checks/hellocheck_base.py deleted file mode 100644 index e98f250d4a..0000000000 --- a/unittests/resources/checks/hellocheck_base.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2016-2020 Swiss National Supercomputing Centre (CSCS/ETH Zurich) -# ReFrame Project Developers. See the top-level LICENSE file for details. -# -# SPDX-License-Identifier: BSD-3-Clause - -import reframe as rfm -import reframe.utility.sanity as sn - - -class HelloBaseTest(rfm.RunOnlyRegressionTest, base_test=True): - def __init__(self): - self.executable = './hello.sh' - self.executable_opts = ['Hello, World!'] - self.local = True - self.valid_prog_environs = ['*'] - self.valid_systems = ['*'] - self.sanity_patterns = sn.assert_found( - r'Hello, World\!', self.stdout) diff --git a/unittests/resources/checks/pinnedcheck.py b/unittests/resources/checks/pinnedcheck.py new file mode 100644 index 0000000000..bc55786000 --- /dev/null +++ b/unittests/resources/checks/pinnedcheck.py @@ -0,0 +1,11 @@ +# Copyright 2016-2020 Swiss National Supercomputing Centre (CSCS/ETH Zurich) +# ReFrame Project Developers. See the top-level LICENSE file for details. +# +# SPDX-License-Identifier: BSD-3-Clause + +import reframe as rfm +import reframe.utility.sanity as sn + + +class PinnedTest(rfm.RunOnlyRegressionTest, pin_prefix=True): + pass diff --git a/unittests/test_pipeline.py b/unittests/test_pipeline.py index 4ab5143ffa..f7dc0c8b32 100644 --- a/unittests/test_pipeline.py +++ b/unittests/test_pipeline.py @@ -18,7 +18,7 @@ SanityError) from reframe.frontend.loader import RegressionCheckLoader from unittests.resources.checks.hellocheck import HelloTest -from unittests.resources.checks.hellocheck_base import HelloBaseTest +from unittests.resources.checks.pinnedcheck import PinnedTest def _run(test, partition, prgenv): @@ -248,11 +248,11 @@ def __init__(self): def test_base_test(local_exec_ctx): - class MyTest(HelloBaseTest): + class MyTest(PinnedTest): pass - _run(MyTest(), *local_exec_ctx) - + pinned = Mytest() + assert 'unittests/resources/checks' in pinned._rfm_pinned_prefix def test_supports_system(hellotest, testsys_system): hellotest.valid_systems = ['*'] From 30c7629bfc4a1f48999936f5d252eb1b7c8b5db7 Mon Sep 17 00:00:00 2001 From: Javier Otero Date: Mon, 16 Nov 2020 11:51:09 +0100 Subject: [PATCH 5/6] Add additional assert to pinned check. --- unittests/test_pipeline.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unittests/test_pipeline.py b/unittests/test_pipeline.py index f7dc0c8b32..26d16d82b0 100644 --- a/unittests/test_pipeline.py +++ b/unittests/test_pipeline.py @@ -247,11 +247,12 @@ def __init__(self): _run(MyTest(), *local_exec_ctx) -def test_base_test(local_exec_ctx): +def test_pinned_test(local_exec_ctx): class MyTest(PinnedTest): pass - pinned = Mytest() + pinned = MyTest() + assert hasattr(pinned, '_rfm_pinned_prefix') assert 'unittests/resources/checks' in pinned._rfm_pinned_prefix def test_supports_system(hellotest, testsys_system): From 213462ab29fd5b9fa8975f978d6dfc002871d605 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Tue, 17 Nov 2020 16:44:15 +0100 Subject: [PATCH 6/6] Minor coding style improvements + fine tuning of the unit test --- reframe/core/pipeline.py | 6 ++++-- unittests/resources/checks/pinnedcheck.py | 3 +-- unittests/test_pipeline.py | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/reframe/core/pipeline.py b/reframe/core/pipeline.py index 27cc699206..839a3b5a35 100644 --- a/reframe/core/pipeline.py +++ b/reframe/core/pipeline.py @@ -729,7 +729,8 @@ def __new__(cls, *args, **kwargs): prefix = cls._rfm_pinned_prefix except AttributeError: prefix = os.path.abspath( - os.path.dirname(inspect.getfile(cls))) + os.path.dirname(inspect.getfile(cls)) + ) obj._rfm_init(name, prefix) return obj @@ -746,7 +747,8 @@ def __init_subclass__(cls, *, special=False, pin_prefix=False, **kwargs): # library with resources in it. if pin_prefix: cls._rfm_pinned_prefix = os.path.abspath( - os.path.dirname(inspect.getfile(cls))) + os.path.dirname(inspect.getfile(cls)) + ) def _rfm_init(self, name=None, prefix=None): if name is not None: diff --git a/unittests/resources/checks/pinnedcheck.py b/unittests/resources/checks/pinnedcheck.py index bc55786000..5be06b375c 100644 --- a/unittests/resources/checks/pinnedcheck.py +++ b/unittests/resources/checks/pinnedcheck.py @@ -4,8 +4,7 @@ # SPDX-License-Identifier: BSD-3-Clause import reframe as rfm -import reframe.utility.sanity as sn class PinnedTest(rfm.RunOnlyRegressionTest, pin_prefix=True): - pass + '''A simple base test for verifying that prefix pinning works correctly''' diff --git a/unittests/test_pipeline.py b/unittests/test_pipeline.py index 26d16d82b0..462572fccd 100644 --- a/unittests/test_pipeline.py +++ b/unittests/test_pipeline.py @@ -252,8 +252,9 @@ class MyTest(PinnedTest): pass pinned = MyTest() - assert hasattr(pinned, '_rfm_pinned_prefix') - assert 'unittests/resources/checks' in pinned._rfm_pinned_prefix + expected_prefix = os.path.join(os.getcwd(), 'unittests/resources/checks') + assert pinned._prefix == expected_prefix + def test_supports_system(hellotest, testsys_system): hellotest.valid_systems = ['*']