Skip to content

Commit

Permalink
Merge pull request #48 from miqsoft/allow-empty-cvparam
Browse files Browse the repository at this point in the history
Allow empty CVParameter value by default and add a corresponding
unit test. The original case where this was needed was while
exporting a TextFinder to a match file where we will get a match file
which cannot be used unless this default is allowed:

```
finder = TextFinder()
TextFinder.to_match_file(finder, 'test.match') 
```
  • Loading branch information
pevogam authored Mar 7, 2023
2 parents f9eacac + 25080a9 commit 7085fda
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion guibot/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def from_string(raw):
:raises: :py:class:`ValueError` if unsupported type is encountered
"""
args = []
string_args = re.match(r"<value='(.+)' min='(-?[\d.None]+)' max='([\d.None]+)'"
string_args = re.match(r"<value='(.*)' min='(-?[\d.None]+)' max='([\d.None]+)'"
r" delta='([\d.]+)' tolerance='([\d.]+)' fixed='(\w+)' enumerated='(\w+)'>",
raw).group(1, 2, 3, 4, 5, 6)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,5 +1054,15 @@ def test_value_with_dots(self):
parsed = CVParameter.from_string("<value='123456789.' min='None' max='None' delta='1030.25' tolerance='10.2' fixed='False' enumerated='False'>")
self.assertEqual(parsed, expected)

def test_empty_value(self):
"""Check that the parser handles empty CVParameter value gracefully."""
expected = CVParameter(
"", min_val=None, max_val=None, delta=10.0,
tolerance=1.0, fixed=True, enumerated=False
)
parsed = CVParameter.from_string("<value='' min='None' max='None' delta='10.0' tolerance='1.0' fixed='True' enumerated='False'>")
self.assertEqual(parsed, expected)


if __name__ == '__main__':
unittest.main()

0 comments on commit 7085fda

Please sign in to comment.