Best Python code snippet using yandex-tank
decorator-tests.js
Source:decorator-tests.js
1module('Decorators');2var Utils = require('select2/utils');3test('overridden - method', function (assert) {4 function BaseClass () {}5 BaseClass.prototype.hello = function () {6 return 'A';7 };8 function DecoratorClass () {}9 DecoratorClass.prototype.hello = function () {10 return 'B';11 };12 var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);13 var inst = new DecoratedClass();14 assert.strictEqual(inst.hello(), 'B');15});16test('overridden - constructor', function (assert) {17 function BaseClass () {18 this.inherited = true;19 }20 BaseClass.prototype.hello = function () {21 return 'A';22 };23 function DecoratorClass (decorated) {24 this.called = true;25 }26 DecoratorClass.prototype.other = function () {27 return 'B';28 };29 var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);30 var inst = new DecoratedClass();31 assert.ok(inst.called);32 assert.ok(!inst.inherited);33});34test('not overridden - method', function (assert) {35 function BaseClass () {}36 BaseClass.prototype.hello = function () {37 return 'A';38 };39 function DecoratorClass () {}40 DecoratorClass.prototype.other = function () {41 return 'B';42 };43 var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);44 var inst = new DecoratedClass();45 assert.strictEqual(inst.hello(), 'A');46});47test('not overridden - constructor', function (assert) {48 function BaseClass () {49 this.called = true;50 }51 BaseClass.prototype.hello = function () {52 return 'A';53 };54 function DecoratorClass () {}55 DecoratorClass.prototype.other = function () {56 return 'B';57 };58 var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);59 var inst = new DecoratedClass();60 assert.ok(inst.called);61});62test('inherited - method', function (assert) {63 function BaseClass () {}64 BaseClass.prototype.hello = function () {65 return 'A';66 };67 function DecoratorClass (decorated) {}68 DecoratorClass.prototype.hello = function (decorated) {69 return 'B' + decorated.call(this) + 'C';70 };71 var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);72 var inst = new DecoratedClass();73 assert.strictEqual(inst.hello(), 'BAC');74});75test('inherited - constructor', function (assert) {76 function BaseClass () {77 this.inherited = true;78 }79 BaseClass.prototype.hello = function () {80 return 'A';81 };82 function DecoratorClass (decorated) {83 this.called = true;84 decorated.call(this);85 }86 DecoratorClass.prototype.other = function () {87 return 'B';88 };89 var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);90 var inst = new DecoratedClass();91 assert.ok(inst.called);92 assert.ok(inst.inherited);93});94test('inherited - three levels', function (assert) {95 function BaseClass (testArgument) {96 this.baseCalled = true;97 this.baseTestArgument = testArgument;98 }99 BaseClass.prototype.test = function (a) {100 return a + 'c';101 };102 function MiddleClass (decorated, testArgument) {103 this.middleCalled = true;104 this.middleTestArgument = testArgument;105 decorated.call(this, testArgument);106 }107 MiddleClass.prototype.test = function (decorated, a) {108 return decorated.call(this, a + 'b');109 };110 function DecoratorClass (decorated, testArgument) {111 this.decoratorCalled = true;112 this.decoratorTestArgument = testArgument;113 decorated.call(this, testArgument);114 }115 DecoratorClass.prototype.test = function (decorated, a) {116 return decorated.call(this, a + 'a');117 };118 var DecoratedClass = Utils.Decorate(119 Utils.Decorate(BaseClass, MiddleClass),120 DecoratorClass121 );122 var inst = new DecoratedClass('test');123 assert.ok(inst.baseCalled, 'The base class contructor was called');124 assert.ok(inst.middleCalled, 'The middle class constructor was called');125 assert.ok(inst.decoratorCalled, 'The decorator constructor was called');126 assert.strictEqual(inst.baseTestArgument, 'test');127 assert.strictEqual(inst.middleTestArgument, 'test');128 assert.strictEqual(inst.decoratorTestArgument, 'test');129 var out = inst.test('test');130 assert.strictEqual(out, 'testabc');...
tests.py
Source:tests.py
...6from django.views.decorators.vary import vary_on_headers, vary_on_cookie7from django.views.decorators.cache import cache_page, never_cache, cache_control8from django.contrib.auth.decorators import login_required, permission_required, user_passes_test9from django.contrib.admin.views.decorators import staff_member_required10def fully_decorated(request):11 """Expected __doc__"""12 return HttpResponse('<html><body>dummy</body></html>')13fully_decorated.anything = "Expected __dict__"14# django.views.decorators.http15fully_decorated = require_http_methods(["GET"])(fully_decorated)16fully_decorated = require_GET(fully_decorated)17fully_decorated = require_POST(fully_decorated)18# django.views.decorators.vary19fully_decorated = vary_on_headers('Accept-language')(fully_decorated)20fully_decorated = vary_on_cookie(fully_decorated)21# django.views.decorators.cache22fully_decorated = cache_page(60*15)(fully_decorated)23fully_decorated = cache_control(private=True)(fully_decorated)24fully_decorated = never_cache(fully_decorated)...
08_two_nested_decorators_name_problem.py
Source:08_two_nested_decorators_name_problem.py
1from functools import wraps2print(80*'-')3def hello_decorator(decorated_func):4 print('WewnÄ
trz dekoratora hello_decorator')5 print('dekorowana funkcja {}'.format(decorated_func.__name__))6 7 def wrapper(*args, **kwargs):8 print('MowiÄ Ci hello')9 return decorated_func(*args, **kwargs)10 11 print('hello_decorator przed wrapper.__name__ = {}, decorated_func.__name__ = {}'.format(wrapper.__name__, decorated_func.__name__))12 wrapper.__name__ = decorated_func.__name__13 print('hello_decorator po wrapper.__name__ = {}, decorated_func.__name__ = {}'.format(wrapper.__name__, decorated_func.__name__))14 15 return wrapper # zwracamy funckcjÄ wewnÄtrznÄ
16print(80*'-')17def goodbye_decorator(decorated_func):18 print('WewnÄ
trz dekoratora goodbye_decorator')19 print('dekorowana funkcja {}'.format(decorated_func.__name__))20 21 def wrapper(*args, **kwargs):22 tmp = decorated_func(*args, **kwargs)23 print('a potem goodbye')24 return tmp25 26 print('goodbye_decorator przed wrapper.__name__ = {}, decorated_func.__name__ = {}'.format(wrapper.__name__, decorated_func.__name__))27 wrapper.__name__ = decorated_func.__name__28 print('goodbye_decorator po wrapper.__name__ = {}, decorated_func.__name__ = {}'.format(wrapper.__name__, decorated_func.__name__))29 30 return wrapper # zwracamy funckcjÄ wewnÄtrznÄ
31print(80*'-')32@hello_decorator33@goodbye_decorator34def next_collatz(val):35 if not val % 2:36 n_val = int(val/2)37 else:38 n_val = 3 * val + 139 print('{} -> {}'.format(val, n_val))40 return n_val41# poprawny42#next_collatz = hello_decorator(goodbye_decorator(next_collatz))43# bÅÄdny44#next_collatz = goodbye_decorator(hello_decorator(next_collatz))45 46print(80*'-')47a = next_collatz(2)48print(a)49print(80*'-')50print(next_collatz.__name__)...
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!!