From dcef43755dac43a11db3c4d8304f5fed2640a7d6 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 31 May 2022 18:14:33 +0300 Subject: [PATCH] fix: Reading xml files from folder --- failure_analysis/failure_analysis.py | 6 +----- utest/rerources/failing_01_.xml | 14 ++++++++++++++ utest/rerources/failing_02_.xml | 14 ++++++++++++++ utest/rerources/pass_01_.xml | 7 +++++++ utest/test_similarity.py | 29 +++++++++++++++++++++++++++- 5 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 utest/rerources/failing_01_.xml create mode 100644 utest/rerources/failing_02_.xml create mode 100644 utest/rerources/pass_01_.xml diff --git a/failure_analysis/failure_analysis.py b/failure_analysis/failure_analysis.py index c0264ff..4f26b6f 100644 --- a/failure_analysis/failure_analysis.py +++ b/failure_analysis/failure_analysis.py @@ -1,5 +1,4 @@ import argparse -import glob as glob import itertools import os from difflib import SequenceMatcher @@ -19,10 +18,7 @@ def parse_xml(path): testname = [] filename = [] classname = [] - - path = [f for f in glob.glob(path + "*.xml")] - - for xml in path: + for xml in Path(path).glob("*.xml"): tree = etree.parse(xml) root = tree.getroot() if int(root.find("testsuite").attrib["failures"]) > 0: diff --git a/utest/rerources/failing_01_.xml b/utest/rerources/failing_01_.xml new file mode 100644 index 0000000..60e60c8 --- /dev/null +++ b/utest/rerources/failing_01_.xml @@ -0,0 +1,14 @@ + + + + + + def test_02(): +> assert False +E assert False + + +tests\test_me.py:6: AssertionError + + + \ No newline at end of file diff --git a/utest/rerources/failing_02_.xml b/utest/rerources/failing_02_.xml new file mode 100644 index 0000000..7c0321e --- /dev/null +++ b/utest/rerources/failing_02_.xml @@ -0,0 +1,14 @@ + + + + + + def test_02(): +> assert False +E assert False + + +tests\test_me.py:6: AssertionError + + + \ No newline at end of file diff --git a/utest/rerources/pass_01_.xml b/utest/rerources/pass_01_.xml new file mode 100644 index 0000000..86cb646 --- /dev/null +++ b/utest/rerources/pass_01_.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/utest/test_similarity.py b/utest/test_similarity.py index b9fa84e..e22de08 100644 --- a/utest/test_similarity.py +++ b/utest/test_similarity.py @@ -1,7 +1,25 @@ +from pathlib import Path + import numpy as np import itertools -from failure_analysis.failure_analysis import jaccard_similarity, cosine_sim_vectors, score_failures +from failure_analysis.failure_analysis import jaccard_similarity, cosine_sim_vectors, score_failures, run + +UTEST_ROOT = Path(".").resolve() +EXPECTED_OUTPUT_START = """============== FAILURE START ================= +def test_02(): +> assert False +E assert False + + +""" + +EXPECTED_OUTPUT_END = """============== FAILURE END ================= + cos leven +suitename2 testname2 filename2 +tests.test_me test_02 failing_01_.xml 1.0 1.0 + failing_02_.xml 1.0 1.0 +""" # noqa: W291 def test_jaccard_similarity(): @@ -31,3 +49,12 @@ def test_score_failures(): assert sum_jaccard > 0 assert sum_jaros > 0 assert sum_levens > 0 + + +def test_console_output(capsys): + xunit_files = UTEST_ROOT / "rerources" + run(str(xunit_files)) + 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