Skip to content

Commit 1a8b334

Browse files
committed
Treat correctly variable deprecations
1 parent 1578473 commit 1a8b334

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

reframe/core/variables.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,12 @@ def create_deprecated(cls, var, message,
246246
ret._target = var._target
247247
return ret
248248

249-
def _check_deprecation(self, kind):
250-
if isinstance(self.field, fields.DeprecatedField):
251-
if self.field.op & kind:
252-
user_deprecation_warning(self.field.message)
249+
def _warn_deprecation(self, kind):
250+
if self.is_deprecated() and self.field.op & kind:
251+
user_deprecation_warning(self.field.message)
252+
253+
def is_deprecated(self):
254+
return isinstance(self._p_field, fields.DeprecatedField)
253255

254256
def is_loggable(self):
255257
return self._loggable
@@ -261,7 +263,7 @@ def undefine(self):
261263
self._default_value = Undefined
262264

263265
def define(self, value):
264-
self._check_deprecation(DEPRECATE_WR)
266+
self._warn_deprecation(DEPRECATE_WR)
265267
self._default_value = value
266268

267269
@property
@@ -283,11 +285,14 @@ def default_value(self):
283285
# Variables must be returned by-value to prevent an instance from
284286
# modifying the class variable space.
285287
self._check_is_defined()
286-
self._check_deprecation(DEPRECATE_RD)
288+
self._warn_deprecation(DEPRECATE_RD)
287289
return copy.deepcopy(self._default_value)
288290

289291
@property
290292
def _field(self):
293+
if self.is_deprecated():
294+
return self._p_field
295+
291296
if self._target:
292297
return self._target._field
293298
else:
@@ -677,7 +682,7 @@ def __init__(self, other):
677682
for name in self.__slots__:
678683
setattr(self, name, getattr(other, name))
679684

680-
self._check_deprecation(DEPRECATE_RD)
685+
self._warn_deprecation(DEPRECATE_RD)
681686

682687

683688
class VarSpace(namespaces.Namespace):

unittests/test_variables.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import reframe as rfm
1111
from reframe.core.exceptions import ReframeSyntaxError
12+
from reframe.core.warnings import ReframeDeprecationWarning
1213

1314

1415
@pytest.fixture
@@ -458,7 +459,6 @@ class A(rfm.RegressionTest):
458459

459460
def test_var_deprecation():
460461
from reframe.core.variables import DEPRECATE_RD, DEPRECATE_WR
461-
from reframe.core.warnings import ReframeDeprecationWarning
462462

463463
# Check read deprecation
464464
class A(rfm.RegressionMixin):
@@ -544,3 +544,15 @@ class S(T):
544544

545545
s.x = 3
546546
assert s.y == 3
547+
548+
# Test deprecated aliases
549+
class S(T):
550+
y = deprecate(variable(alias=x), f'y is deprecated')
551+
552+
with pytest.warns(ReframeDeprecationWarning):
553+
class U(S):
554+
y = 10
555+
556+
s = S()
557+
with pytest.warns(ReframeDeprecationWarning):
558+
s.y = 10

0 commit comments

Comments
 (0)