Skip to content

Commit

Permalink
Do not allow for abbreviations of long options.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldipa committed Dec 27, 2018
1 parent 38b9946 commit fae5ca8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 9 additions & 9 deletions byexample/expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ def _get_captures_by_incremental_match(self, captures, expected_regexs,
>>> s, c = _replace_captures([], expected_regexs, charnos, rcounts, expected, got, 1, 1)
>>> s # byexample: -tag
>>> s # byexample: -tags
'aaAAbb<...>ddd<...>eeeCCcc'
>>> got = r'aaAAbBBxxxddeeeCCcc'
>>> s, c = _replace_captures([], expected_regexs, charnos, rcounts, expected, got, 1, 1)
>>> s # byexample: -tag
>>> s # byexample: -tags
'aa<...>bb<...>ddd<...>eeeCCcc'
The definition of "safely" is a little weak. A capture tag may match
Expand All @@ -343,18 +343,18 @@ def _get_captures_by_incremental_match(self, captures, expected_regexs,
and before the capture.
>>> s, c = _replace_captures([], expected_regexs, charnos, rcounts, expected, got, min_rcount=1, timeout=1)
>>> s # byexample: -tag
>>> s # byexample: -tags
'aaAAbb<...>ddd<...>eeeCCcc'
>>> s, c = _replace_captures([], expected_regexs, charnos, rcounts, expected, got, min_rcount=2, timeout=1)
>>> s # byexample: -tag
>>> s # byexample: -tags
'aaAAbb<...>ddd<...>eeeCCcc'
Notice how a value of 3 changes the result because the 'bb' literal,
after the capture has only a rcount of 2
>>> s, c = _replace_captures([], expected_regexs, charnos, rcounts, expected, got, min_rcount=3, timeout=1)
>>> s # byexample: -tag
>>> s # byexample: -tags
'aa<...>bb<...>ddd<...>eeeCCcc'
Named groups are returned as well:
Expand All @@ -370,7 +370,7 @@ def _get_captures_by_incremental_match(self, captures, expected_regexs,
>>> s, c = _replace_captures(['foo', 'b-r', 'baz', 'z-z'],
... expected_regexs, charnos, rcounts, expected, got, 1, 1)
>>> s # byexample: -tag
>>> s # byexample: -tags
'aaAAbb<b-r>ddd<baz>eeeCCcc'
>>> c
{'foo': 'AA', 'z-z': 'CC'}
Expand All @@ -397,7 +397,7 @@ def _get_captures_by_incremental_match(self, captures, expected_regexs,
>>> s, c = _replace_captures(['foo', 'bar'], expected_regexs,
... charnos, rcounts, expected, got, min_rcount=2, timeout=1)
>>> s # byexample: -tag
>>> s # byexample: -tags
'aaAAbb\ncc\ndd<bar>ee'
>>> c
{'foo': 'AA'}
Expand All @@ -414,7 +414,7 @@ def _get_captures_by_incremental_match(self, captures, expected_regexs,
>>> rcounts = [0, 2, 0, 3, 3, 2, 1, 2, 0] # notice the +1
>>> s, c = _replace_captures(['foo'], expected_regexs, charnos, rcounts, expected, got, min_rcount=2, timeout=1)
>>> s # byexample: -tag
>>> s # byexample: -tags
'aaAAbb\ncc\nddAAee'
>>> c
{'foo': 'AA'}
Expand All @@ -430,7 +430,7 @@ def _get_captures_by_incremental_match(self, captures, expected_regexs,
Setting a value of 0 virtually disable this increcmental match:
>>> s, c = _replace_captures(['foo'], expected_regexs, charnos, rcounts, expected, got, min_rcount=2, timeout=0)
>>> s # byexample: -tag
>>> s # byexample: -tags
'aa<foo>bb\ncc\ndd<foo>ee'
>>> c
{}
Expand Down
3 changes: 3 additions & 0 deletions byexample/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ def __init__(self, **kw):
# do not add -h/--help options
kw.setdefault('add_help', False)

# do not allow for abbreviations of long options
kw.setdefault('allow_abbrev', False)

argparse.ArgumentParser.__init__(self, **kw)
self.__defaults = {}

Expand Down

0 comments on commit fae5ca8

Please sign in to comment.