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