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

feat: make duration_seconds optional #46

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions src/junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ fn populate(
.name
.ok_or_else(|| ParserError::new_err("No name found"))?;

let duration = match rel_attrs.time {
None => testsuite_time
.ok_or_else(|| ParserError::new_err("No time/duration found"))?
.parse()?,
Some(time_str) => time_str.parse()?,
let duration: Option<f64> = match rel_attrs.time {
Some(time_str) => Some(time_str.parse()?),
None => match testsuite_time {
Some(time_str) => Some(time_str.parse()?),
None => None,
},
};

Ok(Testrun {
Expand Down
20 changes: 10 additions & 10 deletions src/testrun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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 All @@ -101,7 +101,7 @@ impl Testrun {
Testrun {
name: "".into(),
classname: "".into(),
duration: 0.0,
duration: None,
outcome: Outcome::Pass,
testsuite: "".into(),
failure_message: None,
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Testrun {
fn new(
name: String,
classname: String,
duration: f64,
duration: Option<f64>,
outcome: Outcome,
testsuite: String,
failure_message: Option<String>,
Expand All @@ -168,7 +168,7 @@ impl Testrun {

fn __repr__(&self) -> String {
format!(
"({}, {}, {}, {}, {}, {:?}, {:?})",
"({}, {}, {}, {:?}, {}, {:?}, {:?})",
self.name,
self.classname,
self.outcome,
Expand Down Expand Up @@ -279,7 +279,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 @@ -294,7 +294,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 @@ -309,7 +309,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 @@ -339,7 +339,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 @@ -354,7 +354,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 @@ -262,6 +262,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" />
Loading