Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79722168
testresults.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Aug 27, 22:21
Size
2 KB
Mime Type
text/x-python
Expires
Thu, Aug 29, 22:21 (2 d)
Engine
blob
Format
Raw Data
Handle
20213826
Attached To
rAKA akantu
testresults.py
View Options
import
xml.etree.ElementTree
as
xml_etree
from
collections
import
namedtuple
from
.results
import
Results
from
.
import
export
class
TestResults
:
STATUS
=
{
'passed'
:
Results
.
PASS
,
'failed'
:
Results
.
FAIL
}
Test
=
namedtuple
(
'Test'
,
'name path status duration reason'
.
split
())
def
__init__
(
self
,
filename
):
self
.
_file
=
open
(
filename
,
"r"
)
self
.
_etree
=
xml_etree
.
parse
(
self
.
_file
)
self
.
_root
=
self
.
_etree
.
getroot
()
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
self
.
_file
.
close
()
def
__enter__
(
self
):
return
self
@export
class
CTestResults
(
TestResults
):
def
__init__
(
self
,
filename
):
super
()
.
__init__
(
self
,
filename
)
self
.
test_format
=
'CTest'
def
__iter__
(
self
):
self
.
_tests
=
iter
(
self
.
_root
.
findall
(
'./Testing/Test'
))
return
self
def
__next__
(
self
):
element
=
next
(
self
.
_tests
)
name
=
element
.
find
(
'Name'
)
.
text
path
=
element
.
find
(
'FullName'
)
.
text
status
=
CTestResults
.
STATUS
[
element
.
attrib
[
'Status'
]]
duration
=
float
(
element
.
find
(
"./Results/NamedMeasurement[@name='Execution Time']/Value"
)
.
text
)
reason
=
None
if
status
==
Results
.
FAIL
:
reason
=
element
.
find
(
"./Results/NamedMeasurement[@name='Exit Code']/Value"
)
.
text
if
reason
==
"Timeout"
:
status
=
Results
.
BROKEN
else
:
reason
=
"{0} with exit code [{1}]
\n
STDOUT:
\n
{2}"
.
format
(
reason
,
element
.
find
(
"./Results/NamedMeasurement[@name='Exit Value']/Value"
)
.
text
,
# noqa: E501
'
\n
'
.
join
((
el
.
text
for
el
in
element
.
findall
(
"./Results/Measurement/Value"
))),
# noqa: E501
)
return
self
.
Test
(
name
,
path
,
status
,
duration
,
reason
)
@export
class
JUnitTestResults
(
TestResults
):
def
__init__
(
self
,
filename
):
super
()
.
__init__
(
self
,
filename
)
self
.
test_format
=
'JUnit'
def
__iter__
(
self
):
self
.
_tests
=
iter
(
self
.
_root
.
findall
(
'testcase'
))
return
self
def
__next__
(
self
):
element
=
next
(
self
.
_tests
)
name
=
element
.
attrib
[
'name'
]
path
=
element
.
attrib
[
'file'
]
\
+
':{}'
.
format
(
element
.
attrib
[
'line'
])
duration
=
element
.
attrib
[
'time'
]
failure
=
element
.
find
(
'failure'
)
error
=
element
.
find
(
'error'
)
if
failure
is
not
None
and
error
is
not
None
:
status
=
Results
.
PASS
elif
error
:
status
=
Results
.
BROKEN
reason
=
error
.
attrib
[
'message'
]
+
'
\n
'
+
error
.
attrib
[
'type'
]
elif
failure
:
status
=
Results
.
FAIL
reason
=
failure
.
attrib
[
'message'
]
+
'
\n
'
\
+
failure
.
attrib
[
'type'
]
return
self
.
Test
(
name
,
path
,
status
,
duration
,
reason
)
Event Timeline
Log In to Comment