Skip to content

Commit 3a4c093

Browse files
committed
Expand unit tests
1 parent a728dd6 commit 3a4c093

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

reframe/core/variables.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,30 +177,30 @@ class MyRequiredTest(HelloTest):
177177
178178
'''
179179

180-
# NOTE: We can't use truly private fields in __slots__, because
181-
# __setattr__() will be called with their mangled name and we cannot match
182-
# them in the __slots__ with making implementation-defined assumptions
183-
# about the mangled name. So we just add the `_p_` prefix for "private"
180+
# NOTE: We can't use truly private fields in `__slots__`, because
181+
# `__setattr__()` will be called with their mangled name and we cannot
182+
# match them in the `__slots__` without making implementation-defined
183+
# assumptions about the mangled name. So we just add the `_p_` prefix for
184+
# to denote the "private" fields.
184185

185186
__slots__ = ('_p_default_value', '_p_field',
186187
'_loggable', '_name', '_target')
187188

188189
__mutable_props = ('_default_value',)
189190

190191
def __init__(self, *args, **kwargs):
191-
field_type = kwargs.pop('field', fields.TypedField)
192192
alias = kwargs.pop('alias', None)
193-
194-
if alias and not isinstance(alias, TestVar):
195-
raise TypeError(f"'alias' must refer to a variable; "
196-
f"found {type(alias).__name__!r}")
197-
198193
if alias and 'field' in kwargs:
199194
raise ValueError(f"'field' cannot be set for an alias variable")
200195

201196
if alias and 'value' in kwargs:
202197
raise ValueError('alias variables do not accept default values')
203198

199+
if alias and not isinstance(alias, TestVar):
200+
raise TypeError(f"'alias' must refer to a variable; "
201+
f"found {type(alias).__name__!r}")
202+
203+
field_type = kwargs.pop('field', fields.TypedField)
204204
if alias:
205205
self._p_default_value = alias._default_value
206206
else:

unittests/test_variables.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,18 @@ class T(rfm.RegressionMixin):
495495
x = variable(int, value=1)
496496
y = variable(alias=x, value=2)
497497

498+
with pytest.raises(TypeError, match=r"'alias' must refer to a variable"):
499+
class T(rfm.RegressionMixin):
500+
x = variable(int, value=1)
501+
y = variable(alias=10)
502+
503+
with pytest.raises(ValueError, match=r"'field' cannot be set"):
504+
from reframe.core.fields import TypedField
505+
506+
class T(rfm.RegressionMixin):
507+
x = variable(int, value=1)
508+
y = variable(alias=x, field=TypedField)
509+
498510
class T(rfm.RegressionMixin):
499511
x = variable(int, value=1)
500512
y = variable(alias=x)

0 commit comments

Comments
 (0)