Skip to content

Commit cd9d060

Browse files
Updated metadata.py
1 parent 292b9da commit cd9d060

File tree

1 file changed

+49
-25
lines changed

1 file changed

+49
-25
lines changed

scripts/tests/py/metadata.py

+49-25
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,33 @@ class Metadata:
3737
PICS: Optional[str] = None
3838
tests: Optional[str] = None
3939

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
4067

4168
class MetadataReader:
4269
"""
@@ -56,14 +83,13 @@ def __init__(self, env_yaml_file_path: str):
5683
5784
Parameters:
5885
59-
env_yaml_file_path: str
86+
env_yaml_file_path:
6087
Path to the environment file that contains the YAML configuration.
6188
"""
6289
with open(env_yaml_file_path) as stream:
6390
self.env=yaml.safe_load(stream)
6491

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:
6793
"""
6894
Resolves the argument defined in the test script to environment values.
6995
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:
7399
74100
Parameter:
75101
76-
metadata_dict: Dict[str, str]
102+
metadata_dict:
77103
Dictionary where each key represent a particular argument and its value represent
78104
the value for that argument defined in the test script.
79105
"""
@@ -111,8 +137,7 @@ def __resolve_env_vals__(self, metadata_dict: Dict[str, str]) -> None:
111137
run_arg_val = True
112138

113139
metadata_dict[run_arg] = run_arg_val
114-
115-
140+
116141

117142
def __read_args__(self,run_args_lines: List[str],metadata_dict: Dict[str, str]) -> None:
118143
"""
@@ -121,22 +146,26 @@ def __read_args__(self,run_args_lines: List[str],metadata_dict: Dict[str, str])
121146
122147
Parameters:
123148
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
126151
127-
metadata_dict: Dict[str, str]
152+
metadata_dict:
128153
Dictionary where the extracted arguments will be stored.
129154
This represents the side effect of this function.
130-
131-
Return:
132-
None
133-
134155
"""
135156
for run_line in run_args_lines:
136157
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+
'''
137167
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
140169

141170

142171
def parse_script(self, py_script_path: str) -> List[Metadata]:
@@ -147,7 +176,7 @@ def parse_script(self, py_script_path: str) -> List[Metadata]:
147176
148177
Parameter:
149178
150-
py_script_path: str
179+
py_script_path:
151180
path to the python test script
152181
153182
Return:
@@ -179,23 +208,18 @@ def parse_script(self, py_script_path: str) -> List[Metadata]:
179208
runs_arg_lines[args_match.group(1)].append(args_match.group(2))
180209

181210
for run in runs_arg_lines:
182-
metadata = Metadata()
183-
metadata_dict = vars(metadata)
211+
metadata_dict = {}
184212
self.__read_args__(runs_arg_lines[run], metadata_dict)
185213
self.__resolve_env_vals__(metadata_dict)
186214

187215
# store the run value and script location in the
188216
# metadata object
189217
metadata_dict['py_script_path'] = str(py_script_path)
190218
metadata_dict['run'] = str(run)
219+
220+
metadata = Metadata()
191221

222+
metadata.copy_from_dict(metadata_dict)
192223
runs_metadata.append(metadata)
193224

194225
return runs_metadata
195-
196-
197-
198-
199-
200-
201-

0 commit comments

Comments
 (0)