Best Python code snippet using pytest-django_python
event.py
Source:event.py
...79 tpl = (self.id, str(self.time),80 self.latitude, self.longitude,81 self.depth_km, self.magnitude)82 return fmt % tpl83 def _get_origin(self):84 origin = self.preferred_origin()85 if origin is None:86 origin = self.origins[0]87 return origin88 def _get_magnitude(self):89 magnitude = self.preferred_magnitude()90 if magnitude is None:91 magnitude = self.magnitudes[0]92 return magnitude93 @property94 def id(self):95 '''Return the origin resource_id.96 '''97 origin = self._get_origin()98 return origin.resource_id.id99 @property100 def time(self):101 '''Return the origin time.102 '''103 origin = self._get_origin()104 return origin.time105 @property106 def latitude(self):107 '''Return the origin latitude.108 '''109 origin = self._get_origin()110 return origin.latitude111 @property112 def longitude(self):113 '''Return the origin longitude.114 '''115 origin = self._get_origin()116 return origin.longitude117 @property118 def depth(self):119 '''Return the origin depth.120 '''121 origin = self._get_origin()122 return origin.depth123 @property124 def depth_km(self):125 '''Return the origin depth.126 '''127 origin = self._get_origin()128 return origin.depth / 1000129 @property130 def magnitude(self):131 '''Return the magnitude value.132 '''133 magnitude = self._get_magnitude()134 return magnitude.mag135def get_event_dict(eventid):136 """Get event dictionary from ComCat using event ID.137 Args:138 eventid (str): Event ID that can be found in ComCat.139 Returns:140 dict: Dictionary containing fields:141 - id String event ID...
typing_api.py
Source:typing_api.py
1'''This file contains the typing api that should exist in python in2order to do metaprogramming and reflection on the built-in typing module'''3import typing4from dagster import check5def _get_origin(ttype):6 return getattr(ttype, '__origin__', None)7def is_closed_python_optional_type(ttype):8 # Optional[X] is Union[X, NoneType] which is what we match against here9 origin = _get_origin(ttype)10 return origin == typing.Union and len(ttype.__args__) == 2 and ttype.__args__[1] == type(None)11def is_python_dict_type(ttype):12 if ttype is dict or ttype is typing.Dict:13 return True14 if ttype is None:15 return False16 origin = _get_origin(ttype)17 # py37 origin is typing.Dict, pre-37 is dict18 return origin == typing.Dict or origin == dict19def is_closed_python_list_type(ttype):20 if ttype is None:21 return False22 if ttype is typing.List:23 return False24 if not hasattr(ttype, '__args__'):25 return False26 if ttype.__args__ is None or len(ttype.__args__) != 1:27 return False28 origin = _get_origin(ttype)29 return origin == typing.List or origin is list30def is_closed_python_dict_type(ttype):31 '''32 A "closed" generic type has all of its type parameters parameterized33 by other closed or concrete types.34 e.g.35 Returns true for typing.Dict[int, str] but not for typing.Dict36 '''37 if ttype is None:38 return False39 if ttype is typing.Dict:40 return False41 if not hasattr(ttype, '__args__'):42 return False43 if ttype.__args__ is None or len(ttype.__args__) != 2:44 return False45 key_type, value_type = ttype.__args__46 origin = _get_origin(ttype)47 # when it is a raw typing.Dict the arguments are instances of TypeVars48 return (49 # py37 origin is typing.Dict, pre-37 is dict50 (origin == typing.Dict or origin is dict)51 and not isinstance(key_type, typing.TypeVar)52 and not isinstance(value_type, typing.TypeVar)53 )54def is_closed_python_tuple_type(ttype):55 '''56 A "closed" generic type has all of its type parameters parameterized57 by other closed or concrete types.58 e.g.59 Returns true for Tuple[int] or Tuple[str, int] but false for Tuple or tuple60 '''61 if ttype is None:62 return False63 if ttype is typing.Tuple:64 return False65 if not hasattr(ttype, '__args__'):66 return False67 if ttype.__args__ is None:68 return False69 origin = _get_origin(ttype)70 return origin == typing.Tuple or origin is tuple71def is_closed_python_set_type(ttype):72 '''73 A "closed" generic type has all of its type parameters parameterized74 by other closed or concrete types.75 e.g.76 Returns true for Set[string] but false for Set or set77 '''78 if ttype is None:79 return False80 if ttype is typing.Set:81 return False82 if not hasattr(ttype, '__args__'):83 return False84 if ttype.__args__ is None or len(ttype.__args__) != 1:85 return False86 inner_type = ttype.__args__[0]87 origin = _get_origin(ttype)88 return (origin == typing.Set or origin is set) and not isinstance(inner_type, typing.TypeVar)89def get_optional_inner_type(ttype):90 check.invariant(91 is_closed_python_optional_type(ttype), 'type must pass is_closed_python_optional_type check'92 )93 return ttype.__args__[0]94def get_list_inner_type(ttype):95 check.param_invariant(is_closed_python_list_type(ttype), 'ttype')96 return ttype.__args__[0]97def get_set_inner_type(ttype):98 check.param_invariant(is_closed_python_set_type(ttype), 'ttype')99 return ttype.__args__[0]100def get_tuple_type_params(ttype):101 check.param_invariant(is_closed_python_tuple_type(ttype), 'ttype')...
collect.py
Source:collect.py
...12 if isinstance(self.origin, PayModeCabal):13 name = self.origin.paymode.rec_name14 return name15 @classmethod16 def _get_origin(cls):17 models = super()._get_origin()18 models.append('payment.paymode.cabal')19 return models20class CollectReturnStart(metaclass=PoolMeta):21 __name__ = 'payment.collect.return.start'22 @property23 def origin_name(self):24 pool = Pool()25 PayModeCabal = pool.get('payment.paymode.cabal')26 name = super().origin_name27 if isinstance(self.origin, PayModeCabal):28 name = self.origin.paymode.rec_name29 return name30 @classmethod31 def _get_origin(cls):32 models = super()._get_origin()33 models.append('payment.paymode.cabal')34 return models35 @classmethod36 def _paymode_types(cls):37 types = super()._paymode_types()...
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!!