@@ -3,7 +3,6 @@ use pyo3::prelude::*;
33use quick_xml:: events:: attributes:: Attributes ;
44use quick_xml:: events:: Event ;
55use quick_xml:: reader:: Reader ;
6- use std:: ascii;
76use std:: collections:: HashMap ;
87
98use crate :: helpers:: ParserError ;
@@ -12,13 +11,11 @@ use crate::testrun::{Outcome, Testrun};
1211// from https://gist.github.com/scott-codecov/311c174ecc7de87f7d7c50371c6ef927#file-cobertura-rs-L18-L31
1312fn attributes_map ( attributes : Attributes ) -> Result < HashMap < String , String > , pyo3:: PyErr > {
1413 let mut attr_map = HashMap :: new ( ) ;
15- for attribute in attributes {
16- if let Ok ( attr) = attribute {
17- let bytes = attr. value . into_owned ( ) ;
18- let value = String :: from_utf8 ( bytes) ?;
19- let key = String :: from_utf8 ( attr. key . into_inner ( ) . to_vec ( ) ) ?;
20- attr_map. insert ( key, value) ;
21- }
14+ for attribute in attributes. flatten ( ) {
15+ let bytes = attribute. value . into_owned ( ) ;
16+ let value = String :: from_utf8 ( bytes) ?;
17+ let key = String :: from_utf8 ( attribute. key . into_inner ( ) . to_vec ( ) ) ?;
18+ attr_map. insert ( key, value) ;
2219 }
2320 Ok ( attr_map)
2421}
@@ -109,7 +106,7 @@ pub fn parse_junit_xml(file_bytes: Vec<u8>) -> PyResult<Vec<Testrun>> {
109106
110107 curr_testsuite = attr_hm?
111108 . get ( "name" )
112- . ok_or ( ParserError :: new_err ( format ! ( "Error getting name" , ) ) ) ?
109+ . ok_or ( ParserError :: new_err ( "Error getting name" . to_string ( ) ) ) ?
113110 . to_string ( ) ;
114111 }
115112 _ => { }
@@ -125,15 +122,14 @@ pub fn parse_junit_xml(file_bytes: Vec<u8>) -> PyResult<Vec<Testrun>> {
125122 b"failure" => in_failure = false ,
126123 _ => ( ) ,
127124 } ,
128- Ok ( Event :: Empty ( e) ) => match e . name ( ) . as_ref ( ) {
129- b"testcase" => {
125+ Ok ( Event :: Empty ( e) ) => {
126+ if e . name ( ) . as_ref ( ) == b"testcase" {
130127 let attr_hm = attributes_map ( e. attributes ( ) ) ;
131128 list_of_test_runs. push ( populate ( & attr_hm?, curr_testsuite. clone ( ) ) ?) ;
132129 }
133- _ => ( ) ,
134- } ,
130+ }
135131 Ok ( Event :: Text ( x) ) => {
136- if in_failure == true {
132+ if in_failure {
137133 let mut testrun = saved_testrun
138134 . ok_or ( ParserError :: new_err ( "Error accessing saved testrun" ) ) ?;
139135
0 commit comments