Best Python code snippet using slash
index.js
Source:index.js  
...7    Base.prototype = {8        func1: function func1() {9            return 'this is func1';10        },11        func2: function func2() {12            return 'this is func2';13        },14        func3: function func3() {15            return 'this is func3';16        }17    };18    Base.staticProp = 'BaseStaticProp';19    describe('suns existence', function () {20        it('is an object', function () {21            suns.should.be.a('object');22        });23        it('version', function () {24            suns.VERSION.should.be.ok;25        });26    });27    describe('normal extending', function () {28        var Child = suns.extend(Base, {29            childfunc1: function childfunc1() {30                return 'this is childfunc1';31            },32            /**33             * @override34             */35            func2: function func2() {36                return 'this is overriden func2';37            }38        });39        var c = new Child();40        it('should have parent property', function () {41            c.should.have.property('func1');42            c.func1().should.be.equal('this is func1');43        });44        it('should have child property', function () {45            c.should.have.property('childfunc1');46            c.childfunc1().should.be.equal('this is childfunc1');47        });48        it('should override parents function', function () {49            c.should.have.property('func2');50            c.func2().should.be.equal('this is overriden func2');51        });52        it('should be able to call parents function', function () {53            c.should.have.property('func2');54            Child.__super__.func2.call(c).should.be.equal('this is func2');55        });56    });57    describe('normal extending with function name', function () {58        var Child = suns.extend(59            'Child',60            Base, {61            childfunc1: function childfunc1() {62                return 'this is childfunc1';63            },64            /**65             * @override66             */67            func2: function func2() {68                return 'this is overriden func2';69            }70        });71        var c = new Child();72        it('should have parent property', function () {73            c.should.have.property('func1');74            c.func1().should.be.equal('this is func1');75        });76        it('should have child property', function () {77            c.should.have.property('childfunc1');78            c.childfunc1().should.be.equal('this is childfunc1');79        });80        it('should override parents function', function () {81            c.should.have.property('func2');82            c.func2().should.be.equal('this is overriden func2');83        });84        it('should be able to call parents function', function () {85            c.should.have.property('func2');86            Child.__super__.func2.call(c).should.be.equal('this is func2');87        });88    });89    describe('multiple extending', function () {90        var Child = suns.extend(91            Base,92            {93                childfunc1: function childfunc1() {94                    return 'this is childfunc1';95                },96                /**97                 * @override98                 */99                func2: function func2() {100                    return 'this is overriden func2';101                }102            },103            {104                childchildfunc1: function childchildfunc1() {105                    return 'this is childchildfunc1';106                },107                /**108                 * @override109                 */110                func2: function func2() {111                    return 'this is overoverriden func2';112                },113                /**114                 * @override115                 */116                func3: function func3() {117                    return 'this is overriden func3';118                }119            }120        );121        var c = new Child();122        it('should have parent property', function () {123            c.should.have.property('func1');124            c.func1().should.be.equal('this is func1');125        });126        it('should have child property', function () {127            c.should.have.property('childfunc1');128            c.should.have.property('childchildfunc1');129            c.childfunc1().should.be.equal('this is childfunc1');130            c.childchildfunc1().should.be.equal('this is childchildfunc1');131        });132        it('should override parents function', function () {133            c.should.have.property('func2');134            c.func2().should.be.equal('this is overoverriden func2');135        });136        it('should be able to call parents function', function () {137            Child.__super__.should.have.property('func2');138            Child.__super__.func2.call(c).should.be.equal('this is overriden func2');139        });140        it('should be able to call parents function', function () {141            Child.__super__.should.have.property('func2');142            Child.__supersuper__.func2.call(c).should.be.equal('this is func2');143        });144        it('should have parents static property', function() {145            Child.should.have.property('staticProp');146            Child.staticProp.should.be.equal('BaseStaticProp');147        });148    });149    describe('multiple extending with name', function () {150        var Child = suns.extend(151            'Child',152            Base,153            {154                childfunc1: function childfunc1() {155                    return 'this is childfunc1';156                },157                /**158                 * @override159                 */160                func2: function func2() {161                    return 'this is overriden func2';162                }163            },164            {165                childchildfunc1: function childchildfunc1() {166                    return 'this is childchildfunc1';167                },168                /**169                 * @override170                 */171                func2: function func2() {172                    return 'this is overoverriden func2';173                },174                /**175                 * @override176                 */177                func3: function func3() {178                    return 'this is overriden func3';179                }180            }181        );182        var c = new Child();183        it('should have parent property', function () {184            c.should.have.property('func1');185            c.func1().should.be.equal('this is func1');186        });187        it('should have child property', function () {188            c.should.have.property('childfunc1');189            c.should.have.property('childchildfunc1');190            c.childfunc1().should.be.equal('this is childfunc1');191            c.childchildfunc1().should.be.equal('this is childchildfunc1');192        });193        it('should override parents function', function () {194            c.should.have.property('func2');195            c.func2().should.be.equal('this is overoverriden func2');196        });197        it('should be able to call parents function', function () {198            Child.__super__.should.have.property('func2');199            Child.__super__.func2.call(c).should.be.equal('this is overriden func2');200        });201        it('should be able to call parents function', function () {202            Child.__super__.should.have.property('func2');203            Child.__supersuper__.func2.call(c).should.be.equal('this is func2');204        });205    });206    describe('constructor overriding', function() {207        var HasConstructor = suns.extend(208            'HasConstructor',209            Base,...test_public.py
Source:test_public.py  
...47    check_func(func1, func1_case_3, True)48    check_func(func1, func1_case_4, True)49    check_func(func1, func1_case_5, True)50def func2_case_1() -> None:51    func2(None)  # success52def func2_case_2() -> None:53    func2(True)  # success54def func2_case_3() -> None:55    func2(1.0)   # fail56def func2_case_4() -> None:57    func2("hello")   # success58def func2_case_5() -> None:59    func2(["hello"])  # fail60def func2_case_6() -> None:61    func2({1, 2, 3})  # fail62def func2_case_7() -> None:63    func2([1, 2, 3])  # success64def func2_case_8() -> None:65    func2([1.0, 2.0, 3.0])  # fail66def func2_case_9() -> None:67    func2({1: "hello"})  # fail68def func2_case_10() -> None:69    T = tp.TypeVar("T", int, str)70    class A(tp.Sequence[T]):71        def __init__(self, value: T):72            self._a: T = value73        @tp.overload  # noqa: F81174        def __getitem__(self, i: int) -> T:  # noqa: F81175            pass76        @tp.overload  # noqa: F81177        def __getitem__(self, s: slice) -> tp.Sequence[T]:  # noqa: F81178            pass79        def __getitem__(self, i):  # noqa: F81180            return self._a81        def __len__(self) -> int:82            pass83    func2(A[str]("hello"))  # fail84def func2_case_11() -> None:85    T = tp.TypeVar("T", bool, str)86    class A(tp.Sequence[T]):87        def __init__(self, value: T):88            self._a: T = value89        @tp.overload  # noqa: F81190        def __getitem__(self, i: int) -> T:   # noqa: F81191            pass92        @tp.overload  # noqa: F81193        def __getitem__(self, s: slice) -> tp.Sequence[T]:  # noqa: F81194            pass95        def __getitem__(self, i):  # noqa: F81196            return self._a97        def __len__(self) -> int:98            pass99    func2(A[bool](True))  # success100def test_func2() -> None:101    check_annotations(func2)102    check_func(func2, func2_case_1, True)103    check_func(func2, func2_case_2, True)104    check_func(func2, func2_case_3, False)105    check_func(func2, func2_case_4, True)106    check_func(func2, func2_case_5, False)107    check_func(func2, func2_case_6, False)108    check_func(func2, func2_case_7, True)109    check_func(func2, func2_case_8, False)110    check_func(func2, func2_case_9, False)111    check_func(func2, func2_case_10, False)112    check_func(func2, func2_case_11, True)113def func3_case_1() -> None:114    func3((1, "re", "rt", ["a", "b", "c"]))  # success...test_multiple_pipelines.py
Source:test_multiple_pipelines.py  
1from stairs.tests.flows.name_extraction import (NameExtractionOneWayFlow,2                                                NameExtractionFlowMultiple)3from stairs.core.pipeline.data_pipeline import concatenate4from utils import run_pipelines, GlobalTestData5def test_connected_pipelines(app):6    @app.pipeline()7    def p_builder(worker, sentence, use_lower):8        data = concatenate(sentence=sentence,9                           use_lower=use_lower)10        data_with_name = data \11            .subscribe_flow(NameExtractionOneWayFlow(),12                            as_worker=False)13        return data_with_name14    @app.pipeline()15    def p_builder_general(worker, sentence, use_lower):16        data = concatenate(sentence=sentence,17                           use_lower=use_lower)18        return data.subscribe_pipeline(p_builder)\19                   .subscribe_flow(NameExtractionFlowMultiple(),20                                   as_worker=False)21    p_builder.compile()22    p_builder_general.compile()23    p_builder_general(sentence="Oleg", use_lower=True)24    run_pipelines(app)25def test_connected_pipelines_multiple(app):26    t = GlobalTestData()27    @app.pipeline()28    def p_builder(worker, sentence, use_lower):29        data = concatenate(sentence=sentence,30                           use_lower=use_lower)31        data_with_name = data\32            .subscribe_flow(NameExtractionOneWayFlow())33        return data_with_name34    @app.pipeline()35    def p_builder_general(worker, sentence, use_lower):36        data = concatenate(sentence=sentence,37                           use_lower=use_lower)38        v1 = data.subscribe_pipeline(p_builder)\39                 .subscribe_flow(NameExtractionFlowMultiple(use_lower=use_lower))40        v2 = data.subscribe_pipeline(p_builder)\41                 .subscribe_flow(NameExtractionFlowMultiple(use_lower=use_lower))42        return concatenate(v1=v1, v2=v2).subscribe_func(t.save_one_item)43    p_builder.compile()44    p_builder_general.compile()45    p_builder_general(sentence="Oleg", use_lower=True)46    run_pipelines(app)47    result = t.get_result()48    assert result['v1']['names'][0] == "oleg"49    assert result['v2']['names'][0] == "oleg"50def test_deep_tree_functions(app):51    t = GlobalTestData()52    @app.consumer()53    def save_globaly(name, result , **kwargs):54        t.save_multiple_items(**{name: result})55    @app.pipeline()56    def p_builder(worker, sentence):57        root_branch = sentence \58            .subscribe_func(lambda sentence: dict(func1="ok"), name='root1') \59            .subscribe_func(lambda sentence: dict(func2="ok"), name='root2')60        return concatenate(61            branch_1=root_branch.subscribe_pipeline(branch_1),62            branch_2=root_branch.subscribe_pipeline(branch_2),63            branch_3=root_branch.subscribe_pipeline(branch_3)64        )65    @app.pipeline()66    def branch_1(work, func1, func2):67        root_branch = concatenate(func1=func1, func2=func2)68        return root_branch \69            .add_value(name='branch_1') \70            .subscribe_func(lambda func1, func2: dict(func1_1="ok"),71                            name='branch_1_1') \72            .subscribe_func(lambda func1, func2: dict(result="branch_1"),73                            name='branch_1_2')\74            .subscribe_consumer(save_globaly)75    @app.pipeline()76    def branch_2(work, func1, func2):77        root_branch = concatenate(func1=func1, func2=func2)78        return root_branch \79            .add_value(name='branch_2') \80            .subscribe_func(lambda func1, func2: dict(func1_1="ok"),81                            name='branch_2_1') \82            .subscribe_func(lambda func1, func2: dict(result="branch_2"),83                            name='branch_2_2')\84            .subscribe_consumer(save_globaly)85    @app.pipeline()86    def branch_3(work, func1, func2):87        root_branch = concatenate(func1=func1, func2=func2)88        return root_branch \89            .add_value(name='branch_3') \90            .subscribe_func(lambda func1, func2: dict(func1_1="ok"),91                            name='branch_3_1') \92            .subscribe_func(lambda func1, func2: dict(result="branch_3"),93                            name='branch_3_2')\94            .subscribe_consumer(save_globaly)95    p_builder.compile()96    branch_1.compile()97    branch_2.compile()98    branch_3.compile()99    p_builder(sentence="Oleg", use_lower=True)100    run_pipelines(app)101    result = t.get_result()102    assert len(result) == 3103    assert list(result[0].keys()) == list(result[0].values())104    assert list(result[1].keys()) == list(result[1].values())105    assert list(result[2].keys()) == list(result[2].values())106def test_deep_tree_functions_of_producers(app):107    t = GlobalTestData()108    @app.consumer()109    def save_globaly(name, result , **kwargs):110        t.save_multiple_items(**{name: result})111    @app.pipeline()112    def p_builder(worker, sentence):113        root_branch = sentence \114            .subscribe_func_as_producer(lambda sentence: [dict(func1="ok"),115                                                         dict(func1="ok"), ],116                                     name='root1') \117            .subscribe_func_as_producer(lambda sentence: [dict(func2="ok"),118                                                          dict(func2="ok"), ],119                                     name='root2')120        return concatenate(121            branch_1=root_branch.subscribe_pipeline(branch_1),122            branch_2=root_branch.subscribe_pipeline(branch_2),123            branch_3=root_branch.subscribe_pipeline(branch_3)124        )125    @app.pipeline()126    def branch_1(work, func1, func2):127        root_branch = concatenate(func1=func1, func2=func2)128        return root_branch \129            .add_value(name='branch_1') \130            .subscribe_func(lambda func1, func2: dict(func1_1="ok"),131                            name='branch_1_1') \132            .subscribe_func(lambda func1, func2: dict(result="branch_1"),133                            name='branch_1_2')\134            .subscribe_consumer(save_globaly)135    @app.pipeline()136    def branch_2(work, func1, func2):137        root_branch = concatenate(func1=func1, func2=func2)138        return root_branch \139            .add_value(name='branch_2') \140            .subscribe_func(lambda func1, func2: dict(func1_1="ok"),141                            name='branch_2_1') \142            .subscribe_func(lambda func1, func2: dict(result="branch_2"),143                            name='branch_2_2')\144            .subscribe_consumer(save_globaly)145    @app.pipeline()146    def branch_3(work, func1, func2):147        root_branch = concatenate(func1=func1, func2=func2)148        return root_branch \149            .add_value(name='branch_3') \150            .subscribe_func(lambda func1, func2: dict(func1_1="ok"),151                            name='branch_3_1') \152            .subscribe_func(lambda func1, func2: dict(result="branch_3"),153                            name='branch_3_2')\154            .subscribe_consumer(save_globaly)155    p_builder.compile()156    branch_1.compile()157    branch_2.compile()158    branch_3.compile()159    p_builder(sentence="Oleg", use_lower=True)160    run_pipelines(app)161    result = t.get_result()...scopes_test.py
Source:scopes_test.py  
...21@scopes.add_arg_scope22def func1(*args, **kwargs):23  return (args, kwargs)24@scopes.add_arg_scope25def func2(*args, **kwargs):26  return (args, kwargs)27class ArgScopeTest(tf.test.TestCase):28  def testEmptyArgScope(self):29    with self.test_session():30      self.assertEqual(scopes._current_arg_scope(), {})31  def testCurrentArgScope(self):32    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}33    key_op = (func1.__module__, func1.__name__)34    current_scope = {key_op: func1_kwargs.copy()}35    with self.test_session():36      with scopes.arg_scope([func1], a=1, b=None, c=[1]) as scope:37        self.assertDictEqual(scope, current_scope)38  def testCurrentArgScopeNested(self):39    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}40    func2_kwargs = {'b': 2, 'd': [2]}41    key = lambda f: (f.__module__, f.__name__)42    current_scope = {key(func1): func1_kwargs.copy(),43                     key(func2): func2_kwargs.copy()}44    with self.test_session():45      with scopes.arg_scope([func1], a=1, b=None, c=[1]):46        with scopes.arg_scope([func2], b=2, d=[2]) as scope:47          self.assertDictEqual(scope, current_scope)48  def testReuseArgScope(self):49    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}50    key_op = (func1.__module__, func1.__name__)51    current_scope = {key_op: func1_kwargs.copy()}52    with self.test_session():53      with scopes.arg_scope([func1], a=1, b=None, c=[1]) as scope1:54        pass55      with scopes.arg_scope(scope1) as scope:56        self.assertDictEqual(scope, current_scope)57  def testReuseArgScopeNested(self):58    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}59    func2_kwargs = {'b': 2, 'd': [2]}60    key = lambda f: (f.__module__, f.__name__)61    current_scope1 = {key(func1): func1_kwargs.copy()}62    current_scope2 = {key(func1): func1_kwargs.copy(),63                      key(func2): func2_kwargs.copy()}64    with self.test_session():65      with scopes.arg_scope([func1], a=1, b=None, c=[1]) as scope1:66        with scopes.arg_scope([func2], b=2, d=[2]) as scope2:67          pass68      with scopes.arg_scope(scope1):69        self.assertDictEqual(scopes._current_arg_scope(), current_scope1)70      with scopes.arg_scope(scope2):71        self.assertDictEqual(scopes._current_arg_scope(), current_scope2)72  def testSimpleArgScope(self):73    func1_args = (0,)74    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}75    with self.test_session():76      with scopes.arg_scope([func1], a=1, b=None, c=[1]):77        args, kwargs = func1(0)78        self.assertTupleEqual(args, func1_args)79        self.assertDictEqual(kwargs, func1_kwargs)80  def testSimpleArgScopeWithTuple(self):81    func1_args = (0,)82    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}83    with self.test_session():84      with scopes.arg_scope((func1,), a=1, b=None, c=[1]):85        args, kwargs = func1(0)86        self.assertTupleEqual(args, func1_args)87        self.assertDictEqual(kwargs, func1_kwargs)88  def testOverwriteArgScope(self):89    func1_args = (0,)90    func1_kwargs = {'a': 1, 'b': 2, 'c': [1]}91    with scopes.arg_scope([func1], a=1, b=None, c=[1]):92      args, kwargs = func1(0, b=2)93      self.assertTupleEqual(args, func1_args)94      self.assertDictEqual(kwargs, func1_kwargs)95  def testNestedArgScope(self):96    func1_args = (0,)97    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}98    with scopes.arg_scope([func1], a=1, b=None, c=[1]):99      args, kwargs = func1(0)100      self.assertTupleEqual(args, func1_args)101      self.assertDictEqual(kwargs, func1_kwargs)102      func1_kwargs['b'] = 2103      with scopes.arg_scope([func1], b=2):104        args, kwargs = func1(0)105        self.assertTupleEqual(args, func1_args)106        self.assertDictEqual(kwargs, func1_kwargs)107  def testSharedArgScope(self):108    func1_args = (0,)109    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}110    with scopes.arg_scope([func1, func2], a=1, b=None, c=[1]):111      args, kwargs = func1(0)112      self.assertTupleEqual(args, func1_args)113      self.assertDictEqual(kwargs, func1_kwargs)114      args, kwargs = func2(0)115      self.assertTupleEqual(args, func1_args)116      self.assertDictEqual(kwargs, func1_kwargs)117  def testSharedArgScopeTuple(self):118    func1_args = (0,)119    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}120    with scopes.arg_scope((func1, func2), a=1, b=None, c=[1]):121      args, kwargs = func1(0)122      self.assertTupleEqual(args, func1_args)123      self.assertDictEqual(kwargs, func1_kwargs)124      args, kwargs = func2(0)125      self.assertTupleEqual(args, func1_args)126      self.assertDictEqual(kwargs, func1_kwargs)127  def testPartiallySharedArgScope(self):128    func1_args = (0,)129    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}130    func2_args = (1,)131    func2_kwargs = {'a': 1, 'b': None, 'd': [2]}132    with scopes.arg_scope([func1, func2], a=1, b=None):133      with scopes.arg_scope([func1], c=[1]), scopes.arg_scope([func2], d=[2]):134        args, kwargs = func1(0)135        self.assertTupleEqual(args, func1_args)136        self.assertDictEqual(kwargs, func1_kwargs)137        args, kwargs = func2(1)138        self.assertTupleEqual(args, func2_args)139        self.assertDictEqual(kwargs, func2_kwargs)140if __name__ == '__main__':...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!!
