Skip to content

Commit

Permalink
fix: Reading xml files from folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatu Aalto committed May 31, 2022
1 parent 4f4f6c0 commit dcef437
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
6 changes: 1 addition & 5 deletions failure_analysis/failure_analysis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import glob as glob
import itertools
import os
from difflib import SequenceMatcher
Expand All @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions utest/rerources/failing_01_.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite name="pytest" errors="0" failures="1" skipped="0" tests="2" time="1.188" timestamp="2022-05-30T13:49:18.865623" hostname="PC">
<testcase classname="tests.test_me" name="test_01" file="tests\test_me.py" line="0" time="0.025"/>
<testcase classname="tests.test_me" name="test_02" file="tests\test_me.py" line="4" time="0.014">
<failure message="assert False">def test_02():
&gt; assert False
E assert False


tests\test_me.py:6: AssertionError</failure>
</testcase>
</testsuite>
</testsuites>
14 changes: 14 additions & 0 deletions utest/rerources/failing_02_.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite name="pytest" errors="0" failures="1" skipped="0" tests="2" time="1.188" timestamp="2022-05-30T14:49:18.865623" hostname="PC">
<testcase classname="tests.test_me" name="test_01" file="tests\test_me.py" line="0" time="0.025"/>
<testcase classname="tests.test_me" name="test_02" file="tests\test_me.py" line="4" time="0.014">
<failure message="assert False">def test_02():
&gt; assert False
E assert False


tests\test_me.py:6: AssertionError</failure>
</testcase>
</testsuite>
</testsuites>
7 changes: 7 additions & 0 deletions utest/rerources/pass_01_.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite name="pytest" errors="0" failures="0" skipped="0" tests="2" time="1.188" timestamp="2022-05-30T14:49:18.865623" hostname="PC">
<testcase classname="tests.test_me" name="test_01" file="tests\test_me.py" line="0" time="0.025"/>
<testcase classname="tests.test_me" name="test_02" file="tests\test_me.py" line="0" time="0.014"/>
</testsuite>
</testsuites>
29 changes: 28 additions & 1 deletion utest/test_similarity.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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

0 comments on commit dcef437

Please sign in to comment.