How to use append_chunk method in yandex-tank

Best Python code snippet using yandex-tank

render.py

Source:render.py Github

copy

Full Screen

...59 truncate=self.truncate,60 term=term,61 special=special or self.special,62 )63 def append_chunk(self, text: str, *, math: t.Optional[str] = None) -> None:64 self.elements.append(Chunk(text, math=math))65 def append_term(self, term: terms.Term) -> None:66 self.elements.append(self.renderer.render_term(term))67@d.dataclass(eq=False)68class Renderer:69 _special_patterns: t.List[SpecialPattern] = d.field(default_factory=list)70 _symbol_to_math: t.Dict[str, str] = d.field(default_factory=dict)71 def add_pattern(self, pattern: SpecialPattern) -> None:72 self._special_patterns.append(pattern)73 def add_math_symbol(self, symbol: str, math: str) -> None:74 self._symbol_to_math[symbol] = math75 def render_condition(76 self,77 condition: inference.Condition,78 substitution: t.Optional[terms.Substitution] = None,79 ) -> Box:80 builder = BoxBuilder(self)81 render_condition(condition, builder, substitution)82 return builder.build()83 def render_term(self, term: terms.Term) -> Box:84 builder = BoxBuilder(self)85 self._render_term(term, builder)86 special = None87 for pattern in self._special_patterns:88 substitution = unification.match(pattern.pattern, term)89 if substitution is not None:90 special = pattern.render(91 *(92 self.render_term(substitution[variable])93 for variable in pattern.variables94 ),95 )96 break97 return builder.build(term=term, special=special)98 @functools.singledispatchmethod99 def _render_term(self, term: terms.Term, builder: BoxBuilder) -> None:100 raise NotImplementedError(f"`_render_term` not implemented for {type(term)}")101 @_render_term.register102 def _render_variable(self, term: terms.Variable, builder: BoxBuilder) -> None:103 info = define.get_variable_info(term)104 text = term.name105 math = term.name106 if info is not None:107 text = info.text or term.name108 math = info.math109 builder.append_chunk(text or "unnamed", math=math)110 @_render_term.register111 def _render_symbol(self, term: terms.Symbol, builder: BoxBuilder) -> None:112 builder.append_chunk(113 term.symbol, math=self._symbol_to_math.get(term.symbol, None)114 )115 @_render_term.register116 def _render_sequence(self, term: terms.Sequence, builder: BoxBuilder) -> None:117 builder.append_chunk("(", math="\\left(")118 for child, lookahead in iter_lookahead(term.elements):119 builder.append_term(child)120 if lookahead:121 builder.append_chunk(" ", math="\\ ")122 builder.append_chunk(")", math="\\right)")123 @_render_term.register124 def _render_value(self, term: terms.Value, builder: BoxBuilder) -> None:125 render_value(term, builder)126 @_render_term.register127 def _render_apply(self, term: terms.Apply, builder: BoxBuilder) -> None:128 render_operator(term.operator, term.arguments, builder)129@functools.singledispatch130def render_value(value: terms.Value, builder: BoxBuilder) -> None:131 raise NotImplementedError(f"`render_value` not implemented for {value}")132@functools.singledispatch133def render_operator(134 operator: terms.Operator, arguments: terms.Arguments, builder: BoxBuilder135) -> None:136 raise NotImplementedError(f"`render_operator` not implemented for {operator}")137@functools.singledispatch138def render_condition(139 condition: inference.Condition,140 builder: BoxBuilder,141 substitution: t.Optional[terms.Substitution] = None,142) -> None:143 raise NotImplementedError(f"`render_condition` not implemented for {condition}")144@render_condition.register145def render_boolean_condition(146 condition: booleans.BooleanCondition,147 builder: BoxBuilder,148 substitution: t.Optional[terms.Substitution] = None,149) -> None:150 builder.append_term(condition.term.substitute(substitution or {}))151class RenderFunctionOperator(t.Protocol):152 def __call__(self, arguments: terms.Arguments, builder: BoxBuilder) -> None:153 pass154_render_function_operator: t.Dict[terms.FunctionOperator, RenderFunctionOperator] = {}155def register_function_operator(156 operator: terms.FunctionOperator,157) -> t.Callable[[RenderFunctionOperator], RenderFunctionOperator]:158 def decorator(render: RenderFunctionOperator) -> RenderFunctionOperator:159 _render_function_operator[operator] = render160 return render161 return decorator162@render_operator.register163def render_function_operator(164 operator: terms.FunctionOperator, arguments: terms.Arguments, builder: BoxBuilder,165) -> None:166 try:167 render = _render_function_operator[operator]168 except KeyError:169 if operator.name is not None:170 builder.append_chunk(171 operator.name, math=f"\\applyFunction{{\\texttt{{{operator.name}}}}}",172 )173 builder.append_chunk("(", math="{{")174 for argument, lookahead in iter_lookahead(arguments):175 builder.append_term(argument)176 if lookahead:177 builder.append_chunk(", ", math=",\\ ")178 builder.append_chunk(")", math="}}")179 else:180 error_operator = operator.name or operator.implementation181 raise NotImplementedError(182 f"rendering function for {error_operator!r} not implemented"183 )184 else:185 render(arguments, builder)186@register_function_operator(terms.replace)187def render_replace(arguments: terms.Arguments, builder: BoxBuilder) -> None:188 builder.append_term(arguments[0])189 builder.append_chunk("[", math="\\mxPreApplySkip\\left[")190 builder.append_term(arguments[1])191 builder.append_chunk(" ↦ ", math="\\mapsto")192 builder.append_term(arguments[2])193 builder.append_chunk("]", math="\\right]")194@register_function_operator(booleans.lnot)195def render_booleans_lnot(arguments: terms.Arguments, builder: BoxBuilder) -> None:196 builder.append_chunk("¬", math="\\lnot")197 builder.append_term(arguments[0])198@register_function_operator(mappings.getitem)199def render_getitem(arguments: terms.Arguments, builder: BoxBuilder) -> None:200 builder.append_term(arguments[0])201 builder.append_chunk("[", math="\\mxPreApplySkip\\left[")202 builder.append_term(arguments[1])203 builder.append_chunk("]", math="\\right]")204 if len(arguments) == 3:205 builder.append_chunk("?", math="?")206 builder.append_term(arguments[2])207@register_function_operator(mappings.setitem)208def render_setitem(arguments: terms.Arguments, builder: BoxBuilder) -> None:209 builder.append_term(arguments[0])210 builder.append_chunk("[", math="\\left[")211 builder.append_term(arguments[1])212 builder.append_chunk(" ↦ ", math="\\mapsto")213 builder.append_term(arguments[2])214 builder.append_chunk("]", math="\\right]")215@register_function_operator(records.getfield_operator)216def render_getfield(arguments: terms.Arguments, builder: BoxBuilder) -> None:217 builder.append_term(arguments[0])218 field = arguments[1]219 builder.append_chunk(".", math=".")220 if isinstance(field, strings.String):221 builder.append_chunk(field.value, math=f"\\texttt{{{field.value}}}")222 else:223 builder.append_term(field)224@register_function_operator(records.setfield_operator)225def render_setfield(arguments: terms.Arguments, builder: BoxBuilder) -> None:226 builder.append_chunk("(", math="\\left(")227 builder.append_term(arguments[0])228 field = arguments[1]229 builder.append_chunk(".", math=".")230 if isinstance(field, strings.String):231 builder.append_chunk(field.value, math=f"\\texttt{{{field.value}}}")232 else:233 builder.append_term(field)234 builder.append_chunk(" := ", math=":=")235 builder.append_term(arguments[2])236 builder.append_chunk(")", math="\\right)")237@register_function_operator(tuples.project_operator)238def render_project(arguments: terms.Arguments, builder: BoxBuilder) -> None:239 index = arguments[1]240 if isinstance(index, numbers.Integer):241 builder.append_chunk(f"#{index.value}")242 builder.append_chunk("(", math="\\left(")243 builder.append_term(arguments[0])244 builder.append_chunk(")", math="\\right)")245 else:246 builder.append_term(arguments[0])247 builder.append_chunk("[", math="\\left[")248 builder.append_term(index)249 builder.append_chunk("]", math="\\right]")250@register_function_operator(sets.not_contains)251def _render_sets_not_contains(arguments: terms.Arguments, builder: BoxBuilder) -> None:252 builder.append_term(arguments[1])253 builder.append_chunk(" ∉ ", math="\\not\\in")254 builder.append_term(arguments[0])255@register_function_operator(sets.contains)256def _render_sets_contains(arguments: terms.Arguments, builder: BoxBuilder) -> None:257 builder.append_term(arguments[1])258 builder.append_chunk(" ∈ ", math="\\in")259 builder.append_term(arguments[0])260@register_function_operator(records.construct)261def _render_records_construct(arguments: terms.Arguments, builder: BoxBuilder) -> None:262 builder.append_chunk("⟨", math="\\left\\langle")263 for (field_name, field_value), lookahead in iter_lookahead(264 zip(arguments[::2], arguments[1::2])265 ):266 builder.append_term(field_name)267 builder.append_chunk(": ", math=":")268 builder.append_term(field_value)269 if lookahead:270 builder.append_chunk(", ", math=",")271 builder.append_chunk("⟩", math="\\right\\rangle")272def register_binary_infix_operator(273 operator: terms.FunctionOperator,274 text: str,275 *,276 math: t.Optional[str] = None,277 prefix: t.Optional[Chunk] = None,278 suffix: t.Optional[Chunk] = None,279) -> None:280 @register_function_operator(operator)281 def _render_operator(arguments: terms.Arguments, builder: BoxBuilder) -> None:282 if prefix is not None:283 builder.append_chunk(prefix.text, math=prefix.math)284 builder.append_term(arguments[0])285 builder.append_chunk(text, math=math)286 builder.append_term(arguments[1])287 if suffix is not None:288 builder.append_chunk(suffix.text, math=suffix.math)289register_binary_infix_operator(numbers.add, " + ", math="+")290register_binary_infix_operator(numbers.sub, " - ", math="-")291register_binary_infix_operator(numbers.mul, " · ", math="\\cdot")292register_binary_infix_operator(numbers.real_div, " ÷ ", math="\\div")293register_binary_infix_operator(294 numbers.floor_div,295 " ÷ ",296 math="\\div",297 prefix=Chunk("⌊", math="\\left\\lfloor"),298 suffix=Chunk("⌋", math="\\right\\rfloor"),299)300register_binary_infix_operator(booleans.equals, " = ", math="=")301register_binary_infix_operator(booleans.not_equals, " ≠ ", math="\\neq")302register_binary_infix_operator(booleans.lor, " ∨ ", math="\\lor")303@render_value.register304def _render_boolean(value: booleans.Boolean, builder: BoxBuilder) -> None:305 if value.value:306 builder.append_chunk("true", math="\\texttt{true}")307 else:308 builder.append_chunk("false", math="\\texttt{false}")309@render_value.register310def _render_mapping(value: mappings.Mapping, builder: BoxBuilder) -> None:311 builder.append_chunk("{", math="\\left\\{")312 for (key, term), lookahead in iter_lookahead(value.entries.items()):313 builder.append_term(key)314 builder.append_chunk(" ↦ ", math="\\mapsto")315 builder.append_term(term)316 if lookahead:317 builder.append_chunk(", ", math=",")318 builder.append_chunk("}", math="\\right\\}")319@render_value.register320def _render_heap(value: references.Heap, builder: BoxBuilder) -> None:321 builder.append_chunk("{", math="\\left\\{")322 builder.append_chunk("HEAP")323 builder.append_chunk("}", math="\\right\\}")324@render_value.register325def _render_number(value: numbers.Number, builder: BoxBuilder) -> None:326 builder.append_chunk(str(value.value), math=str(value.value))327@render_value.register328def _render_null(value: null.Null, builder: BoxBuilder) -> None:329 builder.append_chunk("⊥", math="\\bot")330@render_value.register331def _render_string(value: strings.String, builder: BoxBuilder) -> None:332 builder.append_chunk(333 f"{value.value!r}", math=f"\\text{{`\\texttt{{{value.value}}}'}}"334 )335@render_value.register336def _render_record(value: records.Record, builder: BoxBuilder) -> None:337 builder.append_chunk("⟨", math="\\left\\langle")338 for (field_name, field_value), lookahead in iter_lookahead(value.fields.items()):339 builder.append_chunk(field_name)340 builder.append_chunk(": ", math=":")341 builder.append_term(field_value)342 if lookahead:343 builder.append_chunk(", ", math=",")344 builder.append_chunk("⟩", math="\\right\\rangle")345@render_value.register346def _render_tuple(value: tuples.Tuple, builder: BoxBuilder) -> None:347 builder.append_chunk("⟨", math="\\left[\\,")348 for component, lookahead in iter_lookahead(value.components):349 builder.append_term(component)350 if lookahead:351 builder.append_chunk(", ", math=",")352 builder.append_chunk("⟩", math="\\,\\right]")353@render_value.register354def _render_set(value: sets.Set, builder: BoxBuilder) -> None:355 builder.append_chunk("{", math="\\left\\{")356 for member, lookahead in iter_lookahead(value.members):357 builder.append_term(member)358 if lookahead:359 builder.append_chunk(", ", math=",\\ ")360 builder.append_chunk("}", math="\\right\\}")361@render_value.register362def _render_reference(value: references.Reference, builder: BoxBuilder) -> None:363 builder.append_chunk(f"ref({value.name or value.address})")...

