Best Python code snippet using avocado_python
config.py
Source:config.py
...53 def is_present(self, parsed_args):54 raise NotImplementedError("is_present")55 def add(self, command, parsed_args, value):56 raise NotImplementedError("add")57 def _check_arg(self, parsed_args, arg_name):58 return getattr(parsed_args, arg_name, None)59class StringConfiguration(Configuration):60 def __init__(self, name, arg_name, arg_value_key=None):61 super(StringConfiguration, self).__init__(name, arg_name)62 self.arg_value_key = arg_value_key63 def is_applicable(self, command):64 return command.supports_arg(self.arg_name.replace('_', '-'))65 def is_present(self, parsed_args):66 if (not self.arg_value_key):67 return self._check_arg(parsed_args, self.arg_name)68 else:69 return self._check_arg(parsed_args, self.arg_name) \70 and self.arg_value_key in getattr(parsed_args, self.arg_name)71 def add(self, command, parsed_args, value):72 if (not self.arg_value_key):73 setattr(parsed_args, self.arg_name, value)74 else:75 if (not self._check_arg(parsed_args, self.arg_name)):76 setattr(parsed_args, self.arg_name, {})77 getattr(parsed_args, self.arg_name)[self.arg_value_key] = value78class BooleanConfiguration(Configuration):79 def __init__(self, name):80 super(BooleanConfiguration, self).__init__(name, name)81 self.no_version_arg_name = "no_" + name82 def is_applicable(self, command):83 return command.supports_arg(self.arg_name.replace('_', '-')) and \84 command.supports_arg(self.no_version_arg_name.replace('_', '-'))85 def is_present(self, parsed_args):86 return self._check_arg(parsed_args, self.arg_name) \87 or self._check_arg(parsed_args, self.no_version_arg_name)88 def add(self, command, parsed_args, value):89 if (value.lower() == 'true'):90 setattr(parsed_args, self.arg_name, True)91 setattr(parsed_args, self.no_version_arg_name, False)92 elif (value.lower() == 'false'):93 setattr(parsed_args, self.arg_name, False)94 setattr(parsed_args, self.no_version_arg_name, True)95 else:96 raise exceptions.InvalidBooleanConfigError(97 config_value=value,98 config_key=self.arg_name,99 profile_var_name=configutils.get_current_profile_var_name(...
dsn.py
Source:dsn.py
...28# cx_Oracle. Use of the ConnectParams class or the keyword arguments to29# connect() and create_pool() is recommended instead.30#------------------------------------------------------------------------------31from . import errors32def _check_arg(name: str, value: str) -> None:33 """34 Checks the argument to ensure that it does not contain (, ) or = as these35 characters are not permitted within connect strings.36 """37 if "(" in value or ")" in value or "=" in value:38 errors._raise_err(errors.ERR_INVALID_MAKEDSN_ARG, name=name)39def makedsn(host: str, port: int, sid: str=None, service_name: str=None,40 region:str=None, sharding_key: str=None,41 super_sharding_key: str=None) -> str:42 """43 Return a string suitable for use as the dsn parameter for connect(). This44 string is identical to the strings that are defined in the tnsnames.ora45 file.46 """47 connect_data_parts = []48 _check_arg("host", host)49 if sid is not None:50 _check_arg("sid", sid)51 connect_data_parts.append(f"(SID={sid})")52 if service_name is not None:53 _check_arg("service_name", service_name)54 connect_data_parts.append(f"(SERVICE_NAME={service_name})")55 if region is not None:56 _check_arg("region", region)57 connect_data_parts.append(f"(REGION={region})")58 if sharding_key is not None:59 _check_arg("sharding_key", sharding_key)60 connect_data_parts.append(f"(SHARDING_KEY={sharding_key})")61 if super_sharding_key is not None:62 _check_arg("super_sharding_key", super_sharding_key)63 connect_data_parts.append(f"(SUPER_SHARDING_KEY={super_sharding_key})")64 connect_data = "".join(connect_data_parts)65 return f"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={host})" \...
rational_numbers_v1.py
Source:rational_numbers_v1.py
...16 return self.numer == other.numer and self.denom == other.denom17 def __repr__(self):18 return f'{self.numer}/{self.denom}'19 def __add__(self, other):20 other = __class__._check_arg(other)21 return Rational(self.numer * other.denom + self.denom * other.numer,22 self.denom * other.denom)23 def __sub__(self, other):24 other = __class__._check_arg(other)25 return Rational(self.numer * other.denom - self.denom * other.numer,26 self.denom * other.denom)27 def __mul__(self, other):28 other = __class__._check_arg(other)29 return Rational(self.numer * other.numer, self.denom * other.denom)30 def __truediv__(self, other):31 other = __class__._check_arg(other)32 return Rational(self.numer * other.denom, self.denom * other.numer)33 def __abs__(self):34 return Rational(abs(self.numer), abs(self.denom))35 def __pow__(self, power):36 if power is None or type(power) is not int:37 raise ValueError('NaN or Not an Integer')38 if self.numer == 0 and power == 0:39 raise ArithmeticError("0/n ** 0 is undefined")40 if power >= 0:41 return Rational(self.numer ** power, self.denom ** power);42 else:43 p = abs(power);44 return Rational(self.denom ** p, self.numer ** p);45 def __rpow__(self, base):46 if base is None or \47 (type(base) is not int and type(base) is not float):48 raise ValueError('NaN')49 if (base == 0 or base == 0.0) and self.numer == 0:50 raise ArithmeticError("0 ** 0 is undefined")51 return base ** (self.numer / self.denom)52 @staticmethod53 def _gcd(n, d):54 # n > 0 and d > 055 n, d = (d, n) if n < d else (n, d)56 if d == 0: return n57 r = n58 while r > 1:59 r = n % d60 n, d = d, r61 return n if r == 0 else r62 @staticmethod63 def _div_by_gvd(n, d):64 r = __class__._gcd(n, d)65 return (n // r, d // r)66 @staticmethod67 def _check_arg(r):68 if r is None: raise ValueError('NaN')69 if type(r) is Rational:70 return r71 if type(r) is int:72 return Rational(r, 1)...
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!!