Skip to content

Commit

Permalink
Merge pull request #61 from codecov/joseph/quick-fixes
Browse files Browse the repository at this point in the history
fix: a couple quick fixes
  • Loading branch information
joseph-sentry authored Dec 19, 2024
2 parents d9346a6 + b29e701 commit a1636b3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn parse_junit_xml(file_bytes: &[u8]) -> PyResult<ParsingInfo> {
Ok(thing)
}

fn get_position_info(input: &[u8], byte_offset: usize) -> (usize, usize) {
pub fn get_position_info(input: &[u8], byte_offset: usize) -> (usize, usize) {
let mut line = 1;
let mut last_newline = 0;

Expand All @@ -119,6 +119,7 @@ fn use_reader(reader: &mut Reader<&[u8]>) -> PyResult<ParsingInfo> {
let mut saved_testrun: Option<Testrun> = None;

let mut in_failure: bool = false;
let mut in_error: bool = false;

let mut framework: Option<Framework> = None;

Expand Down Expand Up @@ -168,6 +169,11 @@ fn use_reader(reader: &mut Reader<&[u8]>) -> PyResult<ParsingInfo> {
.as_mut()
.ok_or_else(|| ParserError::new_err("Error accessing saved testrun"))?;
testrun.outcome = Outcome::Error;

testrun.failure_message = get_attribute(&e, "message")?
.map(|failure_message| unescape_str(&failure_message).into());

in_error = true;
}
b"failure" => {
let testrun = saved_testrun
Expand Down Expand Up @@ -200,6 +206,7 @@ fn use_reader(reader: &mut Reader<&[u8]>) -> PyResult<ParsingInfo> {
testruns.push(testrun);
}
b"failure" => in_failure = false,
b"error" => in_error = false,
b"testsuite" => {
testsuite_times.pop();
testsuite_names.pop();
Expand Down Expand Up @@ -231,10 +238,25 @@ fn use_reader(reader: &mut Reader<&[u8]>) -> PyResult<ParsingInfo> {
testrun.failure_message = get_attribute(&e, "message")?
.map(|failure_message| unescape_str(&failure_message).into());
}
b"skipped" => {
let testrun = saved_testrun
.as_mut()
.ok_or_else(|| ParserError::new_err("Error accessing saved testrun"))?;
testrun.outcome = Outcome::Skip;
}
b"error" => {
let testrun = saved_testrun
.as_mut()
.ok_or_else(|| ParserError::new_err("Error accessing saved testrun"))?;
testrun.outcome = Outcome::Error;

testrun.failure_message = get_attribute(&e, "message")?
.map(|failure_message| unescape_str(&failure_message).into());
}
_ => {}
},
Event::Text(mut xml_failure_message) => {
if in_failure {
if in_failure || in_error {
let testrun = saved_testrun
.as_mut()
.ok_or_else(|| ParserError::new_err("Error accessing saved testrun"))?;
Expand Down
15 changes: 15 additions & 0 deletions tests/skip-error.junit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite name="pytest" errors="1" failures="0" skipped="1" tests="2" time="0.1"
timestamp="2024-01-01T12:00:00.000000">
<testcase classname="tests.test_math.TestMath" name="test_subtract" time="0.1">
<error message="hello world"> hello world </error>
</testcase>
<testcase classname="tests.test_math.TestMath" name="test_multiply" time="0.1">
<error />
</testcase>
<testcase classname="tests.test_math.TestMath" name="test_add" time="0.1">
<skipped />
</testcase>
</testsuite>
</testsuites>
38 changes: 38 additions & 0 deletions tests/test_junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,44 @@ def test_junit(self, filename, expected, check):
[],
),
),
(
"./tests/skip-error.junit.xml",
ParsingInfo(
Framework.Pytest,
[
Testrun(
name="test_subtract",
classname="tests.test_math.TestMath",
duration=0.1,
outcome=Outcome.Error,
testsuite="pytest",
failure_message="hello world",
filename=None,
computed_name="tests.test_math.TestMath::test_subtract",
),
Testrun(
name="test_multiply",
classname="tests.test_math.TestMath",
duration=0.1,
outcome=Outcome.Error,
testsuite="pytest",
failure_message=None,
filename=None,
computed_name="tests.test_math.TestMath::test_multiply",
),
Testrun(
name="test_add",
classname="tests.test_math.TestMath",
duration=0.1,
outcome=Outcome.Skip,
testsuite="pytest",
failure_message=None,
filename=None,
computed_name="tests.test_math.TestMath::test_add",
)
],
),
),
],
)
def test_junit(self, filename, expected):
Expand Down

0 comments on commit a1636b3

Please sign in to comment.