-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for inline comments to validate spec
Signed-off-by: Justin Abrahms <[email protected]>
- Loading branch information
1 parent
c0739a1
commit b3e85a8
Showing
3 changed files
with
167 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mypy | ||
pytest | ||
pytest-cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import re | ||
from spec_finder import find_covered_specs, gen_report | ||
|
||
def test_simple_singleline(): | ||
text = """ | ||
// spec:4.3.6:The after stage MUST run after flag resolution occurs. It accepts a hook context (required), flag evaluation details (required) and hook hints (optional). It has no return value.:end | ||
""" | ||
cfg = { | ||
'multiline_regex': r'spec:(.*):end', | ||
'number_subregex': r'(?P<number>[\d.]+):', | ||
'text_subregex': r'[\d.]+:(.*)', | ||
'inline_comment_prefix': '//', | ||
} | ||
output = find_covered_specs(cfg, text) | ||
assert '4.3.6' in output | ||
assert output['4.3.6']['text'] == "The after stage MUST run after flag resolution occurs. It accepts a hook context (required), flag evaluation details (required) and hook hints (optional). It has no return value." | ||
|
||
|
||
def test_multiline_comment(): | ||
text = """ | ||
// spec:4.3.7:The error hook MUST run when errors are encountered in the | ||
// before stage, the after stage or during flag resolution. It accepts hook | ||
// context (required), exception representing what went wrong (required), and | ||
// hook hints (optional). It has no return value.:end | ||
""" | ||
cfg = { | ||
'multiline_regex': r'spec:(.*):end', | ||
'number_subregex': r'(?P<number>[\d.]+):', | ||
'text_subregex': r'[\d.]+:(.*)', | ||
'inline_comment_prefix': '//', | ||
} | ||
output = find_covered_specs(cfg, text) | ||
assert '4.3.7' in output | ||
assert output['4.3.7']['text'] == """The error hook MUST run when errors are encountered in the before stage, the after stage or during flag resolution. It accepts hook context (required), exception representing what went wrong (required), and hook hints (optional). It has no return value.""" | ||
|
||
|
||
def test_report(): | ||
spec = { | ||
'1.2.3': "good text", | ||
'2.3.4': 'different text', | ||
'3.4.5': 'missing' | ||
} | ||
|
||
repo = { | ||
'1.2.3': 'good text', | ||
'2.3.4': 'it is different', | ||
'4.5.6': 'extra' | ||
} | ||
|
||
report = gen_report(spec, repo) | ||
assert len(report['good']) == 1 | ||
assert len(report['different-text']) == 1 | ||
assert len(report['missing']) == 1 | ||
assert len(report['extra']) == 1 | ||
|
||
assert report['good'] == set(['1.2.3']) | ||
assert report['different-text'] == set(['2.3.4']) | ||
assert report['missing'] == set(['3.4.5']) | ||
assert report['extra'] == set(['4.5.6']) |