Full Screen

Full Screen

spacy_exploration.py

Source:spacy_exploration.py Github

copy

Full Screen

...155 'person_2': token2.text,156 'score': similarity_score157 })158 stats['similarity'] = similarity159def append_chunk(original, chunk):160 return original + ' ' + chunk161def is_relation_candidate(token):162 deps = ["ROOT", "adj", "attr", "agent", "amod"]163 return any(subs in token.dep_ for subs in deps)164def is_construction_candidate(token):165 deps = ["compound", "prep", "conj", "mod"]166 return any(subs in token.dep_ for subs in deps)167def get_sentences():168 return [sent.string.strip() for sent in doc.sents]169def process_subject_object_pairs(tokens):170 subject = ''171 object = ''172 relation = ''173 subjectConstruction = ''174 objectConstruction = ''175 for token in tokens:176 if "punct" in token.dep_:177 continue178 if is_relation_candidate(token):179 relation = append_chunk(relation, token.lemma_)180 if is_construction_candidate(token):181 if subjectConstruction:182 subjectConstruction = append_chunk(subjectConstruction, token.text)183 if objectConstruction:184 objectConstruction = append_chunk(objectConstruction, token.text)185 if "subj" in token.dep_:186 subject = append_chunk(subject, token.text)187 subject = append_chunk(subjectConstruction, subject)188 subjectConstruction = ''189 if "obj" in token.dep_:190 object = append_chunk(object, token.text)191 object = append_chunk(objectConstruction, object)192 objectConstruction = ''193 return (subject.strip(), relation.strip(), object.strip())194def process_sentence(sentence):195 tokens = nlp(sentence)196 return process_subject_object_pairs(tokens)197def print_ner(key):198 print("===============", key, "===============")199 for ner in stats['ner'][key]:200 print("ner: ", list(ner.keys())[0], " freq: ", list(ner.values())[0])201def print_stats():202 print("Stats:")203 print_ner('persons')204 print_ner('gpes')205 print_ner('orgs')...

