The Gaudi Framework
master (57817a18)
Toggle main menu visibility
Loading...
Searching...
No Matches
FixtureResult.py
Go to the documentation of this file.
1
11
import
datetime
12
import
subprocess
13
14
from
GaudiTesting.utils
import
CodeWrapper
15
16
17
class
ProcessTimeoutError
(Exception):
18
def
__init__
(self, message, stack_trace):
19
super().
__init__
(message)
20
self.
stack_trace
= stack_trace
21
22
23
class
ExceededStreamError
(Exception):
24
def
__init__
(self, message, exceeded_stream):
25
super().
__init__
(message)
26
self.
exceeded_stream
= exceeded_stream
27
28
29
class
FixtureResult
:
30
"""
31
A class to encapsulate the results of a subprocess execution in a test fixture.
32
"""
33
34
def
__init__
(
35
self,
36
completed_process: subprocess.CompletedProcess,
37
start_time: datetime,
38
end_time: datetime,
39
run_exception: ProcessTimeoutError | ExceededStreamError |
None
,
40
command: list[str],
41
expanded_command: list[str],
42
env: dict,
43
cwd: str,
44
):
45
self.
completed_process
= completed_process
46
self.
start_time
= start_time
47
self.
end_time
= end_time
48
self.
run_exception
= run_exception
49
self.
command
= command
50
self.
expanded_command
= expanded_command
51
self.
runtime_environment
= env
52
self.
cwd
= cwd
53
54
def
elapsed_time
(self):
55
return
self.
end_time
- self.
start_time
56
57
@staticmethod
58
def
format_value
(value):
59
"""
60
Format a given value to a string representation.
61
"""
62
if
isinstance(value, list):
63
return
repr(value)
64
elif
isinstance(value, dict):
65
return
"\n"
.join(f
"{k}={v}"
for
k, v
in
value.items())
66
return
str(value
or
""
)
67
68
def
to_dict
(self) -> dict:
69
"""
70
Convert the attributes of the FixtureResult into a dictionary.
71
"""
72
properties = {attr: getattr(self, attr)
for
attr
in
vars(self)}
73
properties.update(
74
{
75
"stdout"
:
CodeWrapper
(
76
self.
completed_process
.stdout.decode(
77
"utf-8"
, errors=
"backslashreplace"
78
),
79
"console"
,
80
)
81
if
self.
completed_process
.stdout
82
else
None
,
83
"stderr"
:
CodeWrapper
(
84
self.
completed_process
.stderr.decode(
85
"utf-8"
, errors=
"backslashreplace"
86
),
87
"console"
,
88
)
89
if
self.
completed_process
.stderr
90
else
None
,
91
"return_code"
: self.
completed_process
.returncode
92
if
self.
completed_process
.returncode
93
else
None
,
94
"elapsed_time"
: self.
elapsed_time
(),
95
"stack_trace"
: self.
run_exception
.stack_trace
96
if
hasattr(self.
run_exception
,
"stack_trace"
)
97
else
None
,
98
"stream_exceeded"
: self.
run_exception
.exceeded_stream
99
if
hasattr(self.
run_exception
,
"exceeded_stream"
)
100
else
None
,
101
}
102
)
103
formatted_properties = {
104
key: self.
format_value
(value)
for
key, value
in
properties.items()
105
}
106
return
formatted_properties
GaudiTesting.FixtureResult.ExceededStreamError
Definition
FixtureResult.py:23
GaudiTesting.FixtureResult.ExceededStreamError.exceeded_stream
exceeded_stream
Definition
FixtureResult.py:26
GaudiTesting.FixtureResult.ExceededStreamError.__init__
__init__(self, message, exceeded_stream)
Definition
FixtureResult.py:24
GaudiTesting.FixtureResult.FixtureResult
Definition
FixtureResult.py:29
GaudiTesting.FixtureResult.FixtureResult.command
command
Definition
FixtureResult.py:49
GaudiTesting.FixtureResult.FixtureResult.start_time
start_time
Definition
FixtureResult.py:46
GaudiTesting.FixtureResult.FixtureResult.runtime_environment
runtime_environment
Definition
FixtureResult.py:51
GaudiTesting.FixtureResult.FixtureResult.cwd
cwd
Definition
FixtureResult.py:52
GaudiTesting.FixtureResult.FixtureResult.to_dict
dict to_dict(self)
Definition
FixtureResult.py:68
GaudiTesting.FixtureResult.FixtureResult.run_exception
run_exception
Definition
FixtureResult.py:48
GaudiTesting.FixtureResult.FixtureResult.completed_process
completed_process
Definition
FixtureResult.py:45
GaudiTesting.FixtureResult.FixtureResult.expanded_command
expanded_command
Definition
FixtureResult.py:50
GaudiTesting.FixtureResult.FixtureResult.format_value
format_value(value)
Definition
FixtureResult.py:58
GaudiTesting.FixtureResult.FixtureResult.__init__
__init__(self, subprocess.CompletedProcess completed_process, datetime start_time, datetime end_time, ProcessTimeoutError|ExceededStreamError|None run_exception, list[str] command, list[str] expanded_command, dict env, str cwd)
Definition
FixtureResult.py:44
GaudiTesting.FixtureResult.FixtureResult.elapsed_time
elapsed_time(self)
Definition
FixtureResult.py:54
GaudiTesting.FixtureResult.FixtureResult.end_time
end_time
Definition
FixtureResult.py:47
GaudiTesting.FixtureResult.ProcessTimeoutError
Definition
FixtureResult.py:17
GaudiTesting.FixtureResult.ProcessTimeoutError.__init__
__init__(self, message, stack_trace)
Definition
FixtureResult.py:18
GaudiTesting.FixtureResult.ProcessTimeoutError.stack_trace
stack_trace
Definition
FixtureResult.py:20
GaudiTesting.utils.CodeWrapper
Definition
utils.py:23
GaudiTesting.utils
Definition
utils.py:1
GaudiPolicy
python
GaudiTesting
FixtureResult.py
Generated on
for The Gaudi Framework by
1.17.0