Commit b9020598c0c63b5f64e19bb4922d8818a9efc58f
1 parent
4986f5e8
Use the optimal values for period intervals
The values are computed based on which brokers are active in current test suite. Even though the implementation is a bit complicated, explanation is very simple: The greatest value among currently used brokers is taken and then used everywhere. Each mode is independent, startDate and endDate are independent too.
Showing
2 changed files
with
49 additions
and
1 deletions
... | ... | @@ -54,6 +54,8 @@ Set Suite Variable With Default Value |
54 | 54 | Завантажуємо дані про користувачів і майданчики |
55 | 55 | Log ${broker} |
56 | 56 | Log ${role} |
57 | + # Suite variable; should be present in every test suite | |
58 | + # in `*** Variables ***` section | |
57 | 59 | Log Many @{used_roles} |
58 | 60 | |
59 | 61 | # Load brokers data |
... | ... | @@ -92,7 +94,10 @@ Set Suite Variable With Default Value |
92 | 94 | \ ... ${BROKERS['Quinta'].roles.${tmp_role}} |
93 | 95 | \ Append To List ${used_users} ${${tmp_role}} |
94 | 96 | \ Append To List ${used_brokers} ${USERS.users.${${tmp_role}}.broker} |
97 | + # Since `@{used_roles}` is already a suite variable, | |
98 | + # let's make `@{used_brokers}` alike. | |
95 | 99 | ${used_brokers}= Remove Duplicates ${used_brokers} |
100 | + Set Suite Variable ${used_brokers} | |
96 | 101 | # We need to create two lists since Robot Framework doesn't support |
97 | 102 | # dicts in `:FOR` loops. |
98 | 103 | Log Many @{used_users} |
... | ... | @@ -174,7 +179,7 @@ Get Broker Property By Username |
174 | 179 | |
175 | 180 | |
176 | 181 | Підготовка даних для створення тендера |
177 | - ${period_intervals}= Get Broker Property By Username ${tender_owner} intervals | |
182 | + ${period_intervals}= compute_intrs ${BROKERS} ${used_brokers} | |
178 | 183 | ${tender_data}= prepare_test_tender_data ${period_intervals} ${mode} |
179 | 184 | ${TENDER}= Create Dictionary |
180 | 185 | Set Global Variable ${TENDER} | ... | ... |
... | ... | @@ -160,6 +160,49 @@ def load_data_from(file_name, mode=None): |
160 | 160 | return file_data |
161 | 161 | |
162 | 162 | |
163 | +def compute_intrs(brokers_data, used_brokers): | |
164 | + """Compute optimal values for period intervals. | |
165 | + | |
166 | + Notice: This function is maximally effective if ``brokers_data`` | |
167 | + does not contain ``Default`` entry. | |
168 | + Using `load_data_from` with ``mode='brokers'`` is recommended. | |
169 | + """ | |
170 | + num_types = (int, long, float) | |
171 | + | |
172 | + def recur(l, r): | |
173 | + l, r = deepcopy(l), deepcopy(r) | |
174 | + if isinstance(l, list) and isinstance(r, list) and len(l) == len(r): | |
175 | + lst = [] | |
176 | + for ll, rr in zip(l, r): | |
177 | + lst.append(recur(ll, rr)) | |
178 | + return lst | |
179 | + elif isinstance(l, num_types) and isinstance(r, num_types): | |
180 | + if l == r: | |
181 | + return l | |
182 | + if l > r: | |
183 | + return l | |
184 | + if l < r: | |
185 | + return r | |
186 | + elif isinstance(l, dict) and isinstance(r, dict): | |
187 | + for k, v in r.iteritems(): | |
188 | + if k not in l.keys(): | |
189 | + l[k] = v | |
190 | + else: | |
191 | + l[k] = recur(l[k], v) | |
192 | + return l | |
193 | + else: | |
194 | + raise TypeError("Couldn't recur({0}, {1})".format( | |
195 | + str(type(l)), str(type(r)))) | |
196 | + | |
197 | + intrs = [] | |
198 | + for i in used_brokers: | |
199 | + intrs.append(brokers_data[i]['intervals']) | |
200 | + result = intrs.pop(0) | |
201 | + for i in intrs: | |
202 | + result = recur(result, i) | |
203 | + return result | |
204 | + | |
205 | + | |
163 | 206 | def prepare_test_tender_data(procedure_intervals, mode): |
164 | 207 | # Get actual intervals by mode name |
165 | 208 | if mode in procedure_intervals: | ... | ... |
Please
register
or
login
to post a comment