Best Python code snippet using assertpy_python
tracetype.py
Source:tracetype.py  
...22                orig = {orig}23            meta = orig24        self.val = val25        self.meta = meta26    def is_nan(self):27        return pd.isnull(self.val)28    # def isna(self):29    #    return pd.isnull(self.val)30    def __hash__(self):31        return hash(self.val)32    # https://diveintopython3.net/special-method-names.html33    def __str__(self):34        return str(self.val) + "`"35        # return str(self.val) + "_" + str(self.meta)36        # return repr(self)37    def __repr__(self):38        return "Trace(" + repr(self.val) + ', ' + repr(self.meta) + ')'39    def __add__(self, other):40        if not isinstance(other, Trace):41            other = Trace(other)42        if self.is_nan() and other.is_nan():43            return Trace(pd.NA, self.meta | other.meta)44        if self.is_nan():45            return self46        if other.is_nan():47            return other48        return Trace(self.val + other.val, self.meta | other.meta)49    def __sub__(self, other):50        if not isinstance(other, Trace):51            other = Trace(other)52        if self.is_nan() and other.is_nan():53            return Trace(pd.NA, self.meta | other.meta)54        if self.is_nan():55            return self56        if other.is_nan():57            return other58        return Trace(self.val - other.val, self.meta | other.meta)59    def __mul__(self, other):60        if not isinstance(other, Trace):61            other = Trace(other)62        if self.is_nan() and other.is_nan():63            return Trace(pd.NA, self.meta | other.meta)64        if self.is_nan():65            return self66        if other.is_nan():67            return other68        return Trace(self.val * other.val, self.meta | other.meta)69    def __truediv__(self, other):70        if not isinstance(other, Trace):71            other = Trace(other)72        if self.is_nan() and other.is_nan():73            return Trace(pd.NA, self.meta | other.meta)74        if self.is_nan():75            return self76        if other.is_nan():77            return other78        return Trace(self.val / other.val, self.meta | other.meta)79    def __floordiv__(self, other):80        if not isinstance(other, Trace):81            other = Trace(other)82        if self.is_nan() and other.is_nan():83            return Trace(pd.NA, self.meta | other.meta)84        if self.is_nan():85            return self86        if other.is_nan():87            return other88        return Trace(self.val // other.val, self.meta | other.meta)89    def __mod__(self, other):90        if not isinstance(other, Trace):91            other = Trace(other)92        if self.is_nan() and other.is_nan():93            return Trace(pd.NA, self.meta | other.meta)94        if self.is_nan():95            return self96        if other.is_nan():97            return other98        return Trace(self.val % other.val, self.meta | other.meta)99    # skip divmod for now100    def __pow__(self, other):101        if not isinstance(other, Trace):102            other = Trace(other)103        if self.is_nan() and other.is_nan():104            return Trace(pd.NA, self.meta | other.meta)105        if self.is_nan():106            return self107        if other.is_nan():108            return other109        return Trace(self.val ** other.val, self.meta | other.meta)110    def __lshift__(self, other):111        if not isinstance(other, Trace):112            other = Trace(other)113        if self.is_nan() and other.is_nan():114            return Trace(pd.NA, self.meta | other.meta)115        if self.is_nan():116            return self117        if other.is_nan():118            return other119        return Trace(self.val << other.val, self.meta | other.meta)120    def __rshift__(self, other):121        if not isinstance(other, Trace):122            other = Trace(other)123        if self.is_nan() and other.is_nan():124            return Trace(pd.NA, self.meta | other.meta)125        if self.is_nan():126            return self127        if other.is_nan():128            return other129        return Trace(self.val >> other.val, self.meta | other.meta)130    def __and__(self, other):131        if not isinstance(other, Trace):132            other = Trace(other)133        if self.is_nan() and other.is_nan():134            return Trace(pd.NA, self.meta | other.meta)135        if self.is_nan():136            return self137        if other.is_nan():138            return other139        return Trace(self.val & other.val, self.meta | other.meta)140    def __xor__(self, other):141        if not isinstance(other, Trace):142            other = Trace(other)143        if self.is_nan() and other.is_nan():144            return Trace(pd.NA, self.meta | other.meta)145        if self.is_nan():146            return self147        if other.is_nan():148            return other149        return Trace(self.val ^ other.val, self.meta | other.meta)150    def __or__(self, other):151        if not isinstance(other, Trace):152            other = Trace(other)153        if self.is_nan() and other.is_nan():154            return Trace(pd.NA, self.meta | other.meta)155        if self.is_nan():156            return self157        if other.is_nan():158            return other159        return Trace(self.val | other.val, self.meta | other.meta)160    # r161    def __radd__(self, other):162        if not isinstance(other, Trace):163            other = Trace(other)164        if self.is_nan() and other.is_nan():165            return Trace(pd.NA, self.meta | other.meta)166        if self.is_nan():167            return self168        if other.is_nan():169            return other170        return Trace(other.val + self.val, self.meta | other.meta)171    def __rsub__(self, other):172        if not isinstance(other, Trace):173            other = Trace(other)174        if self.is_nan() and other.is_nan():175            return Trace(pd.NA, self.meta | other.meta)176        if self.is_nan():177            return self178        if other.is_nan():179            return other180        return Trace(other.val - self.val, self.meta | other.meta)181    def __rmul__(self, other):182        if not isinstance(other, Trace):183            other = Trace(other)184        if self.is_nan() and other.is_nan():185            return Trace(pd.NA, self.meta | other.meta)186        if self.is_nan():187            return self188        if other.is_nan():189            return other190        return Trace(other.val * self.val, self.meta | other.meta)191    def __rtruediv__(self, other):192        if not isinstance(other, Trace):193            other = Trace(other)194        if self.is_nan() and other.is_nan():195            return Trace(pd.NA, self.meta | other.meta)196        if self.is_nan():197            return self198        if other.is_nan():199            return other200        return Trace(other.val / self.val, self.meta | other.meta)201    def __rfloordiv__(self, other):202        if not isinstance(other, Trace):203            other = Trace(other)204        if self.is_nan() and other.is_nan():205            return Trace(pd.NA, self.meta | other.meta)206        if self.is_nan():207            return self208        if other.is_nan():209            return other210        return Trace(other.val // self.val, self.meta | other.meta)211    def __rmod__(self, other):212        if not isinstance(other, Trace):213            other = Trace(other)214        if self.is_nan() and other.is_nan():215            return Trace(pd.NA, self.meta | other.meta)216        if self.is_nan():217            return self218        if other.is_nan():219            return other220        return Trace(other.val % self.val, self.meta | other.meta)221    # skip rdivmod for now222    def __rpow__(self, other):223        if not isinstance(other, Trace):224            other = Trace(other)225        if self.is_nan() and other.is_nan():226            return Trace(pd.NA, self.meta | other.meta)227        if self.is_nan():228            return self229        if other.is_nan():230            return other231        return Trace(other.val ** self.val, self.meta | other.meta)232    def __rlshift__(self, other):233        if not isinstance(other, Trace):234            other = Trace(other)235        if self.is_nan() and other.is_nan():236            return Trace(pd.NA, self.meta | other.meta)237        if self.is_nan():238            return self239        if other.is_nan():240            return other241        return Trace(other.val << self.val, self.meta | other.meta)242    def __rrshift__(self, other):243        if not isinstance(other, Trace):244            other = Trace(other)245        if self.is_nan() and other.is_nan():246            return Trace(pd.NA, self.meta | other.meta)247        if self.is_nan():248            return self249        if other.is_nan():250            return other251        return Trace(other.val >> self.val, self.meta | other.meta)252    def __rand__(self, other):253        if not isinstance(other, Trace):254            other = Trace(other)255        if self.is_nan() and other.is_nan():256            return Trace(pd.NA, self.meta | other.meta)257        if self.is_nan():258            return self259        if other.is_nan():260            return other261        return Trace(other.val & self.val, self.meta | other.meta)262    def __rxor__(self, other):263        if not isinstance(other, Trace):264            other = Trace(other)265        if self.is_nan() and other.is_nan():266            return Trace(pd.NA, self.meta | other.meta)267        if self.is_nan():268            return self269        if other.is_nan():270            return other271        return Trace(other.val ^ self.val, self.meta | other.meta)272    def __ror__(self, other):273        if not isinstance(other, Trace):274            other = Trace(other)275        if self.is_nan() and other.is_nan():276            return Trace(pd.NA, self.meta | other.meta)277        if self.is_nan():278            return self279        if other.is_nan():280            return other281        return Trace(other.val | self.val, self.meta | other.meta)282    # unary283    def __neg__(self):284        return Trace(-self.val, self.meta)285    def __pos__(self):286        return Trace(+self.val, self.meta)287    def __abs__(self):288        return Trace(abs(self.val), self.meta)289    def __invert__(self):290        return Trace(~self.val, self.meta)291    def __complex__(self):292        return Trace(complex(self.val), self.meta)293    def __int__(self):294        return Trace(int(self.val), self.meta)295    def __float__(self):296        return Trace(float(self.val), self.meta)297    def __round__(self):298        return Trace(round(self.val), self.meta)299    def __round__(self, other):300        if not isinstance(other, Trace):301            other = Trace(other)302        if self.is_nan() and other.is_nan():303            return Trace(pd.NA, self.meta | other.meta)304        if self.is_nan():305            return self306        if other.is_nan():307            return other308        return Trace(round(self.val, other.val), self.meta | other.meta)309    def __ceil__(self):310        return Trace(math.ceil(self.val), self.meta)311    def __floor__(self):312        return Trace(math.floor(self.val), self.meta)313    def __trunc__(self):314        return Trace(math.trunc(self.val), self.meta)315    def __index__(self):316        return self.val.__int__()317    # comp318    def __eq__(self, other):319        if not isinstance(other, Trace):320            other = Trace(other)321        if self.is_nan() and other.is_nan():322            return Trace(True, self.meta | other.meta)323        if self.is_nan():324            return Trace(False, self.meta)325        if other.is_nan():326            return Trace(False, other.meta)327        return Trace(self.val == other.val, self.meta | other.meta)328    def __ne__(self, other):329        if not isinstance(other, Trace):330            other = Trace(other)331        if self.is_nan() and other.is_nan():332            return Trace(False, self.meta | other.meta)333        if self.is_nan():334            return Trace(True, self.meta)335        if other.is_nan():336            return Trace(True, other.meta)337        return Trace(self.val != other.val, self.meta | other.meta)338    def __lt__(self, other):339        if not isinstance(other, Trace):340            other = Trace(other)341        if self.is_nan() and other.is_nan():342            return Trace(pd.NA, self.meta | other.meta)343        if self.is_nan():344            return self345        if other.is_nan():346            return other347        return Trace(self.val < other.val, self.meta | other.meta)348    def __le__(self, other):349        if not isinstance(other, Trace):350            other = Trace(other)351        if self.is_nan() and other.is_nan():352            return Trace(pd.NA, self.meta | other.meta)353        if self.is_nan():354            return self355        if other.is_nan():356            return other357        return Trace(self.val <= other.val, self.meta | other.meta)358    def __gt__(self, other):359        if not isinstance(other, Trace):360            other = Trace(other)361        if self.is_nan() and other.is_nan():362            return Trace(pd.NA, self.meta | other.meta)363        if self.is_nan():364            return self365        if other.is_nan():366            return other367        return Trace(self.val > other.val, self.meta | other.meta)368    def __ge__(self, other):369        if not isinstance(other, Trace):370            other = Trace(other)371        if self.is_nan() and other.is_nan():372            return Trace(pd.NA, self.meta | other.meta)373        if self.is_nan():374            return self375        if other.is_nan():376            return other377        return Trace(self.val >= other.val, self.meta | other.meta)378    def __bool__(self):379        return self.val.__bool__()380    def __call__(self, *args, **kwargs):381        return self.val(*args, **kwargs)382class TraceDtype(ExtensionDtype):383    """A custom data type, to be paired with an ExtensionArray."""384    type = Trace385    name = "Trace"386    na_value = pd.NA387    def __init__(self, orig=None):388        self.orig = orig389        #self.na_value = Trace(pd.NA, orig)390    @classmethod391    def construct_array_type(cls):392        """Return the array type associated with this dtype."""393        return TraceArray394class TraceArray(ExtensionArray, ExtensionScalarOpsMixin):395    """Abstract base class for custom 1-D array types."""396    def __init__(self, values, orig=None, dtype=None, copy=False):397        """Instantiate the array.398        If you're doing any type coercion in here, you will also need399        that in an overwritten __setitem__ method.400        But, here we coerce the input values into Decimals.401        """402        if isinstance(dtype, TraceDtype) and orig is None:403            orig = dtype.orig404        values = [Trace(val, None, orig) for val in values]405        self._data = np.asarray(values, dtype=object)406        self._dtype = TraceDtype(orig)407    @classmethod408    def _from_sequence(cls, scalars, dtype=None, copy=False):409        """Construct a new ExtensionArray from a sequence of scalars."""410        return cls(scalars, dtype=dtype)411    @classmethod412    def _from_factorized(cls, values, original):413        """Reconstruct an ExtensionArray after factorization."""414        return cls(values)415    def __getitem__(self, item):416        """Select a subset of self."""417        return self._data[item]418    def __len__(self) -> int:419        """Length of this array."""420        return len(self._data)421    @property422    def nbytes(self):423        """The byte size of the data."""424        return self._itemsize * len(self)425    @property426    def dtype(self):427        """An instance of 'ExtensionDtype'."""428        return self._dtype429    def isna(self):430        """A 1-D array indicating if each value is missing."""431        return np.array([x.is_nan() for x in self._data], dtype=bool)432    def take(self, indexer, allow_fill=False, fill_value=None):433        """Take elements from an array.434        Relies on the take method defined in pandas:435        https://github.com/pandas-dev/pandas/blob/e246c3b05924ac1fe083565a765ce847fcad3d91/pandas/core/algorithms.py#L1483436        """437        from pandas.api.extensions import take438        data = self._data439        if allow_fill and fill_value is None:440            fill_value = self.dtype.na_value441        result = take(442            data, indexer, fill_value=fill_value, allow_fill=allow_fill)443        return self._from_sequence(result)444    def copy(self):445        """Return a copy of the array."""...test_lvector2.py
Source:test_lvector2.py  
...42    assert Vec2(0, 1).compare_to(Vec2(0, 1)) == 043def test_vec2_nan():44    nan = float("nan")45    inf = float("inf")46    assert not Vec2F(0, 0).is_nan()47    assert not Vec2F(1, 0).is_nan()48    assert Vec2F(nan, 0).is_nan()49    assert Vec2F(0, nan).is_nan()50    assert Vec2F(nan, nan).is_nan()51    assert Vec2F(-nan, 0).is_nan()52    assert Vec2F(-nan, nan).is_nan()53    assert Vec2F(inf, nan).is_nan()54    assert not Vec2F(inf, 0).is_nan()55    assert not Vec2F(inf, inf).is_nan()56    assert not Vec2F(-inf, 0).is_nan()57    assert not Vec2D(0, 0).is_nan()58    assert not Vec2D(1, 0).is_nan()59    assert Vec2D(nan, 0).is_nan()60    assert Vec2D(0, nan).is_nan()61    assert Vec2D(nan, nan).is_nan()62    assert Vec2D(-nan, 0).is_nan()63    assert Vec2D(-nan, nan).is_nan()64    assert Vec2D(inf, nan).is_nan()65    assert not Vec2D(inf, 0).is_nan()66    assert not Vec2D(inf, inf).is_nan()67    assert not Vec2D(-inf, 0).is_nan()68def test_vec2_round():69    original_vector = Vec2(2.3, -2.6)70    rounded_vector = round(original_vector)71    assert rounded_vector.x == 272    assert rounded_vector.y == -373def test_vec2_floor():74    original_vector = Vec2(2.3, -2.6)75    rounded_vector = floor(original_vector)76    assert rounded_vector.x == 277    assert rounded_vector.y == -378def test_vec2_ceil():79    original_vector = Vec2(2.3, -2.6)80    rounded_vector = ceil(original_vector)81    assert rounded_vector.x == 3...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!!