Full Screen

Full Screen

historical_funcs.py

Source:historical_funcs.py Github

copy

Full Screen

...148 chunk_one = random.randint(5, 50)149 else:150 # pick a number between 10 and 39...151 chunk_one = random.randint(10, 40)152 prices = append_chunk(o, val_one, prices, chunk_one)153 chunk_two = random.randint(5, 60 - len(prices))154 prices = append_chunk(val_one, val_two, prices, chunk_two)155 chunk_three = 60 - len(prices) - 1156 prices = append_chunk(val_two, c, prices, chunk_three)157 # 10% of the time, it will be completely random.158 else:159 # create random price values for 56 of the 60 seconds between high and low160 for x in range(0, 56):161 prices.append(round(random.uniform(l, h), 3))162 # insert high and low randomly163 prices.insert(random.randint(2, int(len(prices))-1), h)164 prices.insert(random.randint(2, int(len(prices))-1), l)165 prices.append(c)166 return prices167def momentum_second_data(o, h, l, c):168 if c > o:169 val_one = l170 val_two = h171 else:172 # dojis have same momentum as red candles173 val_one = h174 val_two = l175 d1 = abs(o - val_one)176 d2 = abs(val_one - val_two)177 d3 = abs(val_two - c)178 full_d = d1 + d2 + d3179 if full_d == 0:180 d1, d2, d3 = 20,20,19181 else:182 d1 = int((d1 / full_d)*60)183 d2 = int((d2 / full_d)*60)184 d3 = 59 - d1 - d2185 prices = [o]186 prices = append_chunk(o, val_one, prices, d1)187 prices = append_chunk(val_one, val_two, prices, d2)188 prices = append_chunk(val_two, c, prices, d3)189 return prices190def append_chunk(first_value, last_value, main_list, middle_length):191 if middle_length == 0:192 # main_list.append(last_value)193 return main_list194 d = abs(first_value - last_value) / middle_length195 if last_value < first_value:196 d *= -1197 for _ in range(1, middle_length):198 first_value += d199 main_list.append(round(first_value, 2))200 main_list.append(last_value)201 return main_list202def randomize_hl():203 o, h, l, c = 1, 2, .5, 1204 hl_order = {}...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful