Skip to content

Commit

Permalink
Merge pull request #46 from codecov/joseph/null-duration
Browse files Browse the repository at this point in the history
feat: make duration_seconds optional
  • Loading branch information
joseph-sentry authored Nov 27, 2024
2 parents 02db067 + 2443547 commit c840502
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ fn populate(
.time
.as_deref()
.or(testsuite_time)
.ok_or_else(|| ParserError::new_err("No time/duration found"))?
.parse()?;
.and_then(|t| t.parse().ok());

let mut t = Testrun {
name,
Expand Down
18 changes: 9 additions & 9 deletions src/testrun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct Testrun {
#[pyo3(get, set)]
pub classname: String,
#[pyo3(get, set)]
pub duration: f64,
pub duration: Option<f64>,
#[pyo3(get, set)]
pub outcome: Outcome,
#[pyo3(get, set)]
Expand Down Expand Up @@ -139,7 +139,7 @@ impl Testrun {
fn new(
name: String,
classname: String,
duration: f64,
duration: Option<f64>,
outcome: Outcome,
testsuite: String,
failure_message: Option<String>,
Expand All @@ -162,7 +162,7 @@ impl Testrun {

fn __repr__(&self) -> String {
format!(
"({}, {}, {}, {}, {}, {:?}, {:?}, {:?})",
"({}, {}, {}, {:?}, {}, {:?}, {:?}, {:?})",
self.name,
self.classname,
self.outcome,
Expand Down Expand Up @@ -276,7 +276,7 @@ mod tests {
let t = Testrun {
classname: "".to_string(),
name: "".to_string(),
duration: 0.0,
duration: None,
outcome: Outcome::Pass,
testsuite: "pytest".to_string(),
failure_message: None,
Expand All @@ -292,7 +292,7 @@ mod tests {
let t = Testrun {
classname: "".to_string(),
name: "".to_string(),
duration: 0.0,
duration: None,
outcome: Outcome::Pass,
testsuite: "".to_string(),
failure_message: None,
Expand All @@ -308,7 +308,7 @@ mod tests {
let t = Testrun {
classname: ".py".to_string(),
name: "".to_string(),
duration: 0.0,
duration: None,
outcome: Outcome::Pass,
testsuite: "".to_string(),
failure_message: None,
Expand All @@ -324,7 +324,7 @@ mod tests {
let t = Testrun {
classname: "".to_string(),
name: ".py".to_string(),
duration: 0.0,
duration: None,
outcome: Outcome::Pass,
testsuite: "".to_string(),
failure_message: None,
Expand All @@ -340,7 +340,7 @@ mod tests {
let t = Testrun {
classname: "".to_string(),
name: "".to_string(),
duration: 0.0,
duration: None,
outcome: Outcome::Pass,
testsuite: "".to_string(),
failure_message: Some(".py".to_string()),
Expand All @@ -356,7 +356,7 @@ mod tests {
let t = Testrun {
classname: "".to_string(),
name: "".to_string(),
duration: 0.0,
duration: None,
outcome: Outcome::Pass,
testsuite: "".to_string(),
failure_message: Some(".py".to_string()),
Expand Down
22 changes: 22 additions & 0 deletions tests/no-time.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="/file1.xml" tests="2"
assertions="2" errors="0" failures="0" skipped="0">
<testsuite name="Thing"
file="/file1.php"
tests="2" assertions="2" errors="0" failures="0" skipped="0">
<testcase
name="test1"
file="/file1.php"
line="1"
classname="class.className" assertions="1"
/>
<testcase
name="test2"
file="/file1.php"
line="2"
assertions="1"
/>
</testsuite>
</testsuite>
</testsuites>
7 changes: 7 additions & 0 deletions tests/test_junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ def test_junit(self, filename, expected, check):
],
),
),
(
"./tests/testsuites.xml",
ParsingInfo(
None,
[],
),
),
],
)
def test_junit(self, filename, expected):
Expand Down
1 change: 1 addition & 0 deletions tests/testsuites.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<testsuites name="empty_testsuites" tests="0" failures="0" />

0 comments on commit c840502

Please sign in to comment.