Skip to content

Commit

Permalink
Add bail out (#22)
Browse files Browse the repository at this point in the history
* Add an option to disable pretty printing

It can be useful to save some space on disk for big files.

Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>

* Add Bail Out parsing as TAP version 13 specifies it.

Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>

* Improve XML output for missing tests

And a test case for Bail Out

Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>

* Update lint_python to add test file on bailout

Add recursive option for isort and update .gitignore for mypy generated directory

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
  • Loading branch information
fmartinsons authored May 9, 2021
1 parent f7ed9be commit be4ce46
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ jobs:
- run: black --check .
- run: codespell --quiet-level=2 --skip="*.tap" # --ignore-words-list=""
- run: flake8 . --max-line-length=88 --show-source --statistics
- run: isort --check-only --profile black . || true
- run: isort -rc --check-only --profile black . || true
- run: pip install junit_xml yamlish
- run: mypy --ignore-missing-imports .
- run: pytest . || true
- run: pytest --doctest-modules . || true
- run: shopt -s globstar && pyupgrade --py36-plus **/*.py
- run: safety check
- run: |
for FILENAME in test-eslint1 test-eslint2 test-eslint3 test test2 test3; do
for FILENAME in test-eslint1 test-eslint2 test-eslint3 test test2 test3 test-bailout; do
echo "Testing ${FILENAME}..."
python tap2junit/tap13.py
python -m tap2junit -i "test/fixtures/${FILENAME}.tap" -o "test/output/${FILENAME}.xml"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
# virtualenv
/.venv

.mypy_cache

dist
build
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ env:
- FILENAME=test
- FILENAME=test2
- FILENAME=test3
- FILENAME=test-bailout
install: pip install flake8 junit-xml yamlish
before_script: flake8 . --max-line-length=88
script:
Expand Down
11 changes: 7 additions & 4 deletions tap2junit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def map_yaml_to_junit(test):
t.add_error_info(error_message, err_output, err_code)
else:
t.add_failure_info(error_message, err_output, err_code)

t.stderr = test.diagnostics
return t


Expand All @@ -37,11 +37,11 @@ def parse(name, data):
return TestSuite(name, junit_tests, platform.node())


def convert(in_file, out_file):
def convert(in_file, out_file, pretty=True):
input_file = os.path.splitext(in_file.name)[0]
data = in_file.read()
result = parse(input_file, data)
TestSuite.to_file(out_file, [result], prettyprint=True, encoding="utf-8")
TestSuite.to_file(out_file, [result], prettyprint=pretty, encoding="utf-8")


def main():
Expand All @@ -60,8 +60,11 @@ def main():
help="output file name",
required=True,
)
arg_parser.add_argument(
"--compact", "-c", action="store_true", help="do not prettify the xml output"
)
args = arg_parser.parse_args()
convert(args.input, args.output)
convert(args.input, args.output, pretty=not args.compact)


if __name__ == "__main__":
Expand Down
18 changes: 15 additions & 3 deletions tap2junit/tap13.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
)
RE_TEST_LINE = re.compile(
(
r"^\s*(?P<result>(not\s+)?ok)\s*(?P<id>\d+)?\s*(?P<description>[^#]+)"
r"^\s*(?P<result>(not\s+)?ok|Bail out\!)\s*"
r"(?P<id>\d+)?\s*(?P<description>[^#]+)"
r"?\s*(#\s*(?P<directive>TODO|SKIP)?\s*(?P<comment>.+)?)?\s*$"
),
re.IGNORECASE,
Expand Down Expand Up @@ -140,6 +141,12 @@ def _parse(self, source):
)
self.__tests_counter += 1
t = Test(**t_attrs)
if t.result == "Bail out!":
t.result = "not ok"
# according to TAP13 specs, everything after this is an
# explanation of why testing must be stopped
t.diagnostics = t.diagnostics or t.description
t.description = "Bail out for Test %s" % self.__tests_counter
self.tests.append(t)
in_test = True
continue
Expand All @@ -150,9 +157,14 @@ def _parse(self, source):

if len(self.tests) != self.tests_planned:
for i in range(len(self.tests), self.tests_planned):
self.tests.append(
Test("not ok", i + 1, comment="DIAG: Test %s not present")
t = Test(
"not ok",
i + 1,
description="Test %s missing" % (i + 1),
comment="DIAG: Test %s not present" % (i + 1),
)
t.yaml = {"severity": "missing", "exitcode": -1}
self.tests.append(t)

def parse(self, source):
if isinstance(source, str):
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/test-bailout.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TAP version 13
1..5
ok 1 /MyTest/1
ok 2 /MyTest/2
# My test 2 comments
ok 3 /MyTest/3
Bail out! Fatal condition met which prevent to continue

0 comments on commit be4ce46

Please sign in to comment.