Skip to content

Commit

Permalink
Merge pull request #27 from tatu-aalto/no_failures
Browse files Browse the repository at this point in the history
test: Prove that no failures in xunit fails analysis
  • Loading branch information
Tatu Aalto authored Jun 1, 2022
2 parents 3134b70 + d2f8b5c commit 275000f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion failure_analysis/failure_analysis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import itertools
import os
import sys
from difflib import SequenceMatcher
from pathlib import Path

Expand Down Expand Up @@ -93,7 +94,7 @@ def run(path: str):

if len(failure) == 0:
print("NO FAILURES FOUND")
exit()
sys.exit(0)

testnames = list(itertools.permutations(testname, 2))
failures = list(itertools.permutations(failure, 2))
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 21 additions & 2 deletions utest/test_similarity.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import shutil
import tempfile
from pathlib import Path

import numpy as np
Expand All @@ -8,6 +10,7 @@
from failure_analysis.failure_analysis import jaccard_similarity, cosine_sim_vectors, score_failures, run

UTEST_ROOT = Path(__file__).resolve().parent
XUNIT_FILES_DIR = UTEST_ROOT / "resources"
EXPECTED_OUTPUT_START = """============== FAILURE START =================
def test_02():
> assert False
Expand Down Expand Up @@ -59,9 +62,25 @@ def test_invalid_path():


def test_console_output(capsys):
xunit_files = UTEST_ROOT / "rerources"
run(str(xunit_files))
run(str(XUNIT_FILES_DIR))
captured = capsys.readouterr()
assert EXPECTED_OUTPUT_START in captured.out
assert EXPECTED_OUTPUT_END in captured.out
assert "test_me.py:6: AssertionError\n" in captured.out


def test_no_failures(capsys):
with pytest.raises(SystemExit):
with tempfile.TemporaryDirectory() as temp_folder:
file_name = "pass_01_.xml"
xunit_pass_file = XUNIT_FILES_DIR / file_name
shutil.copy(xunit_pass_file, Path(temp_folder) / file_name)
run(temp_folder)
captured = capsys.readouterr()
assert captured.out == "NO FAILURES FOUND"

with pytest.raises(SystemExit):
with tempfile.TemporaryDirectory() as temp_folder:
run(temp_folder)
captured = capsys.readouterr()
assert captured.out == "NO FAILURES FOUND"

0 comments on commit 275000f

Please sign in to comment.