Best Python code snippet using hypothesis
test_decorators.py
Source:test_decorators.py  
...807        @staticmethod808        def a_staticmethod() -> int:809            return _counter.inc()810        @classmethod811        def a_classmethod(cls) -> int:812            return _counter.inc()813    instance = _Class()814    for each in (815            _function,816            instance.a_method,817            instance.a_staticmethod,818            instance.a_classmethod,819            _Class.a_staticmethod,820            _Class.a_classmethod,821    ):822        first = each()823        second = each()824        assert first == second825@_parametrize__cache_test826def test__cache__args(827        decorator: DecoratorType,828        kwargs: Any829) -> None:830    """Test cache decorators with same argument values."""831    # pylint: disable=missing-function-docstring832    @decorator(**kwargs)833    def _function(arg1: int, arg2: int) -> int:834        return arg1 + arg2 + _counter.inc()835    @decorator(**kwargs)836    class _Class:837        def a_method(self, arg1: int, arg2: int) -> int: \838                # pylint: disable=no-self-use839            return arg1 + arg2 + _counter.inc()840        @staticmethod841        def a_staticmethod(arg1: int, arg2: int) -> int:842            return arg1 + arg2 + _counter.inc()843        @classmethod844        def a_classmethod(cls, arg1: int, arg2: int) -> int:845            return arg1 + arg2 + _counter.inc()846    instance = _Class()847    for each in (848            _function,849            instance.a_method,850            instance.a_staticmethod,851            instance.a_classmethod,852            _Class.a_staticmethod,853            _Class.a_classmethod,854    ):855        first = each(1, 1)856        different = each(1, 2)857        assert different != first858        second = each(1, 1)859        assert first == second860@_parametrize__cache_test861def test__cache__kwargs(862        decorator: DecoratorType,863        kwargs: Any864) -> None:865    """Test cache decorators with same optional arguments."""866    # pylint: disable=missing-function-docstring867    @decorator(**kwargs)868    def _function(869            arg0: int,  # pylint: disable=unused-argument870            arg1: int = 0,871            arg2: int = 3872    ) -> int:873        return arg1 + arg2 + _counter.inc()874    @decorator(**kwargs)875    class _Class:876        def a_method(  # pylint: disable=no-self-use877                self,878                arg0: int,  # pylint: disable=unused-argument879                arg1: int = 0,880                arg2: int = 3881        ) -> int:882            return arg1 + arg2 + _counter.inc()883        @staticmethod884        def a_staticmethod(885                arg0: int,  # pylint: disable=unused-argument886                arg1: int = 0,887                arg2: int = 3888        ) -> int:889            return arg1 + arg2 + _counter.inc()890        @classmethod891        def a_classmethod(892                cls,893                arg0: int,  # pylint: disable=unused-argument894                arg1: int = 0,895                arg2: int = 3896        ) -> int:897            return arg1 + arg2 + _counter.inc()898    instance = _Class()899    for each in (900            _function,901            instance.a_method,902            instance.a_staticmethod,903            instance.a_classmethod,904            _Class.a_staticmethod,905            _Class.a_classmethod,906    ):907        first = each(1, arg2=1)908        different = each(1, arg2=2)909        assert different != first910        second = each(1, arg2=1)911        assert first == second912@_parametrize__cache_test913def test__cache__default_kwargs(914        decorator: DecoratorType,915        kwargs: Any916) -> None:917    """Test cache decorators with same default argument values."""918    # pylint: disable=missing-function-docstring919    @decorator(**kwargs)920    def _function(921            arg0: int,  # pylint: disable=unused-argument922            arg1: int = 0,923            arg2: int = 3924    ) -> int:925        return arg1 + arg2 + _counter.inc()926    @decorator(**kwargs)927    class _Class():928        def a_method(  # pylint: disable=no-self-use929                self,930                arg0: int,  # pylint: disable=unused-argument931                arg1: int = 0,932                arg2: int = 3933        ) -> int:934            return arg1 + arg2 + _counter.inc()935        @staticmethod936        def a_staticmethod(937                arg0: int,  # pylint: disable=unused-argument938                arg1: int = 0,939                arg2: int = 3940        ) -> int:941            return arg1 + arg2 + _counter.inc()942        @classmethod943        def a_classmethod(944                cls,945                arg0: int,  # pylint: disable=unused-argument946                arg1: int = 0,947                arg2: int = 3948        ) -> int:949            return arg1 + arg2 + _counter.inc()950    instance = _Class()951    for each in (952            _function,953            instance.a_method,954            instance.a_staticmethod,955            instance.a_classmethod,956            _Class.a_staticmethod,957            _Class.a_classmethod,958    ):959        first = each(1)960        different = each(1, arg2=4)961        assert different != first962        second = each(1, arg1=0)963        assert first == second964@_parametrize__cache_test965def test__cache__synchronize(966        decorator: DecoratorType,967        kwargs: Any968) -> None:969    """Test that the cache decorators are synchronized correctly."""970    # pylint: disable=missing-function-docstring971    max_entries = 3972    variables = _create_variables()973    @decorator(max_entries=max_entries, **kwargs)974    def _function() -> str:975        return _inc_dec(variables)976    @decorator(max_entries=max_entries, **kwargs)977    class _Class:978        def a_method(self) -> str:  # pylint: disable=no-self-use979            return _inc_dec(variables)980        @staticmethod981        def a_staticmethod() -> str:982            return _inc_dec(variables)983        @classmethod984        def a_classmethod(cls) -> str:985            return _inc_dec(variables)986    instance = _Class()987    for each in (988            _function,989            instance.a_method,990            (_Class.a_staticmethod, instance.a_staticmethod),991            (_Class.a_classmethod, instance.a_classmethod),992    ):993        _reset_variables(variables)994        _test_synchronized(variables, each, expected_count=1)995# cache ###996def test__cache__no_args__expire() -> None:997    """Test `@cache` with no arguments expires the cache."""998    # pylint: disable=missing-function-docstring999    @cache(expire_time_secs=0)1000    def _function() -> int:1001        return _counter.inc()1002    @cache(expire_time_secs=0)1003    class _Class:1004        def a_method(self) -> int:  # pylint: disable=no-self-use1005            return _counter.inc()1006        @staticmethod1007        def a_staticmethod() -> int:1008            return _counter.inc()1009        @classmethod1010        def a_classmethod(cls) -> int:1011            return _counter.inc()1012    instance = _Class()1013    for each in (1014            _function,1015            instance.a_method,1016            instance.a_staticmethod,1017            instance.a_classmethod,1018            _Class.a_staticmethod,1019            _Class.a_classmethod,1020    ):1021        first = each()1022        second = each()1023        assert first < second1024def test__cache__max_entries() -> None:1025    """1026    Test cache decorators with argument `max_entries`.1027    Calls method with different arguments.1028    """1029    # pylint: disable=missing-function-docstring1030    max_entries = 31031    @cache(expire_time_secs=10, max_entries=max_entries)1032    def _function(arg: int) -> int:1033        return arg1034    @cache(expire_time_secs=10, max_entries=max_entries)1035    class _Class:1036        def a_method(self, arg: int) -> int:  # pylint: disable=no-self-use1037            return arg1038        @staticmethod1039        def a_staticmethod(arg: int) -> int:1040            return arg1041        @classmethod1042        def a_classmethod(cls, arg: int) -> int:1043            return arg1044    instance = _Class()1045    for each in (1046            _function,1047            instance.a_method,1048            instance.a_staticmethod,1049            instance.a_classmethod,1050            _Class.a_staticmethod,1051            _Class.a_classmethod,1052    ):1053        for index in range(max_entries + 1):1054            value = each(index)1055            assert value == index1056        # endfor1057@_parametrize__cache_test1058def test__cache__max_entries__same_args(1059        decorator: DecoratorType,1060        kwargs: Any1061) -> None:1062    """1063    Test cache decorators with argument `max_entries`.1064    Calls method with same arguments.1065    """1066    # pylint: disable=missing-function-docstring1067    max_entries = 31068    @decorator(max_entries=max_entries, **kwargs)1069    def _function(arg: int) -> int:1070        return arg1071    @decorator(max_entries=max_entries, **kwargs)1072    class _Class:1073        def a_method(self, arg: int) -> int:  # pylint: disable=no-self-use1074            return arg1075        @staticmethod1076        def a_staticmethod(arg: int) -> int:1077            return arg1078        @classmethod1079        def a_classmethod(cls, arg: int) -> int:1080            return arg1081    instance = _Class()1082    for each in (1083            _function,1084            instance.a_method,1085            instance.a_staticmethod,1086            instance.a_classmethod,1087            _Class.a_staticmethod,1088            _Class.a_classmethod,1089    ):1090        for _ in range(max_entries + 1):1091            value = each(0)1092            assert value == 01093        # endfor1094def test__cache__max_entries__refresh() -> None:1095    """Test `@cache` with argument `max_entries`."""1096    # pylint: disable=missing-function-docstring1097    max_entries = 31098    @cache(expire_time_secs=10, max_entries=max_entries)1099    def _function(arg: int) -> int:1100        return arg + _counter.inc()1101    @cache(expire_time_secs=10, max_entries=max_entries)1102    class _Class:1103        def a_method(self, arg: int) -> int:  # pylint: disable=no-self-use1104            return arg + _counter.inc()1105        @staticmethod1106        def a_staticmethod(arg: int) -> int:1107            return arg + _counter.inc()1108        @classmethod1109        def a_classmethod(cls, arg: int) -> int:1110            return arg + _counter.inc()1111    instance = _Class()1112    for each in (1113            _function,1114            instance.a_method,1115            instance.a_staticmethod,1116            instance.a_classmethod,1117            _Class.a_staticmethod,1118            _Class.a_classmethod,1119    ):1120        first = each(0)1121        for index in range(max_entries):1122            each(index + 1)1123        second = each(0)...pydocfodder.py
Source:pydocfodder.py  
1"""Something just to look at via pydoc."""23import types45class A_classic:6    "A classic class."7    def A_method(self):8        "Method defined in A."9    def AB_method(self):10        "Method defined in A and B."11    def AC_method(self):12        "Method defined in A and C."13    def AD_method(self):14        "Method defined in A and D."15    def ABC_method(self):16        "Method defined in A, B and C."17    def ABD_method(self):18        "Method defined in A, B and D."19    def ACD_method(self):20        "Method defined in A, C and D."21    def ABCD_method(self):22        "Method defined in A, B, C and D."232425class B_classic(A_classic):26    "A classic class, derived from A_classic."27    def AB_method(self):28        "Method defined in A and B."29    def ABC_method(self):30        "Method defined in A, B and C."31    def ABD_method(self):32        "Method defined in A, B and D."33    def ABCD_method(self):34        "Method defined in A, B, C and D."35    def B_method(self):36        "Method defined in B."37    def BC_method(self):38        "Method defined in B and C."39    def BD_method(self):40        "Method defined in B and D."41    def BCD_method(self):42        "Method defined in B, C and D."4344class C_classic(A_classic):45    "A classic class, derived from A_classic."46    def AC_method(self):47        "Method defined in A and C."48    def ABC_method(self):49        "Method defined in A, B and C."50    def ACD_method(self):51        "Method defined in A, C and D."52    def ABCD_method(self):53        "Method defined in A, B, C and D."54    def BC_method(self):55        "Method defined in B and C."56    def BCD_method(self):57        "Method defined in B, C and D."58    def C_method(self):59        "Method defined in C."60    def CD_method(self):61        "Method defined in C and D."6263class D_classic(B_classic, C_classic):64    "A classic class, derived from B_classic and C_classic."65    def AD_method(self):66        "Method defined in A and D."67    def ABD_method(self):68        "Method defined in A, B and D."69    def ACD_method(self):70        "Method defined in A, C and D."71    def ABCD_method(self):72        "Method defined in A, B, C and D."73    def BD_method(self):74        "Method defined in B and D."75    def BCD_method(self):76        "Method defined in B, C and D."77    def CD_method(self):78        "Method defined in C and D."79    def D_method(self):80        "Method defined in D."818283class A_new(object):84    "A new-style class."8586    def A_method(self):87        "Method defined in A."88    def AB_method(self):89        "Method defined in A and B."90    def AC_method(self):91        "Method defined in A and C."92    def AD_method(self):93        "Method defined in A and D."94    def ABC_method(self):95        "Method defined in A, B and C."96    def ABD_method(self):97        "Method defined in A, B and D."98    def ACD_method(self):99        "Method defined in A, C and D."100    def ABCD_method(self):101        "Method defined in A, B, C and D."102103    def A_classmethod(cls, x):104        "A class method defined in A."105    A_classmethod = classmethod(A_classmethod)106107    def A_staticmethod():108        "A static method defined in A."109    A_staticmethod = staticmethod(A_staticmethod)110111    def _getx(self):112        "A property getter function."113    def _setx(self, value):114        "A property setter function."115    def _delx(self):116        "A property deleter function."117    A_property = property(fdel=_delx, fget=_getx, fset=_setx,118                          doc="A sample property defined in A.")119120    A_int_alias = int121122class B_new(A_new):123    "A new-style class, derived from A_new."124125    def AB_method(self):126        "Method defined in A and B."127    def ABC_method(self):128        "Method defined in A, B and C."129    def ABD_method(self):130        "Method defined in A, B and D."131    def ABCD_method(self):132        "Method defined in A, B, C and D."133    def B_method(self):134        "Method defined in B."135    def BC_method(self):136        "Method defined in B and C."137    def BD_method(self):138        "Method defined in B and D."139    def BCD_method(self):140        "Method defined in B, C and D."141142class C_new(A_new):143    "A new-style class, derived from A_new."144145    def AC_method(self):146        "Method defined in A and C."147    def ABC_method(self):148        "Method defined in A, B and C."149    def ACD_method(self):150        "Method defined in A, C and D."151    def ABCD_method(self):152        "Method defined in A, B, C and D."153    def BC_method(self):154        "Method defined in B and C."155    def BCD_method(self):156        "Method defined in B, C and D."157    def C_method(self):158        "Method defined in C."159    def CD_method(self):160        "Method defined in C and D."161162class D_new(B_new, C_new):163    """A new-style class, derived from B_new and C_new.164    """165166    def AD_method(self):167        "Method defined in A and D."168    def ABD_method(self):169        "Method defined in A, B and D."170    def ACD_method(self):171        "Method defined in A, C and D."172    def ABCD_method(self):173        "Method defined in A, B, C and D."174    def BD_method(self):175        "Method defined in B and D."176    def BCD_method(self):177        "Method defined in B, C and D."178    def CD_method(self):179        "Method defined in C and D."180    def D_method(self):181        "Method defined in D."182183class FunkyProperties(object):184    """From SF bug 472347, by Roeland Rengelink.185186    Property getters etc may not be vanilla functions or methods,187    and this used to make GUI pydoc blow up.188    """189190    def __init__(self):191        self.desc = {'x':0}192193    class get_desc:194        def __init__(self, attr):195            self.attr = attr196        def __call__(self, inst):197            print('Get called', self, inst)198            return inst.desc[self.attr]199    class set_desc:200        def __init__(self, attr):201            self.attr = attr202        def __call__(self, inst, val):203            print('Set called', self, inst, val)204            inst.desc[self.attr] = val205    class del_desc:206        def __init__(self, attr):207            self.attr = attr208        def __call__(self, inst):209            print('Del called', self, inst)210            del inst.desc[self.attr]211212    x = property(get_desc('x'), set_desc('x'), del_desc('x'), 'prop x')213214215submodule = types.ModuleType(__name__ + '.submodule',
...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!!
