Skip to content

Commit 4a59838

Browse files
authored
Test default value case for RepresentationMixin (#3923)
Parameters with default values take a different path in RepresentationMixin and that path was previously not tested. # Changed Behaviour none ## Type of change - Code maintenance/cleanup
1 parent 84ec5cf commit 4a59838

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

parsl/tests/test_utils/test_representation_mixin.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ def __init__(self, x, y):
99
self.y = y
1010

1111

12+
class GoodReprDefaults(RepresentationMixin):
13+
def __init__(self, x, y="default 2"):
14+
self.x = x
15+
self.y = y
16+
17+
1218
class BadRepr(RepresentationMixin):
1319
"""This class incorrectly subclasses RepresentationMixin.
1420
It does not store the parameter x on self.
@@ -31,6 +37,33 @@ def test_repr_good():
3137
assert p2 in r
3238

3339

40+
@pytest.mark.local
41+
def test_repr_good_defaults_overridden():
42+
p1 = "parameter 1"
43+
p2 = "the second parameter"
44+
45+
# repr should not raise an exception
46+
r = repr(GoodReprDefaults(p1, p2))
47+
48+
# representation should contain both values supplied
49+
# at object creation.
50+
assert p1 in r
51+
assert p2 in r
52+
53+
54+
@pytest.mark.local
55+
def test_repr_good_defaults_defaulted():
56+
p1 = "parameter 1"
57+
58+
# repr should not raise an exception
59+
r = repr(GoodReprDefaults(p1))
60+
61+
# representation should contain one value supplied
62+
# at object creation, and the other defaulted.
63+
assert p1 in r
64+
assert "default 2" in r
65+
66+
3467
@pytest.mark.local
3568
def test_repr_bad():
3669
p1 = "parameter 1"

0 commit comments

Comments
 (0)