How to use is_right_version method in autotest

Best Python code snippet using autotest_python

versionable_class.py

Source:versionable_class.py Github

copy

Full Screen

...24 @staticmethod25 def get_version():26 return "get_version_from_system"27 @classmethod28 def is_right_version(cls, version):29 if version is not None:30 if "version is satisfied":31 return True32 return False33 def func1(self):34 print "func1"35 def func2(self):36 print "func2"37 # get_version could be inherited.38 class VC3(VC2, VersionableClass):39 @classmethod40 def is_right_version(cls, version):41 if version is not None:42 if "version+1 is satisfied":43 return True44 return False45 def func2(self):46 print "func2_2"47 class M(VCP):48 pass49 m = M() # <- When class is constructed the right version is50 # automatically selected. In this case VC3 is selected.51 m.func2() # call VC3.func2(m)52 m.func1() # call VC2.func1(m)53 m.foo() # call VC1.foo(m)54 # When controlled "program" version is changed then is necessary call55 check_repair_versions or recreate object.56 m.check_repair_versions()57 # priority of class. (change place where is method searched first in group58 # of verisonable class.)59 class PP(VersionableClass):60 def __new__(cls, *args, **kargs):61 PP.master_class = PP62 return super(PP, cls).__new__(cls, *args, **kargs)63 class PP2(PP, VersionableClass):64 @staticmethod65 def get_version():66 return "get_version_from_system"67 @classmethod68 def is_right_version(cls, version):69 if version is not None:70 if "version is satisfied":71 return True72 return False73 def func1(self):74 print "PP func1"75 class N(VCP, PP):76 pass77 n = N()78 n.func1() # -> "func2"79 n.set_priority_class(PP, [VCP, PP])80 n.func1() # -> "PP func1"81 Necessary for using:82 1) Subclass of versionable class must have implemented class methods83 get_version and is_right_version. These two methods are necessary84 for correct version section. Class without this method will be never85 chosen like suitable class.86 2) Every class derived from master_class have to add to class definition87 inheritance from VersionableClass. Direct inheritance from Versionable88 Class is use like a mark for manipulation with VersionableClass.89 3) Master of VersionableClass have to defined class variable90 cls.master_class.91 """92 def __new__(cls, *args, **kargs):93 cls.check_repair_versions()94 return super(VersionableClass, cls).__new__(cls, *args, **kargs)95 #VersionableClass class management class.96 @classmethod97 def check_repair_versions(cls, master_classes=None):98 """99 Check version of versionable class and if version not100 match repair version to correct version.101 @param master_classes: Check and repair only master_class.102 @type master_classes: list.103 """104 if master_classes is None:105 master_classes = cls._find_versionable_baseclass()106 for base in master_classes:107 cls._check_repair_version_class(base)108 @classmethod109 def set_priority_class(cls, prioritized_class, group_classes):110 """111 Set class priority. Limited only for change bases class priority inside112 one subclass.__bases__ after that continue to another class.113 """114 def change_position(ccls):115 if not VersionableClass in ccls.__bases__:116 bases = list(ccls.__bases__)117 index = None118 remove_variant = None119 for i, item in enumerate(ccls.__bases__):120 if (VersionableClass in item.__bases__ and121 item.master_class in group_classes):122 if index is None:123 index = i124 if item.master_class is prioritized_class:125 remove_variant = item126 bases.remove(item)127 break128 else:129 return130 bases.insert(index, remove_variant)131 ccls.__bases__ = tuple(bases)132 def find_cls(ccls):133 change_position(ccls)134 for base in ccls.__bases__:135 find_cls(base)136 find_cls(cls)137 @classmethod138 def _check_repair_version_class(cls, master_class):139 version = None140 for class_version in master_class._find_versionable_subclass():141 try:142 version = class_version.get_version()143 if class_version.is_right_version(version):144 cls._switch_by_class(class_version)145 break146 except NotImplementedError:147 continue148 else:149 cls._switch_by_class(class_version)150 @classmethod151 def _find_versionable_baseclass(cls):152 """153 Find versionable class in master class.154 """155 ver_class = []156 for superclass in cls.mro():157 if VersionableClass in superclass.__bases__:158 ver_class.append(superclass.master_class)159 return set(ver_class)160 @classmethod161 def _find_versionable_subclass(cls):162 """163 Find versionable subclasses which subclass.master_class == cls164 """165 subclasses = [cls]166 for sub in cls.__subclasses__():167 if VersionableClass in list(sub.__bases__):168 subclasses.extend(sub._find_versionable_subclass())169 return subclasses170 @classmethod171 def _switch_by_class(cls, new_class):172 """173 Finds all class with same master_class as new_class in class tree174 and replaces them by new_class.175 @param new_class: Class for replacing.176 """177 def find_replace_class(bases):178 for base in bases:179 if (VersionableClass in base.__bases__ and180 base.master_class == new_class.master_class):181 bnew = list(bases)182 bnew[bnew.index(base)] = new_class183 return tuple(bnew)184 else:185 bnew = find_replace_class(base.__bases__)186 if bnew:187 base.__bases__ = bnew188 bnew = find_replace_class(cls.__bases__)189 if bnew:190 cls.__bases__ = bnew191 # Method defined in part below must be defined in192 # verisonable class subclass.193 @classmethod194 def get_version(cls):195 """196 Get version of installed OpenVSwtich.197 Must be re-implemented for in child class.198 @return: Version or None when get_version is unsuccessful.199 """200 raise NotImplementedError("Method 'get_verison' must be"201 " implemented in child class")202 @classmethod203 def is_right_version(cls, version):204 """205 Check condition for select control class.206 Function must be re-implemented in new OpenVSwitchControl class.207 Must be re-implemented for in child class.208 @param version: version of OpenVSwtich209 """210 raise NotImplementedError("Method 'is_right_version' must be"...

