@@ -37,6 +37,33 @@ class Metadata:
37
37
PICS : Optional [str ] = None
38
38
tests : Optional [str ] = None
39
39
40
+ def copy_from_dict (self ,attr_dict : Dict [str , str ]) -> None :
41
+ """
42
+ Sets the value of the attributes from a dictionary.
43
+
44
+ Attributes:
45
+
46
+ attr_dict:
47
+ Dictionary that stores attributes value that should
48
+ be transferred to this class.
49
+ """
50
+
51
+ if "app" in attr_dict :
52
+ self .app = attr_dict ["app" ]
53
+
54
+ if "run" in attr_dict :
55
+ self .run = attr_dict ["run" ]
56
+
57
+ if "discriminator" in attr_dict :
58
+ self .discriminator = attr_dict ["discriminator" ]
59
+
60
+ if "passcode" in attr_dict :
61
+ self .passcode = attr_dict ["passcode" ]
62
+
63
+ if "py_script_path" in attr_dict :
64
+ self .py_script_path = attr_dict ["py_script_path" ]
65
+
66
+ # TODO - set other attributes as well
40
67
41
68
class MetadataReader :
42
69
"""
@@ -56,14 +83,13 @@ def __init__(self, env_yaml_file_path: str):
56
83
57
84
Parameters:
58
85
59
- env_yaml_file_path: str
86
+ env_yaml_file_path:
60
87
Path to the environment file that contains the YAML configuration.
61
88
"""
62
89
with open (env_yaml_file_path ) as stream :
63
90
self .env = yaml .safe_load (stream )
64
91
65
-
66
- def __resolve_env_vals__ (self , metadata_dict : Dict [str , str ]) -> None :
92
+ def __resolve_env_vals__ (self , metadata_dict : Dict [str , Union [str ,bool ]]) -> None :
67
93
"""
68
94
Resolves the argument defined in the test script to environment values.
69
95
For example, if a test script defines "all_clusters" as the value for app
@@ -73,7 +99,7 @@ def __resolve_env_vals__(self, metadata_dict: Dict[str, str]) -> None:
73
99
74
100
Parameter:
75
101
76
- metadata_dict: Dict[str, str]
102
+ metadata_dict:
77
103
Dictionary where each key represent a particular argument and its value represent
78
104
the value for that argument defined in the test script.
79
105
"""
@@ -111,8 +137,7 @@ def __resolve_env_vals__(self, metadata_dict: Dict[str, str]) -> None:
111
137
run_arg_val = True
112
138
113
139
metadata_dict [run_arg ] = run_arg_val
114
-
115
-
140
+
116
141
117
142
def __read_args__ (self ,run_args_lines : List [str ],metadata_dict : Dict [str , str ]) -> None :
118
143
"""
@@ -121,22 +146,26 @@ def __read_args__(self,run_args_lines: List[str],metadata_dict: Dict[str, str])
121
146
122
147
Parameters:
123
148
124
- run_args_lines: List[str]
125
- Raw lines in argument header
149
+ run_args_lines:
150
+ Line in test script header that contains run argumment definition
126
151
127
- metadata_dict: Dict[str, str]
152
+ metadata_dict:
128
153
Dictionary where the extracted arguments will be stored.
129
154
This represents the side effect of this function.
130
-
131
- Return:
132
- None
133
-
134
155
"""
135
156
for run_line in run_args_lines :
136
157
for run_arg_word in run_line .strip ().split ():
158
+ '''
159
+ We expect the run arg to be defined in one of the
160
+ following two formats:
161
+ 1. run_arg
162
+ 2. run_arg/run_arg_val
163
+
164
+ Examples: "discriminator" and "app/all_clusters"
165
+
166
+ '''
137
167
run_arg = run_arg_word .split ('/' ,1 )[0 ]
138
- if run_arg in metadata_dict :
139
- metadata_dict [run_arg ] = run_arg_word
168
+ metadata_dict [run_arg ] = run_arg_word
140
169
141
170
142
171
def parse_script (self , py_script_path : str ) -> List [Metadata ]:
@@ -147,7 +176,7 @@ def parse_script(self, py_script_path: str) -> List[Metadata]:
147
176
148
177
Parameter:
149
178
150
- py_script_path: str
179
+ py_script_path:
151
180
path to the python test script
152
181
153
182
Return:
@@ -179,23 +208,18 @@ def parse_script(self, py_script_path: str) -> List[Metadata]:
179
208
runs_arg_lines [args_match .group (1 )].append (args_match .group (2 ))
180
209
181
210
for run in runs_arg_lines :
182
- metadata = Metadata ()
183
- metadata_dict = vars (metadata )
211
+ metadata_dict = {}
184
212
self .__read_args__ (runs_arg_lines [run ], metadata_dict )
185
213
self .__resolve_env_vals__ (metadata_dict )
186
214
187
215
# store the run value and script location in the
188
216
# metadata object
189
217
metadata_dict ['py_script_path' ] = str (py_script_path )
190
218
metadata_dict ['run' ] = str (run )
219
+
220
+ metadata = Metadata ()
191
221
222
+ metadata .copy_from_dict (metadata_dict )
192
223
runs_metadata .append (metadata )
193
224
194
225
return runs_metadata
195
-
196
-
197
-
198
-
199
-
200
-
201
-
0 commit comments