def test_version_validation(self): conditions = [ VersionValidator('<=1.0.0'), VersionValidator('2.0.0..2.5'), VersionValidator('3.0') ] self.assertTrue(any(c.validate('0.1') for c in conditions)) self.assertTrue(any(c.validate('2.0.0') for c in conditions)) self.assertTrue(any(c.validate('2.2') for c in conditions)) self.assertTrue(any(c.validate('2.5') for c in conditions)) self.assertTrue(any(c.validate('3.0') for c in conditions)) self.assertFalse(any(c.validate('3.1') for c in conditions)) self.assertRaises(ValueError, VersionValidator, '2.0.0..') self.assertRaises(ValueError, VersionValidator, '..2.0.0') self.assertRaises(ValueError, VersionValidator, '1.0.0..2.0.0..3.0.0') self.assertRaises(ValueError, VersionValidator, '=>2.0.0') self.assertRaises(ValueError, VersionValidator, '2.0.0>') self.assertRaises(ValueError, VersionValidator, '2.0.0>1.0.0') self.assertRaises(ValueError, VersionValidator, '=>') self.assertRaises(ValueError, VersionValidator, '>1')
def required_version(*versions): '''Class decorator for specifying the required ReFrame versions for the following test. If the test is not compatible with the current ReFrame version it will be skipped. :arg versions: A list of ReFrame version specifications that this test is allowed to run. A version specification string can have one of the following formats: 1. ``VERSION``: Specifies a single version. 2. ``{OP}VERSION``, where ``{OP}`` can be any of ``>``, ``>=``, ``<``, ``<=``, ``==`` and ``!=``. For example, the version specification string ``'>=3.5.0'`` will allow the following test to be loaded only by ReFrame 3.5.0 and higher. The ``==VERSION`` specification is the equivalent of ``VERSION``. 3. ``V1..V2``: Specifies a range of versions. You can specify multiple versions with this decorator, such as ``@required_version('3.5.1', '>=3.5.6')``, in which case the test will be selected if *any* of the versions is satisfied, even if the versions specifications are conflicting. .. versionadded:: 2.13 .. versionchanged:: 3.5.0 Passing ReFrame version numbers that do not comply with the `semantic versioning <https://semver.org/>`__ specification is deprecated. Examples of non-compliant version numbers are ``3.5`` and ``3.5-dev0``. These should be written as ``3.5.0`` and ``3.5.0-dev.0``. ''' if not versions: raise ValueError('no versions specified') conditions = [VersionValidator(v) for v in versions] def _skip_tests(cls): mod = inspect.getmodule(cls) if not hasattr(mod, '__rfm_skip_tests'): mod.__rfm_skip_tests = set() if not any(c.validate(osext.reframe_version()) for c in conditions): getlogger().info('skipping incompatible test defined' ' in class: %s' % cls.__name__) mod.__rfm_skip_tests.add(cls) return cls return _skip_tests
def required_version(*versions): """Class decorator for specifying the required ReFrame versions for the following test. If the test is not compatible with the current ReFrame version it will be skipped. :arg versions: A list of ReFrame version specifications that this test is allowed to run. A version specification string can have one of the following formats: 1. ``VERSION``: Specifies a single version. 2. ``{OP}VERSION``, where ``{OP}`` can be any of ``>``, ``>=``, ``<``, ``<=``, ``==`` and ``!=``. For example, the version specification string ``'>=2.15'`` will only allow the following test to be loaded only by ReFrame 2.15 and higher. The ``==VERSION`` specification is the equivalent of ``VERSION``. 3. ``V1..V2``: Specifies a range of versions. You can specify multiple versions with this decorator, such as ``@required_version('2.13', '>=2.16')``, in which case the test will be selected if *any* of the versions is satisfied, even if the versions specifications are conflicting. .. versionadded:: 2.13 """ if not versions: raise ValueError('no versions specified') conditions = [VersionValidator(v) for v in versions] def _skip_tests(cls): mod = inspect.getmodule(cls) if not hasattr(mod, '__rfm_skip_tests'): mod.__rfm_skip_tests = set() if not any(c.validate(reframe.VERSION) for c in conditions): getlogger().info('skipping incompatible test defined' ' in class: %s' % cls.__name__) mod.__rfm_skip_tests.add(cls) return cls return _skip_tests
def _validate_test(cls): if not issubclass(cls, RegressionTest): raise ReframeSyntaxError('the decorated class must be a ' 'subclass of RegressionTest') if (cls.is_abstract()): getlogger().warning(f'skipping test {cls.__qualname__!r}: ' f'test has one or more undefined parameters') return False conditions = [VersionValidator(v) for v in cls._rfm_required_version] if (cls._rfm_required_version and not any(c.validate(osext.reframe_version()) for c in conditions)): getlogger().warning(f"skipping incompatible test " f"'{cls.__qualname__}': not valid for ReFrame " f"version {osext.reframe_version().split('-')[0]}") return False return True
def required_version(*versions): '''Class decorator for specifying the required ReFrame versions for the following test. If the test is not compatible with the current ReFrame version it will be skipped. :arg versions: A list of ReFrame version specifications that this test is allowed to run. A version specification string can have one of the following formats: 1. ``VERSION``: Specifies a single version. 2. ``{OP}VERSION``, where ``{OP}`` can be any of ``>``, ``>=``, ``<``, ``<=``, ``==`` and ``!=``. For example, the version specification string ``'>=3.5.0'`` will allow the following test to be loaded only by ReFrame 3.5.0 and higher. The ``==VERSION`` specification is the equivalent of ``VERSION``. 3. ``V1..V2``: Specifies a range of versions. You can specify multiple versions with this decorator, such as ``@required_version('3.5.1', '>=3.5.6')``, in which case the test will be selected if *any* of the versions is satisfied, even if the versions specifications are conflicting. .. versionadded:: 2.13 .. versionchanged:: 3.5.0 Passing ReFrame version numbers that do not comply with the `semantic versioning <https://semver.org/>`__ specification is deprecated. Examples of non-compliant version numbers are ``3.5`` and ``3.5-dev0``. These should be written as ``3.5.0`` and ``3.5.0-dev.0``. .. deprecated:: 3.5.0 Please set the ``require_version`` parameter in the class definition instead. ''' warn.user_deprecation_warning( "the '@required_version' decorator is deprecated; please set " "the 'require_version' parameter in the class definition instead", from_version='3.7.0' ) if not versions: raise ReframeSyntaxError('no versions specified') conditions = [VersionValidator(v) for v in versions] def _skip_tests(cls): mod = inspect.getmodule(cls) if not hasattr(mod, '__rfm_skip_tests'): mod.__rfm_skip_tests = set() if not hasattr(mod, '_rfm_test_registry'): mod._rfm_test_registry = TestRegistry() if not any(c.validate(osext.reframe_version()) for c in conditions): getlogger().warning( f"skipping incompatible test '{cls.__qualname__}': not valid " f"for ReFrame version {osext.reframe_version().split('-')[0]}" ) if cls in mod._rfm_test_registry: mod._rfm_test_registry.skip(cls) else: mod.__rfm_skip_tests.add(cls) return cls return _skip_tests
def test_version_validation(): conditions = [ VersionValidator('<=1.0.0'), VersionValidator('2.0.0..2.5'), VersionValidator('3.0') ] assert all([ any(c.validate('0.1') for c in conditions), any(c.validate('2.0.0') for c in conditions), any(c.validate('2.2') for c in conditions), any(c.validate('2.5') for c in conditions), any(c.validate('3.0') for c in conditions), not any(c.validate('3.1') for c in conditions) ]) with pytest.raises(ValueError): VersionValidator('2.0.0..') with pytest.raises(ValueError): VersionValidator('..2.0.0') with pytest.raises(ValueError): VersionValidator('1.0.0..2.0.0..3.0.0') with pytest.raises(ValueError): VersionValidator('=>2.0.0') with pytest.raises(ValueError): VersionValidator('2.0.0>') with pytest.raises(ValueError): VersionValidator('2.0.0>1.0.0') with pytest.raises(ValueError): VersionValidator('=>') with pytest.raises(ValueError): VersionValidator('>1')