Best Python code snippet using molotov_python
utils_accumulation.py
Source:utils_accumulation.py
1# ##### BEGIN GPL LICENSE BLOCK #####2#3# This program is free software; you can redistribute it and/or4# modify it under the terms of the GNU General Public License5# as published by the Free Software Foundation; either version 26# of the License, or (at your option) any later version.7#8# This program is distributed in the hope that it will be useful,9# but WITHOUT ANY WARRANTY; without even the implied warranty of10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11# GNU General Public License for more details.12#13# You should have received a copy of the GNU General Public License14# along with this program; if not, write to the Free Software Foundation,15# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.16#17# ##### END GPL LICENSE BLOCK #####18import bpy19import math20import bisect21from .utils_python import sequence_startswith, sequence_endswith22from .utils_text import indent, longest_common_substring23#============================================================================#24"""25TODO: "active" query (for consistency)26"""27class Aggregator:28 _count = 029 _same = True30 _prev = None31 32 _min = None33 _max = None34 35 _sum = None36 _sum_log = None37 _sum_rec = None38 _product = None39 40 _Ak = None41 _Qk = None42 43 _sorted = None44 45 _freq_map = None46 _freq_max = None47 _modes = None48 49 _union = None50 _intersection = None51 _difference = None52 53 _subseq = None54 _subseq_starts = None55 _subseq_ends = None56 57 # sum can be calculated from average, and product (for values > 0)58 # can be calculated from sum_log, but it won't be precise for ints59 60 type = property(lambda self: self._type)61 62 count = property(lambda self: self._count)63 same = property(lambda self: self._same)64 65 min = property(lambda self: self._min)66 max = property(lambda self: self._max)67 @property68 def range(self):69 if (self._max is None) or (self._min is None): return None70 return self._max - self._min71 @property72 def center(self):73 if (self._max is None) or (self._min is None): return None74 return (self._max + self._min) * 0.575 76 sum = property(lambda self: self._sum)77 sum_log = property(lambda self: self._sum_log)78 sum_rec = property(lambda self: self._sum_rec)79 product = property(lambda self: self._product)80 81 @property82 def mean(self):83 return self._Ak84 @property85 def geometric_mean(self):86 if (self._sum_log is None) or (self._count is None): return None87 return math.exp(self._sum_log / self._count)88 @property89 def harmonic_mean(self):90 if (self._sum_rec is None): return None91 return 1.0 / self._sum_rec92 @property93 def variance(self):94 if (self._Qk is None) or (self._count is None): return None95 if self._count < 2: return 0.096 return self._Qk / (self._count - 1)97 @property98 def stddev(self):99 if (self._Qk is None) or (self._count is None): return None100 if self._count < 2: return 0.0101 return math.sqrt(self._Qk / (self._count - 1))102 103 sorted = property(lambda self: self._sorted)104 @property105 def median(self):106 if not self._sorted: return None107 n = len(self._sorted)108 if (n % 2) == 1: return self._sorted[n // 2]109 i = n // 2110 return (self._sorted[i] + self._sorted[i - 1]) * 0.5111 112 freq_map = property(lambda self: self._freq_map)113 freq_max = property(lambda self: self._freq_max)114 modes = property(lambda self: self._modes)115 mode = property(lambda self: self._modes[0] if self._modes else None)116 117 union = property(lambda self: self._union)118 intersection = property(lambda self: self._intersection)119 difference = property(lambda self: self._difference)120 121 subseq = property(lambda self: self._subseq)122 subseq_starts = property(lambda self: self._subseq_starts)123 subseq_ends = property(lambda self: self._subseq_ends)124 125 def get(self, query, fallback):126 value = getattr(self, query)127 if value is None: return fallback128 return ((value > 0.5) if isinstance(fallback, bool) else value)129 130 _numerical_queries = frozenset([131 'count', 'same', 'min', 'max', 'range', 'center',132 'sum', 'sum_log', 'sum_rec', 'product',133 'mean', 'geometric_mean', 'harmonic_mean', 'variance', 'stddev',134 'sorted', 'median', 'freq_map', 'freq_max', 'modes',135 ])136 _enum_queries = frozenset([137 'count', 'same',138 'freq_map', 'freq_max', 'modes',139 'union', 'intersection', 'difference',140 ])141 _sequence_queries = frozenset([142 'count', 'same',143 'sorted', 'median', 'freq_map', 'freq_max', 'modes',144 'subseq', 'subseq_starts', 'subseq_ends',145 ])146 _object_queries = frozenset([147 'count', 'same',148 'freq_map', 'freq_max', 'modes',149 ])150 _all_queries = {'NUMBER':_numerical_queries, 'ENUM':_enum_queries,151 'SEQUENCE':_sequence_queries, 'OBJECT':_object_queries}152 153 _compiled = {}154 155 def __init__(self, type, queries=None, convert=None, epsilon=1e-6):156 self._type = type157 158 self._startswith = sequence_startswith159 self._endswith = sequence_endswith160 if type == 'STRING':161 self._startswith = str.startswith162 self._endswith = str.endswith163 type = 'SEQUENCE'164 elif type == 'BOOL':165 if convert is None: convert = int166 type = 'NUMBER'167 168 if queries is None:169 queries = self._all_queries[type]170 elif isinstance(queries, str):171 queries = queries.split(" ")172 173 if (type != 'NUMBER') or ((epsilon is not None) and (epsilon <= 0)): epsilon = None174 175 compiled_key0 = (type, frozenset(queries), convert, epsilon)176 compiled = Aggregator._compiled.get(compiled_key0)177 178 if not compiled:179 queries = set(queries) # make sure it's a copy180 181 # make sure requirements are included182 if 'same' in queries: queries.update(('min', 'max') if epsilon else ('prev',))183 if ('range' in queries) or ('center' in queries): queries.update(('min', 'max'))184 if 'mean' in queries: queries.add('Ak')185 if 'geometric_mean' in queries: queries.update(('sum_log', 'count'))186 if 'harmonic_mean' in queries: queries.add('sum_rec')187 if ('variance' in queries) or ('stddev' in queries): queries.update(('Qk', 'count'))188 if 'Qk' in queries: queries.add('Ak')189 if 'Ak' in queries: queries.add('count')190 if 'median' in queries: queries.add('sorted')191 if 'mode' in queries: queries.add('modes')192 if 'modes' in queries: queries.add('freq_max')193 if 'freq_max' in queries: queries.add('freq_map')194 if queries.intersection(('subseq', 'subseq_starts', 'subseq_ends')):195 queries.update(('subseq', 'subseq_starts', 'subseq_ends'))196 197 compiled_key = (type, frozenset(queries), convert, epsilon)198 compiled = Aggregator._compiled.get(compiled_key)199 200 if not compiled:201 compiled = self._compile(type, queries, convert, epsilon)202 Aggregator._compiled[compiled_key] = compiled203 204 Aggregator._compiled[compiled_key0] = compiled205 206 self.queries = compiled_key0[1] # the original queries, without dependencies207 208 # Assign bound methods209 self.reset = compiled[0].__get__(self, self.__class__)210 self._init = compiled[1].__get__(self, self.__class__)211 self._add = compiled[2].__get__(self, self.__class__)212 213 self.reset()214 215 def _compile(self, type, queries, convert, epsilon):216 reset_lines = []217 init_lines = []218 add_lines = []219 220 localvars = dict(log=math.log, insort_left=bisect.insort_left,221 startswith=self._startswith, endswith=self._endswith, convert=convert)222 223 if 'count' in queries:224 reset_lines.append("self._count = 0")225 init_lines.append("self._count = 1")226 add_lines.append("self._count += 1")227 228 if 'min' in queries:229 reset_lines.append("self._min = None")230 init_lines.append("self._min = value")231 add_lines.append("self._min = min(self._min, value)")232 if 'max' in queries:233 reset_lines.append("self._max = None")234 init_lines.append("self._max = value")235 add_lines.append("self._max = max(self._max, value)")236 237 if 'same' in queries:238 reset_lines.append("self._same = True")239 init_lines.append("self._same = True")240 if epsilon:241 add_lines.append("if self._same: self._same = (abs(self._max - self._min) <= %s)" % epsilon)242 else:243 add_lines.append("if self._same: self._same = (value == self._prev)")244 if 'prev' in queries:245 reset_lines.append("self._prev = None")246 init_lines.append("self._prev = value")247 add_lines.append("self._prev = value")248 249 if 'sum' in queries:250 reset_lines.append("self._sum = None")251 init_lines.append("self._sum = value")252 add_lines.append("self._sum += value")253 if 'sum_log' in queries:254 reset_lines.append("self._sum_log = None")255 init_lines.append("self._sum_log = (log(value) if value > 0.0 else 0.0)")256 add_lines.append("self._sum_log += (log(value) if value > 0.0 else 0.0)")257 if 'sum_rec' in queries:258 reset_lines.append("self._sum_rec = None")259 init_lines.append("self._sum_rec = (1.0 / value if value != 0.0 else 0.0)")260 add_lines.append("self._sum_rec += (1.0 / value if value != 0.0 else 0.0)")261 if 'product' in queries:262 reset_lines.append("self._product = None")263 init_lines.append("self._product = value")264 add_lines.append("self._product *= value")265 266 if 'Ak' in queries:267 reset_lines.append("self._Ak = None")268 init_lines.append("self._Ak = value")269 add_lines.append("delta = (value - self._Ak)")270 add_lines.append("self._Ak += delta / self._count")271 if 'Qk' in queries:272 reset_lines.append("self._Qk = None")273 init_lines.append("self._Qk = 0.0")274 add_lines.append("self._Qk += delta * (value - self._Ak)")275 276 if 'sorted' in queries:277 reset_lines.append("self._sorted = None")278 init_lines.append("self._sorted = [value]")279 add_lines.append("insort_left(self._sorted, value)")280 281 if type != 'ENUM':282 if 'freq_map' in queries:283 reset_lines.append("self._freq_map = None")284 init_lines.append("self._freq_map = {value:1}")285 add_lines.append("freq = self._freq_map.get(value, 0) + 1")286 add_lines.append("self._freq_map[value] = freq")287 if 'freq_max' in queries:288 reset_lines.append("self._freq_max = None")289 init_lines.append("self._freq_max = 0")290 add_lines.append("if freq > self._freq_max:")291 add_lines.append(" self._freq_max = freq")292 if 'modes' in queries:293 reset_lines.append("self._modes = None")294 init_lines.append("self._modes = [value]")295 add_lines.append(" self._modes = [value]")296 add_lines.append("elif freq == self._freq_max:")297 add_lines.append(" self._modes.append(value)")298 else:299 if 'freq_map' in queries:300 reset_lines.append("self._freq_map = None")301 init_lines.append("self._freq_map = {item:1 for item in value}")302 add_lines.append("for item in value:")303 add_lines.append(" freq = self._freq_map.get(item, 0) + 1")304 add_lines.append(" self._freq_map[item] = freq")305 if 'freq_max' in queries:306 reset_lines.append("self._freq_max = None")307 init_lines.append("self._freq_max = 0")308 add_lines.append(" if freq > self._freq_max:")309 add_lines.append(" self._freq_max = freq")310 if 'modes' in queries:311 reset_lines.append("self._modes = None")312 init_lines.append("self._modes = list(value)")313 add_lines.append(" self._modes = [item]")314 add_lines.append(" elif freq == self._freq_max:")315 add_lines.append(" self._modes.append(item)")316 317 if 'union' in queries:318 reset_lines.append("self._union = None")319 init_lines.append("self._union = set(value)")320 add_lines.append("self._union.update(value)")321 if 'intersection' in queries:322 reset_lines.append("self._intersection = None")323 init_lines.append("self._intersection = set(value)")324 add_lines.append("self._intersection.intersection_update(value)")325 if 'difference' in queries:326 reset_lines.append("self._difference = None")327 init_lines.append("self._difference = set(value)")328 add_lines.append("self._difference.symmetric_difference_update(value)")329 330 if 'subseq' in queries:331 reset_lines.append("self._subseq = None")332 reset_lines.append("self._subseq_starts = None")333 reset_lines.append("self._subseq_ends = None")334 init_lines.append("self._subseq = value")335 init_lines.append("self._subseq_starts = True")336 init_lines.append("self._subseq_ends = True")337 add_lines.append("self._subseq_update(value)")338 339 reset_lines.append("self.add = self._init")340 reset_lines = [indent(line, " ") for line in reset_lines]341 reset_lines.insert(0, "def reset(self):")342 reset_code = "\n".join(reset_lines)343 #print(reset_code)344 exec(reset_code, localvars, localvars)345 reset = localvars["reset"]346 347 if convert is not None: init_lines.insert(0, "value = convert(value)")348 init_lines.append("self.add = self._add")349 init_lines = [indent(line, " ") for line in init_lines]350 init_lines.insert(0, "def _init(self, value):")351 init_code = "\n".join(init_lines)352 #print(init_code)353 exec(init_code, localvars, localvars)354 _init = localvars["_init"]355 356 if convert is not None: init_lines.insert(0, "value = convert(value)")357 add_lines = [indent(line, " ") for line in add_lines]358 add_lines.insert(0, "def _add(self, value):")359 add_code = "\n".join(add_lines)360 #print(add_code)361 exec(add_code, localvars, localvars)362 _add = localvars["_add"]363 364 return reset, _init, _add365 366 def _subseq_update(self, value):367 if self._subseq_starts:368 if self._startswith(value, self._subseq):369 pass370 elif self._startswith(self._subseq, value):371 self._subseq = value372 else:373 self._subseq_starts = False374 if self._subseq_ends:375 if self._endswith(value, self._subseq):376 pass377 elif self._endswith(self._subseq, value):378 self._subseq = value379 else:380 self._subseq_ends = False381 if self._subseq and not (self._subseq_starts or self._subseq_ends):382 prev_subseq = self._subseq383 self._subseq = next(iter(longest_common_substring(self._subseq, value)), None) or value[0:0]384 # Seems like there is no other way than to check everything again385 # (e.g. Blue, Red, White -> "e" is common, but is wasn't on the end in "Red")386 #if self._subseq:387 # if self._startswith(prev_subseq, self._subseq):388 # self._subseq_starts = self._startswith(value, self._subseq)389 # if self._endswith(prev_subseq, self._subseq):390 # self._subseq_ends = self._endswith(value, self._subseq)391class VectorAggregator:392 def __init__(self, size, type, queries=None, covert=None, epsilon=1e-6):393 self._type = type394 self.axes = tuple(Aggregator(type, queries, covert, epsilon) for i in range(size))395 396 def reset(self):397 for axis in self.axes:398 axis.reset()399 400 def __len__(self):401 return len(self.axes)402 403 def add(self, value, i=None):404 if i is None:405 for axis, item in zip(self.axes, value):406 axis.add(item)407 else:408 self.axes[i].add(value)409 410 type = property(lambda self: self._type)411 412 count = property(lambda self: (self.axes[0].count if self.axes else 0)) # same for all413 same = property(lambda self: tuple(axis.same for axis in self.axes))414 415 min = property(lambda self: tuple(axis.min for axis in self.axes))416 max = property(lambda self: tuple(axis.max for axis in self.axes))417 range = property(lambda self: tuple(axis.range for axis in self.axes))418 center = property(lambda self: tuple(axis.center for axis in self.axes))419 420 sum = property(lambda self: tuple(axis.sum for axis in self.axes))421 sum_log = property(lambda self: tuple(axis.sum_log for axis in self.axes))422 sum_rec = property(lambda self: tuple(axis.sum_rec for axis in self.axes))423 product = property(lambda self: tuple(axis.product for axis in self.axes))424 425 mean = property(lambda self: tuple(axis.mean for axis in self.axes))426 geometric_mean = property(lambda self: tuple(axis.geometric_mean for axis in self.axes))427 harmonic_mean = property(lambda self: tuple(axis.harmonic_mean for axis in self.axes))428 variance = property(lambda self: tuple(axis.variance for axis in self.axes))429 stddev = property(lambda self: tuple(axis.stddev for axis in self.axes))430 431 sorted = property(lambda self: tuple(axis.sorted for axis in self.axes))432 median = property(lambda self: tuple(axis.median for axis in self.axes))433 434 freq_map = property(lambda self: tuple(axis.freq_map for axis in self.axes))435 freq_max = property(lambda self: tuple(axis.freq_max for axis in self.axes))436 modes = property(lambda self: tuple(axis.modes for axis in self.axes))437 mode = property(lambda self: tuple(axis.mode for axis in self.axes))438 439 union = property(lambda self: tuple(axis.union for axis in self.axes))440 intersection = property(lambda self: tuple(axis.intersection for axis in self.axes))441 difference = property(lambda self: tuple(axis.difference for axis in self.axes))442 443 subseq = property(lambda self: tuple(axis.subseq for axis in self.axes))444 subseq_starts = property(lambda self: tuple(axis.subseq_starts for axis in self.axes))445 subseq_ends = property(lambda self: tuple(axis.subseq_ends for axis in self.axes))446 447 def get(self, query, fallback, vector=True):448 if not vector: return tuple(axis.get(query, fallback) for axis in self.axes)449 return tuple(axis.get(query, fb_item) for axis, fb_item in zip(self.axes, fallback))450class PatternRenamer:451 before = "\u2190"452 after = "\u2192"453 whole = "\u2194"454 455 @classmethod456 def is_pattern(cls, value):457 return (cls.before in value) or (cls.after in value) or (cls.whole in value)458 459 @classmethod460 def make(cls, subseq, subseq_starts, subseq_ends):461 pattern = subseq462 if (not subseq_starts): pattern = cls.before + pattern463 if (not subseq_ends): pattern = pattern + cls.after464 if (pattern == cls.before+cls.after): pattern = cls.whole465 return pattern466 467 @classmethod468 def apply(cls, value, src_pattern, pattern):469 middle = src_pattern.lstrip(cls.before).rstrip(cls.after).rstrip(cls.whole)470 if middle not in value: return value # pattern not applicable471 i_mid = value.index(middle)472 473 sL, sC, sR = "", value, ""474 475 if src_pattern.startswith(cls.before):476 if middle: sL = value[:i_mid]477 478 if src_pattern.endswith(cls.after):479 if middle: sR = value[i_mid+len(middle):]480 481 return pattern.replace(cls.before, sL).replace(cls.after, sR).replace(cls.whole, sC)482 483 @classmethod484 def apply_to_attr(cls, obj, attr_name, pattern, src_pattern):...
build_parameter_ref.py
Source:build_parameter_ref.py
...14 def __init__(self, file_name,title):15 self.lines=[]16 self.toc_dict = {}17 self.file_name = file_name + '.rst'18 self.add_lines((len(title)+1) * '#')19 self.add_lines(title)20 self.add_lines((len(title)+1) * '#')21 self.add_lines()22 def add_lines(self,lines='', indent=0):23 if type(lines) != list: lines=[lines]24 for l in lines:25 self.lines.append( {'type': 'text', 'text': l, 'indent': indent})26 def add_heading(self,txt, level=0):27 self.add_lines()28 m='*=_^'29 self.add_lines(txt)30 self.add_lines(m[level]*(len(txt)+1))31 self.add_lines()32 def add_directive(self,direct_type, caption='', body=[], indent=0):33 if type(body) != list: body=[body]34 self.lines.append({'type': 'directive', 'direct_type': direct_type, 'body' : body, 'indent' :indent, 'params':{}})35 self.add_lines()36 def collapsable_code(self,file_name):37 a=138 '''39 ..raw:: html40 41 < details >42 < summary > code < / summary >43 44 ..literalinclude::../../../ demos / minimal_example.py45 :language: python46 :caption:47 48 ..raw:: html49 50 < / details >51 '''52 def write(self):53 file_name = path.join(root_param_ref_dir, self.file_name)54 with open(file_name ,'w') as f:55 for l in self.lines:56 indent=l['indent'] * '\t'57 if l['type'] == 'text':58 f.write( indent + l['text']+'\n')59 if l['type'] == 'directive':60 f.write(indent + '\n')61 f.write(indent+ '.. ' + l['direct_type'] + '::' +'\n')62 for p,val in l['params'].items():63 f.write(indent + '\t:' + p + ': ' +str(val) + '\n')64 f.write(indent + '\n')65 o = sorted(l['body']) if l['direct_type'] =='toctree' and l['sort_body'] else l['body']66 for b in o:67 f.write(indent +'\t' +b +'\n')68 f.write(indent + '\n')69 a=170 def add_new_toc_to_page(self, toc_name, indent=0, maxdepth=2, sort_body=False):71 self.lines.append({'type':'directive','direct_type': 'toctree','body': [],'sort_body': sort_body, 'indent':indent,'params': {'maxdepth': maxdepth}})72 self.toc_dict[toc_name] = self.lines[-1]73 def add_toc_link(self, toc_name, linked_toc):74 self.toc_dict[toc_name]['body'].append(linked_toc.file_name.replace('\\', '/'))75 def write_param_dict_defaults(self, params):76 self.add_lines()77 self.add_directive('warning', body='Lots more to add here and work on layout!!')78 self.add_heading('Parameters:', level=0)79 self.add_params_from_dict(params)80 self.write()81 def add_params_from_dict(self,params, indent=0):82 for key in sorted(params.keys()):83 item= params[key]84 if type(item) == dict:85 self.add_lines('* ``' + key + '``:' + ' nested parameter dictionary' , indent=indent+1)86 self.add_params_from_dict( item, indent=1)87 continue88 if type(item) == PVC:89 self.add_lines('* ``' + key + '`` : ``' + str(item.info['type']) + '`` '90 + (' *<optional>*' if not item.info['is_required'] else '**<isrequired>**') , indent=indent+1)91 if item.info['doc_str'] is not None:92 self.add_lines('Description: - ' + str(item.info['doc_str'].strip()), indent=indent+2)93 self.add_lines()94 self.add_lines('- default: ``' + str(item.get_default()) + '``', indent=indent+2)95 for k, v in item.info.items():96 if k not in ['type', 'default_value', 'is_required', 'doc_str'] and v is not None:97 self.add_lines('- ' + k + ': ``' + str(v) + '``', indent=indent+2)98 self.add_lines()99 elif type(item) == PLC:100 self.add_lines('* ``' + key + '``:' + (' *<optional>*' if not item.info['is_required'] else '**<isrequired>**'), indent=indent + 1)101 if item.info['doc_str'] is not None:102 self.add_lines('Description: - ' + str(item.info['doc_str'].strip()), indent=indent + 2)103 self.add_lines()104 if type(item.info['list_type']) == dict or type(item.info['default_list']) == dict or type(item.info['default_value']) == dict:105 self.add_lines()106 self.add_lines(key + ': still working on display of lists of dict, eg nested polygon list ', indent=indent+0)107 self.add_lines()108 continue109 self.add_lines('- a list containing type: ``' + str(item.info['list_type']) + '``', indent=indent+2)110 self.add_lines('- default list item: ``'111 + str(item.info['default_value'].get_defaults() if item.info['default_value'] is not None else None) + '``', indent=indent+2)112 for k, v in item.info.items():113 if k not in ['default_list','list_type', 'default_value', 'is_required', 'doc_str'] and v is not None:114 self.add_lines('- ' + k + ': ``' + str(v) + '``', indent=indent+2)115 self.add_lines()116 else:117 self.add_lines()118 self.add_lines(key +': still working on display of default params of type ' + str(type(params[key])),indent=indent+0)119 self.add_lines()120def make_sub_pages(class_type):121 # make doc pages from defaults of all python in named dir122 if class_type in default_class_names:123 mod_name= default_class_names[class_type].rsplit('.', maxsplit=2)[0]124 else:125 mod_name=package_util.get_package_name()+ '.' +class_type126 mod = importlib.import_module( mod_name)127 package_dir= package_util.get_package_dir()128 toc = RSTfileBuilder(class_type+'_toc', class_type)129 toc.add_lines('**Module:** ' + package_util.package_relative_file_name(mod.__name__).strip())130 toc.add_lines()131 toc.add_new_toc_to_page(class_type, maxdepth=1,sort_body=True)132 for f in glob(path.join( package_dir,class_type,'*.py')):133 mod_str= path.splitext(f)[0].split(package_util.get_root_package_dir() +'\\')[-1].replace('\\','.')134 mod = importlib.import_module(mod_str)135 package_util.get_package_name()136 for name, c in inspect.getmembers(mod):137 if not inspect.isclass(c) : continue138 #print(name)139 if name[0] == '_': continue # ignore internal/base classes flagged with underscore140 if not issubclass(c, ParameterBaseClass): continue141 if c.__module__ != mod.__name__ : continue # only work on locally declared claseses142 instance= c()143 p = RSTfileBuilder(name, name)144 p.add_lines('**Description:** ' + instance.docs['description'])145 p.add_lines()146 p.add_lines('**Class:** ' + c.__module__ + '.' + c.__name__)147 p.add_lines()148 p.add_lines('**File:** ' + package_util.package_relative_file_name(mod.__file__))149 p.add_lines()150 # show pinhertince151 parents=''152 for b in inspect.getmro(c)[1:]:153 #print(b.__name__, parents)154 if b.__name__ in ['object', 'ParameterBaseClass'] :continue155 parents = b.__name__ + '> ' + parents156 p.add_lines('**Inheritance:** ' + parents + c.__name__)157 p.add_lines()158 internal_name = instance.default_params['name'].get_default() if instance.default_params['name'].get_default() is not None else 'not given in defaults'159 p.add_lines('**Default internal name:** ``"' + internal_name.strip() + '"``' )160 p.add_lines()161 # get all defaults and wrte to yaml162 #instance.merge_with_class_defaults({},{})163 #write_YAML(name+'.yaml',instance.params)164 p.add_heading('Parameters:', level=0)165 p.add_params_from_dict(instance.default_params)166 p.write()167 toc.add_toc_link(class_type,p)168 toc.write()169 return toc170def build_param_ref():171 # parameter ref TOC172 page= RSTfileBuilder('parameter_ref_toc','Parameter details')173 page.add_lines('Links to details of parameter default values, acceptable values etc.')174 page.add_lines()175 page.add_directive('note',body= 'Lots more to add here!!')176 page.add_heading('Top level parameters',level=1)177 sp = RSTfileBuilder('shared_params', 'shared_params')178 sp.write_param_dict_defaults(run_params_defaults_template['shared_params'])179 page.add_new_toc_to_page('top', maxdepth=1)180 page.add_toc_link('top', sp)181 # look at readers182 toc= make_sub_pages('reader')183 page.add_toc_link('top', toc)184 page.add_heading('Case parameters',level=1)185 page.add_new_toc_to_page('case', maxdepth=1, sort_body=True)186 rp = RSTfileBuilder('run_params', 'run_params')187 rp.write_param_dict_defaults(default_case_param_template['run_params'])188 page.add_toc_link('case',rp)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!