Skip to content

Commit

Permalink
tested existing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed May 12, 2023
1 parent bf18238 commit 5b03e57
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions tests/unit/test_param_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,11 @@ def test_parameter_graph_mixing_offset_and_conditional(self):

class myParam():
def __init__(
self, expect, raw_str,
self, raw_str,
parameter_values={}, templates={}, raises=None,
xfail=False,
id=None,
expect=None,
):# -> None:
"""Ease of reading wrapper for pytest.param
Expand All @@ -376,7 +377,7 @@ def __init__(
self.templates = templates
self.parameters = ((parameter_values, templates))
self.name_expander = NameExpander(self.parameters)
self.id = id
self.id = 'raises:' + id if raises else id

def get(self):
return param(self, id=self.id)
Expand All @@ -390,13 +391,27 @@ def get(self):
raw_str='no_params_here',
id='basic'
).get(),
myParam(
expect=({'bar': 1}, 'bar1'),
raw_str='<bar>',
parameter_values={'bar': 1},
templates={'bar': 'bar%(bar)s'},
id='one-valid-param'
).get(),
myParam(
expect=({'bar': 1}, 'foo_bar1_baz'),
raw_str='foo<bar>baz',
parameter_values={'bar': 1},
templates={'bar': '_bar%(bar)s_'},
id='one-valid-param'
).get(),
myParam(
raw_str='foo<bar>baz',
parameter_values={'qux': 2},
templates={'bar': '_bar%(bar)s_'},
raises=(ParamExpandError, 'parameter \'bar\' undefined'),
id='one-invalid-param'
).get(),
myParam(
expect=({'bar': 1, 'baz': 42}, 'foo_bar1_baz42'),
raw_str='foo<bar, baz>',
Expand All @@ -413,12 +428,9 @@ def get(self):
xfail=True,
).get(),
myParam(
expect=({'bar': 1}, 'foo_bar1_baz'),
raw_str='foo<bar-1>baz',
parameter_values={'bar': 1},
templates={'bar': '_bar%(bar)s_'},
raises=(ParamExpandError, '^parameter offsets illegal here'),
id='fails:offsets-illegal'
id='offsets-illegal'
).get(),
myParam(
expect=({'bar': 1}, 'foo_bar1_baz'),
Expand All @@ -427,16 +439,31 @@ def get(self):
templates={'bar': '_bar%(bar)s_'},
id='value-set'
).get(),
myParam(
raw_str='foo<bar=3>baz',
parameter_values={'bar': [1, 2]},
raises=(ParamExpandError, '^illegal'),
id='illegal-value'
).get(),
myParam(
expect=({'bar': 1}, 'foo_bar1_baz'),
raw_str='foo<bar=3>baz',
raises=(ParamExpandError, '^parameter \'bar\' undefined'),
id='parameter-undefined'
).get(),
)
)
def test_expand_parent_params(param):
if param.xfail:
pytest.skip('Functionality yet to be added')

if not param.raises:
# Good Path tests:
result = param.name_expander.expand_parent_params(
param.raw_str, param.parameter_values, 'Errortext')
assert result == param.expect
else:
# Bad path tests:
with pytest.raises(param.raises[0], match=param.raises[1]):
param.name_expander.expand_parent_params(
param.raw_str, param.parameter_values, 'Errortext')

0 comments on commit 5b03e57

Please sign in to comment.