Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Prove that no failures in xunit fails analysis #27

Merged
1 commit merged into from Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"