Full Screen

Full Screen

core.py

Source:core.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3Implementation of the GPT-3 engine.4Website:5 https://openai.com6"""7import json8import os9from pathlib import Path10from typing import Dict11import openai12from pylogics.syntax.base import Formula13from nl2ltl.engines.base import Engine14from nl2ltl.engines.gpt3 import ENGINE_ROOT15from nl2ltl.engines.gpt3.output import GPT3Output, parse_gpt3_output, parse_gpt3_result16from nl2ltl.filters.base import Filter17openai.api_key = os.getenv("OPENAI_API_KEY")18engine_root = ENGINE_ROOT19DATA_DIR = engine_root / "data"20PROMPT_PATH = engine_root / DATA_DIR / "prompt.json"21class GPT3Engine(Engine):22 """The GPT-3 engine."""23 def __init__(24 self,25 prompt: Path = PROMPT_PATH,26 temperature: float = 0.5,27 ):28 """GPT-3 LLM Engine initialization."""29 self.prompt = self._load_prompt(prompt)30 self.temperature = temperature31 def _load_prompt(self, prompt):32 return json.load(open(prompt, "r"))["prompt"]33 @classmethod34 def __check_openai_version(cls):35 """Check that the GPT-3 tool is at the right version."""36 is_right_version = openai.__version__ == "0.23.0"37 if not is_right_version:38 raise Exception(39 "OpenAI needs to be at version 0.23.0. "40 "Please install it manually using:"41 "\n"42 "pip install openai==0.23.0"43 )44 def __post_init__(self):45 """Do post-initialization checks."""46 self.__check_openai_version()47 def translate(48 self, utterance: str, filtering: Filter = None49 ) -> Dict[Formula, float]:50 """From NL to best matching LTL formulas with confidence."""51 return _process_utterance(utterance, self.prompt, self.temperature, filtering)52def _process_utterance(53 utterance: str, prompt: str, temperature: float, filtering: Filter54) -> Dict[Formula, float]:55 """56 Process NL utterance.57 :param utterance: the natural language utterance58 :return: a dict with matching formulas and confidence59 """60 query = "NL: " + utterance + "\n"61 prediction = openai.Completion.create(62 model="text-davinci-002",63 prompt=prompt + query,64 temperature=temperature,65 max_tokens=200,66 top_p=1.0,67 frequency_penalty=0.0,68 presence_penalty=0.0,69 stop=["\n\n"],70 )71 gpt3_result: GPT3Output = parse_gpt3_output(prediction)72 matching_formulas: Dict[Formula, float] = parse_gpt3_result(gpt3_result, filtering)...

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 autotest 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