Skip to content

Commit d970497

Browse files
committed
Stricter test of alias value
1 parent 1a8b334 commit d970497

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

reframe/core/variables.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,31 +204,30 @@ class MyRequiredTest(HelloTest):
204204

205205
def __init__(self, *args, **kwargs):
206206
alias = kwargs.pop('alias', None)
207-
if alias and 'field' in kwargs:
207+
if alias is not None and 'field' in kwargs:
208208
raise ValueError(f"'field' cannot be set for an alias variable")
209209

210-
if alias and 'value' in kwargs:
210+
if alias is not None and 'value' in kwargs:
211211
raise ValueError('alias variables do not accept default values')
212212

213-
if alias and not isinstance(alias, TestVar):
213+
if alias is not None and not isinstance(alias, TestVar):
214214
raise TypeError(f"'alias' must refer to a variable; "
215215
f"found {type(alias).__name__!r}")
216216

217217
field_type = kwargs.pop('field', fields.TypedField)
218-
if alias:
218+
if alias is not None:
219219
self._p_default_value = alias._default_value
220220
else:
221221
self._p_default_value = kwargs.pop('value', Undefined)
222222

223223
self._loggable = kwargs.pop('loggable', False)
224-
225224
if not issubclass(field_type, fields.Field):
226225
raise TypeError(
227226
f'field {field_type!r} is not derived from '
228227
f'{fields.Field.__qualname__}'
229228
)
230229

231-
if alias:
230+
if alias is not None:
232231
self._p_field = alias._field
233232
else:
234233
self._p_field = field_type(*args, **kwargs)

unittests/test_variables.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,13 @@ class T(rfm.RegressionMixin):
508508
y = variable(alias=x, field=TypedField)
509509

510510
class T(rfm.RegressionMixin):
511-
x = variable(int, value=1)
511+
x = variable(int, value=0)
512512
y = variable(alias=x)
513513
z = variable(alias=y)
514514

515515
t = T()
516-
assert t.y == 1
517-
assert t.z == 1
516+
assert t.y == 0
517+
assert t.z == 0
518518

519519
t.x = 4
520520
assert t.y == 4

0 commit comments

Comments
 (0)