Commit 6356fcfb authored by M. Huang's avatar M. Huang
Browse files

v1.0.1 minor test case for valid

parent 35a328ab
......@@ -17,7 +17,7 @@ To install (It is a good idea to add ``--user`` at the end or to use a virtualen
.. code-block:: shell
python3 -m pip install http://mercury.bao.ac.cn:9006/mh/fdi/-/archive/v1.0/fdi-v1.0.tar.gz
python3 -m pip install http://mercury.bao.ac.cn:9006/mh/fdi/-/archive/v1.0.1/fdi-v1.0.1.tar.gz
If you want to install the ``develop`` branch:
......
......@@ -422,15 +422,20 @@ f With two positional arguments: arg1-> value, arg2-> description. Parame
# like {'foo': 0b10, 'bar': 0b0110}
return {into[mask]: value for mask, value in masks.items()}
def validate(self, value):
def validate(self, value=INVALID):
""" checks if a match the rule set.
value: will be checked against the ruleset. Default is ``self._valid``.
returns:
(valid value, rule name) for discrete and range rules.
{mask: (valid val, rule name, mask_height, mask_width), ...} for binary masks rules.
(INVALID, 'Invalid') if no matching is found.
(value, 'Default') if rule set is empty.
"""
if value is INVALID:
value = self._value
ruleset = self.getValid()
if ruleset is None or len(ruleset) == 0:
return (value, 'Default')
......
......@@ -592,6 +592,13 @@ def test_Parameter_valid():
assert v.split({0b110000: 'foo', 0b001111: 'bar'}) == {
'foo': 0b10, 'bar': 0b0110}
# display
v = StringParameter('Right', 'str parameter. but only "" is allowed.',
valid={'': 'empty'}, default='cliche', typecode='B')
assert v.validate() == (INVALID, 'Invalid')
assert v.validate('') == ('', 'empty')
assert v.toString(alist=True)[0] == 'Invalid (Right)'
def test_Parameter_features():
# test equivalence of v.setXxxx(a) and v.xxx = a
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment