How to use test_func method in wpt

Best JavaScript code snippet using wpt

test_api.js

Source:test_api.js Github

copy

Full Screen

1// Create a new YUI instance and populate it with the required modules.2YUI.add('bookie-test-api', function (Y) {3 var ns = Y.namespace('bookie.test.api');4 ns.suite = new Y.Test.Suite('Account API Tests');5 var gen_fakeio = function (test_function) {6 return function (url, cfg) {7 test_function(url, cfg);8 };9 };10 ns.suite.add(new Y.Test.Case({11 name: "API Tests",12 setUp: function () {13 },14 testApiExists: function () {15 Y.Assert.isObject(Y.bookie.Api,16 "Should find an object for Api module");17 },18 testPublicBmarkList: function () {19 var that = this,20 hit = false,21 test_func = function (url, cfg) {22 Y.Assert.areEqual('GET', cfg.method);23 Y.Assert.areEqual('http://127.0.0.1:6543/api/v1/bmarks',24 url);25 Y.ObjectAssert.areEqual({26 count: 10,27 page: 0,28 resource: undefined,29 username: "",30 with_content: false31 }, cfg.data);32 hit = true;33 },34 API_CFG = {35 url: 'http://127.0.0.1:6543/api/v1'36 },37 api = new Y.bookie.Api.route.BmarksAll(API_CFG);38 Y.io = gen_fakeio(test_func);39 api.call({});40 Y.Assert.isTrue(hit);41 },42 testPublicSearch: function () {43 var that = this,44 hit = false,45 test_func = function (url, cfg) {46 Y.Assert.areEqual('GET', cfg.method);47 Y.Assert.areEqual(48 'http://127.0.0.1:6543/api/v1/bmarks/search',49 url);50 Y.ObjectAssert.areEqual({51 count: 10,52 page: 0,53 resource: undefined,54 username: "",55 with_content: true56 }, cfg.data);57 hit = true;58 },59 API_CFG = {60 url: 'http://127.0.0.1:6543/api/v1'61 },62 api = new Y.bookie.Api.route.Search(API_CFG);63 Y.io = gen_fakeio(test_func);64 api.call({});65 Y.Assert.isTrue(hit);66 },67 testPublicSearchTerms: function () {68 var that = this,69 hit = false,70 test_func = function (url, cfg) {71 Y.Assert.areEqual('GET', cfg.method);72 Y.Assert.areEqual(73 'http://127.0.0.1:6543/api/v1/bmarks/search/books',74 url);75 Y.ObjectAssert.areEqual({76 count: 10,77 page: 0,78 resource: undefined,79 username: "",80 with_content: true81 }, cfg.data);82 hit = true;83 },84 API_CFG = {85 url: 'http://127.0.0.1:6543/api/v1'86 },87 api = new Y.bookie.Api.route.Search(Y.merge(API_CFG, {88 phrase: ['books']89 }));90 Y.io = gen_fakeio(test_func);91 api.call({});92 Y.Assert.isTrue(hit);93 },94 testUserPublicSearchTerms: function () {95 var that = this,96 hit = false,97 test_func = function (url, cfg) {98 Y.Assert.areEqual('GET', cfg.method);99 Y.Assert.areEqual(100 'http://127.0.0.1:6543/api/v1/admin/bmarks/search/books',101 url);102 Y.ObjectAssert.areEqual({103 count: 10,104 page: 0,105 resource: undefined,106 username: "admin",107 with_content: true108 }, cfg.data);109 hit = true;110 },111 API_CFG = {112 url: 'http://127.0.0.1:6543/api/v1'113 },114 api = new Y.bookie.Api.route.UserSearch(Y.merge(API_CFG, {115 phrase: ['books'],116 username: 'admin'117 }));118 Y.io = gen_fakeio(test_func);119 api.call({});120 Y.Assert.isTrue(hit);121 },122 testFilteredPublicBmarkList: function () {123 var that = this,124 hit = false,125 test_func = function (url, cfg) {126 Y.Assert.areEqual('GET', cfg.method);127 Y.Assert.areEqual(128 'http://127.0.0.1:6543/api/v1/bmarks/books',129 url);130 Y.ObjectAssert.areEqual(cfg.data, {131 count: 10,132 page: 0,133 resource: undefined,134 username: "",135 with_content: false136 });137 hit = true;138 },139 API_CFG = {140 url: 'http://127.0.0.1:6543/api/v1',141 tags: ['books']142 },143 api = new Y.bookie.Api.route.BmarksAll(API_CFG);144 Y.io = gen_fakeio(test_func);145 api.call({});146 Y.Assert.isTrue(hit);147 },148 testUserBmarkList: function () {149 var that = this,150 hit = false,151 test_func = function (url, cfg) {152 Y.Assert.areEqual('GET', cfg.method);153 Y.Assert.areEqual(154 'http://127.0.0.1:6543/api/v1/admin/bmarks',155 url);156 Y.ObjectAssert.areEqual(cfg.data, {157 api_key: '2dcf75460cb5',158 resource: "admin",159 username: "admin"160 });161 hit = true;162 },163 API_CFG = {164 url: 'http://127.0.0.1:6543/api/v1',165 username: 'admin',166 resource: 'admin',167 api_key: '2dcf75460cb5'168 },169 api = new Y.bookie.Api.route.UserBmarksAll(API_CFG);170 Y.io = gen_fakeio(test_func);171 api.call({});172 Y.Assert.isTrue(hit);173 },174 testTagComplete: function () {175 var that = this,176 hit = false,177 test_func = function (url, cfg) {178 Y.Assert.areEqual('GET', cfg.method);179 Y.Assert.areEqual(180 'http://127.0.0.1:6543/api/v1/admin/tags/complete',181 url);182 Y.ObjectAssert.areEqual(cfg.data, {183 api_key: '2dcf75460cb5',184 current: '',185 resource: undefined,186 tag: 'boo',187 username: "admin"188 });189 hit = true;190 },191 API_CFG = {192 url: 'http://127.0.0.1:6543/api/v1',193 username: 'admin',194 api_key: '2dcf75460cb5'195 },196 api = new Y.bookie.Api.route.TagComplete(API_CFG);197 Y.io = gen_fakeio(test_func);198 api.call({}, 'boo', '');199 Y.Assert.isTrue(hit);200 },201 testGetUserBmark: function () {202 var that = this,203 hit = false,204 test_func = function (url, cfg) {205 Y.Assert.areEqual('GET', cfg.method);206 Y.Assert.areEqual(207 'http://127.0.0.1:6543/api/v1/admin/bmark/b1210b874f52a1',208 url);209 Y.ObjectAssert.areEqual(cfg.data, {210 api_key: '2dcf75460cb5',211 hash_id: 'b1210b874f52a1',212 last_bmark: false,213 username: "admin"214 });215 hit = true;216 },217 API_CFG = {218 url: 'http://127.0.0.1:6543/api/v1',219 hash_id: 'b1210b874f52a1',220 username: 'admin'221 },222 api = new Y.bookie.Api.route.Bmark(API_CFG);223 Y.io = gen_fakeio(test_func);224 api.call({}, 'boo', '');225 Y.Assert.isTrue(hit);226 },227 testApiKey: function () {228 var that = this,229 hit = false,230 test_func = function (url, cfg) {231 Y.Assert.areEqual('GET', cfg.method);232 Y.Assert.areEqual(233 'http://127.0.0.1:6543/api/v1/admin/api_key',234 url);235 Y.ObjectAssert.areEqual({236 username: "admin",237 api_key: "7745ac02c6dc",238 resource: undefined239 }, cfg.data);240 hit = true;241 },242 API_CFG = {243 url: 'http://127.0.0.1:6543/api/v1',244 username: 'admin',245 api_key: '7745ac02c6dc'246 },247 api = new Y.bookie.Api.route.UserApiKey(API_CFG);248 Y.io = gen_fakeio(test_func);249 api.call({});250 Y.Assert.isTrue(hit);251 },252 testApiPing: function () {253 var that = this,254 hit = false,255 test_func = function (url, cfg) {256 Y.Assert.areEqual('GET', cfg.method);257 Y.Assert.areEqual(258 'http://127.0.0.1:6543/api/v1/admin/ping',259 url);260 Y.ObjectAssert.areEqual({261 api_key: "7745ac02c6dc",262 resource: undefined,263 username: "admin"264 }, cfg.data);265 hit = true;266 },267 API_CFG = {268 url: 'http://127.0.0.1:6543/api/v1',269 username: 'admin',270 api_key: '7745ac02c6dc'271 },272 api = new Y.bookie.Api.route.Ping(API_CFG);273 Y.io = gen_fakeio(test_func);274 api.call({});275 Y.Assert.isTrue(hit);276 },277 testDeleteBmark: function () {278 var that = this,279 hit = false,280 test_func = function (url, cfg) {281 Y.Assert.areEqual('DELETE', cfg.method);282 Y.Assert.areEqual(283 'http://127.0.0.1:6543/api/v1/admin/bmark/6c4370829d7ebc',284 url);285 Y.ObjectAssert.areEqual({286 api_key: "2dcf75460cb5",287 hash_id: "6c4370829d7ebc",288 resource: undefined,289 username: "admin"290 }, cfg.data);291 hit = true;292 },293 API_CFG = {294 url: 'http://127.0.0.1:6543/api/v1',295 username: 'admin',296 api_key: '2dcf75460cb5',297 hash_id: '6c4370829d7ebc'298 },299 api = new Y.bookie.Api.route.UserBmarkDelete(API_CFG);300 Y.io = gen_fakeio(test_func);301 api.call({});302 Y.Assert.isTrue(hit);303 },304 testUnSuspendUser: function () {305 var that = this,306 hit = false,307 test_func = function (url, cfg) {308 Y.Assert.areEqual('DELETE', cfg.method);309 Y.Assert.areEqual(310 'http://127.0.0.1:6543/api/v1/suspend',311 url);312 Y.ObjectAssert.areEqual({313 username: 'admin',314 password: 'test',315 code: '123456',316 resource: undefined317 }, cfg.data);318 hit = true;319 },320 API_CFG = {321 url: 'http://127.0.0.1:6543/api/v1',322 username: 'admin',323 code: '123456',324 password: 'test'325 },326 api = new Y.bookie.Api.route.UnSuspendUser(API_CFG);327 Y.io = gen_fakeio(test_func);328 api.call({});329 Y.Assert.isTrue(hit);330 },331 testInviteUser: function () {332 var that = this,333 hit = false,334 test_func = function (url, cfg) {335 Y.Assert.areEqual('POST', cfg.method);336 Y.Assert.areEqual(337 'http://127.0.0.1:6543/api/v1/admin/invite',338 url);339 // in post requests, the data is json-stringified so we340 // have to compare strings341 Y.Assert.areEqual(342 Y.JSON.stringify({343 email: 'testing@me.com',344 username: 'admin'345 }), cfg.data);346 hit = true;347 },348 API_CFG = {349 url: 'http://127.0.0.1:6543/api/v1',350 username: 'admin',351 email: 'testing@me.com'352 },353 api = new Y.bookie.Api.route.Invite(API_CFG);354 Y.io = gen_fakeio(test_func);355 api.call({});356 Y.Assert.isTrue(hit);357 },358 testUserBmarkCount: function() {359 var that = this,360 hit = false,361 test_func = function(url, cfg) {362 Y.Assert.areEqual('POST', cfg.method);363 Y.Assert.areEqual(364 'http://127.0.0.1:6543/api/v1/admin/stats/bmarkcount',365 url);366 Y.Assert.areEqual(367 Y.JSON.stringify({368 api_key: '2dcf75460cb5',369 username: 'admin'370 }), cfg.data);371 hit = true;372 },373 API_CFG = {374 url: 'http://127.0.0.1:6543/api/v1',375 username: 'admin',376 api_key: '2dcf75460cb5'377 },378 api = new Y.bookie.Api.route.UserBmarkCount(API_CFG);379 Y.io = gen_fakeio(test_func);380 api.call({});381 Y.Assert.isTrue(hit);382 }383 }));384}, '0.4', {385 requires: [386 'test', 'bookie-api'387 ]...

Full Screen

Full Screen

test_ode_coder.py

Source:test_ode_coder.py Github

copy

Full Screen

...30 code = odc.make_def(name, *args)31 test_func = f'{code}\n\treturn [a, b]'32 exec(test_func)33 a, b = 1, 234 assert test_func(a, b) == [1, 2]35 36 #Test code generation for local functions37 code = odc.funcs2code(funcs)38 test_func = f'def test_func(v, x, k):\n{code}\n\treturn MM(v, x, k)'39 exec(test_func)40 assert test_func(2, 4, 6) == 0.841 42 #Test local variable43 code = odc.vrbs2code(vrbs)44 test_func = f'def test_func(x2, k1):\n{code}\n\treturn sat2'45 exec(test_func)46 assert test_func(1, 1) == 0.547 48 #Parse single reaction49 stripper = lambda *s: ''.join(s).replace(' ', '').strip()50 r = odc._parse_rxn(*rxns['r0'])51 52 assert {'x0': '-1', 'x1': '-2', 'x2': '+1'} == r[0]53 assert stripper(rxns['r0'][1], '-', rxns['r0'][2]) == stripper(r[1])54 55 r = odc._parse_rxn(*rxns['r1'])56 57 assert {'x2': '-1', 'x3': '+1'} == r[0]58 assert stripper(rxns['r1'][1]) == stripper(r[1])59 60 r = odc._parse_rxn(*rxns['r2'])61 62 assert {'x3': '-1'} == r[0]63 assert stripper(rxns['r2'][1]) == stripper(r[1])64 65 #Test code generation for multiple reactions66 code = odc.rxns2code(model_data0)67 68 MM = lambda v, x, k: 069 sat2 = 0.570 test_func = f'def test_func(x0, x1, x2, x3, x4, p0, p1, p2, p3, p4):\n{code}\treturn [d_x0, d_x1, d_x2, d_x3, d_x4]'71 exec(test_func)72 r = test_func(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)73 assert r == [-1.0, -2.0, 0.5, -0.5, 1]74 75 #Test code generation for hierarchical models76 #We need to create the "submodel"77 MM = lambda v, x, k: 078 code = odc.rxns2code(model_data1)79 test_func0 = 'def model_M2(*args): return np.array([1, 1])'80 exec(test_func0)81 82 code = odc.rxns2code(model_data2)83 test_func = f'def test_func(t, x0, x1, x2, x3, p0, p1, p2, p3, k2):\n{code}\treturn [d_x0, d_x1, d_x2, d_x3]'84 exec(test_func)85 r = test_func(0, 1, 1, 1, 1, 1, 1, 1, 1, 1)86 assert r == [-1, 2, 1, 1]87 88 temp = dun_data1['M3']['rxns']['r1']89 dun_data1['M3']['rxns']['r1'] = {'submodel': 'M2', 90 'substates': {'xx0': 'x1', 'xx1': 'x2'}, 91 'subparams': {'pp0' : 'p0', 'pp1' : 'p1', 'kk1': 'k2'}92 }93 94 try:95 code = odc.rxns2code(model_data2)96 except NotImplementedError as e:97 assert True98 else:99 assert False100 dun_data1['M3']['rxns']['r1'] = temp101 102 ###############################################################################103 #Part 2: High Level Code Generation104 ###############################################################################105 template0 = odc.make_template(model_data0)106 template1 = odc.make_template(model_data1)107 template2 = odc.make_template(model_data2)108 109 params = model_data0['params']110 exvs = model_data0['exvs']111 events = model_data0['events'] 112 modify = model_data0['modify'] 113 114 #Generate code for ode rhs115 code = odc.rhs2code(template0, model_data0)[1]116 test_func = code.replace('model_M1', 'test_func')117 exec(test_func)118 t = 0 119 y = np.ones(5)120 p = pd.DataFrame(params).values[0]121 dy = test_func(t, y, p)122 assert all( dy == np.array([-0.5, -1, 0, -1.5 , 2]) )123 124 #Generate code for sim125 code = odc.sim2code(template0, model_data0)[1]126 test_func = code.replace('sim_M1', 'test_func')127 exec(test_func)128 t = np.array([0, 1])129 y = np.ones((5, 2))130 p = pd.DataFrame(params).values[0]131 r = test_func(t, y, p)132 133 answer = {'x0' : np.array([1., 1.]), 'x1' : np.array([1., 1.]), 134 'x2' : np.array([1., 1.]), 'x3' : np.array([1., 1.]), 135 'x4' : np.array([1., 1.]), 'sat2': np.array([0.5, 0.5]), 136 'd_x0': np.array([-0.5, -0.5]), 'd_x1': np.array([-1., -1.]), 137 'd_x2': np.array([0., 0.]), 'd_x3': np.array([-1.5, -1.5]), 138 'd_x4': np.array([2., 2.]), 't' : np.array([0, 1])139 }140 for k, v in answer.items():141 assert np.all(v == r[k])142 143 #Generate code for exv 144 codes = odc.exvs2code(template0, model_data0)145 test_func = codes['r0'][1].replace('exv_M1_r0', 'test_func')146 exec(test_func)147 t = np.array([0, 1])148 y = np.ones((5, 2))149 p = pd.DataFrame(params).values[0]150 r = test_func(t, y, p)151 assert all(r == 0.5)152 153 #Generate code for single event trigger154 trigger = events['e0'][0] 155 156 code = odc.trigger2code('e0', trigger, template0, model_data0)[1]157 test_func = code.replace('trigger_M1_e0', 'test_func')158 exec(test_func)159 t = 10160 y = np.array([0, 1, 1, 1, 1])161 p = pd.DataFrame(params).values[0]162 r = test_func(t, y, p)163 assert r == 0.5164 165 #Generate code for single event assignment166 assignment = events['e0'][1] 167 168 code = odc.assignment2code('e0', assignment, template0, model_data0)[1]169 test_func = code.replace('assignment_M1_e0', 'test_func')170 exec(test_func)171 t = 10172 y = np.array([0, 1, 1, 1, 1])173 p = pd.DataFrame(params).values[0]174 r = test_func(t, y, p)175 assert r[0][0] == 5176 assert r[1][0] == 0.5177 178 #Generate code for single event179 codes = odc.event2code('e0', template0, model_data0)180 181 test_func = codes['trigger'][1].replace('trigger_M1_e0', 'test_func')182 exec(test_func)183 t = 10184 y = np.array([0, 1, 1, 1, 1])185 p = pd.DataFrame(params).values[0]186 r = test_func(t, y, p)187 assert r == 0.5188 189 test_func = codes['assignment'][1].replace('assignment_M1_e0', 'test_func')190 exec(test_func)191 t = 10192 y = np.array([0, 1, 1, 1, 1])193 p = pd.DataFrame(params).values[0]194 r = test_func(t, y, p)195 assert r[0][0] == 5196 assert r[1][0] == 0.5197 198 #Generate code for all events199 codes = odc.events2code(template0, model_data0)200 201 test_func = codes['e0']['trigger'][1].replace('trigger_M1_e0', 'test_func')202 exec(test_func)203 t = 10204 y = np.array([0, 1, 1, 1, 1])205 p = pd.DataFrame(params).values[0]206 r = test_func(t, y, p)207 assert r == 0.5208 209 test_func = codes['e0']['assignment'][1].replace('assignment_M1_e0', 'test_func')210 exec(test_func)211 t = 10212 y = np.array([0, 1, 1, 1, 1])213 p = pd.DataFrame(params).values[0]214 r = test_func(t, y, p)215 assert r[0][0] == 5216 assert r[1][0] == 0.5217 218 #Generate modify 219 code = odc.modify2code(template0, model_data0)[1]220 test_func = code.replace('modify_M1', 'test_func')221 exec(test_func)222 t = 10223 y = np.array([0, 1, 1, 1, 1])224 p = pd.DataFrame(params).values[0]225 r = test_func(y, p, scenario=1)226 assert all( r[0] == np.array([10, 1, 1, 1, 1]) )227 assert all( r[1] == p)228 229 ###############################################################################230 #Part 3A: Function Generation231 ###############################################################################232 #Generate single function from code233 code = 'x = lambda t: t+1'234 scope = {}235 test_func = odc.code2func(['x', code])236 assert test_func(5) == 6237 238 #Generate multiple functions from codes239 #The second function requires access to the first one240 codes = {'fx': ['x', 'def x(t):\n\treturn t+1'], 241 'fy': ['y', 'def y(t):\n\treturn x(t)+2']242 }243 r = odc.code2func(codes)244 test_func = r['fx']245 assert test_func(5) == 6246 test_func = r['fy']247 assert test_func(5) == 8248 249 ###############################################################################250 #Part 3B: Function Generation251 ###############################################################################252 template0 = odc.make_template(model_data0)253 template1 = odc.make_template(model_data1)254 template2 = odc.make_template(model_data2)255 256 params = model_data0['params']257 exvs = model_data0['exvs']258 events = model_data0['events'] 259 modify = model_data0['modify'] 260 261 #Generate rhs function...

Full Screen

Full Screen

TestSmart.js

Source:TestSmart.js Github

copy

Full Screen

1const {2 BN, // Big Number support3 constants, // Common constants, like the zero address and largest integers4 expectEvent, // Assertions for emitted events5 expectRevert, // Assertions for transactions that should fail6} = require('@openzeppelin/test-helpers');7const EtherlessSmart = artifacts.require('EtherlessSmart');8const EtherlessStorage = artifacts.require('EtherlessStorage');9const EtherlessEscrow = artifacts.require('EtherlessEscrow');10contract('EtherlessSmart', (accounts) => {11 const [pippo, pluto] = accounts;12 let instance13 let storage14 beforeEach(async function setup() {15 instance = await EtherlessSmart.new();16 storage = await EtherlessStorage.new();17 await instance.initialize(storage.address, pippo, 10);18 });19 it('at start, list should be empty', async () => {20 const expected = "{\"functionArray\":[]}";21 const id = await instance.getId();22 const list = await instance.getFuncList();23 assert.equal(list, expected, 'list is not empty');24 });25 it('func should not exist', async () => {26 const fname = "test_func";27 const expected = false;28 const exists = await storage.existsFunction(fname);29 assert.equal(exists, expected, 'function exists');30 });31 it('should correctly send request to add a function', async () => {32 const expected = 10;33 const fname = "test_func";34 const receipt = await instance.deployFunction(fname, "sign", "description","hash", {from: pippo, value: 10});35 expectEvent(receipt, 'deployRequest', { funcname: fname, signature: "sign", funchash: "hash", id: new BN(1) });36 const deposit = await instance.getDeposit(1);37 assert.equal(deposit, expected, 'function was not added correctly');38 });39 it('should correctly send request to run a function', async () => {40 const expected = 8;41 const fname = "test_func";42 //mock deployed function43 await storage.insertNewFunction(fname, "sign", 10, pippo, "description", { from: pippo});44 await storage.insertInArray(fname,{ from: pippo});45 const receipt = await instance.runFunction(fname, "10,2", { from: pippo, value: 10 });46 const deposit = await instance.getDeposit(1);47 expectEvent(receipt, 'runRequest', { funcname: fname, param:"10,2", id: new BN(1) });48 assert.equal(deposit, expected, 'function was not run correctly');49 });50 it('should correctly send request to delete a function', async () => {51 const expected = 10;52 const fname = "test_func";53 //mock deployed function54 await storage.insertNewFunction(fname, "sign", 10, pippo, "description", { from: pippo });55 await storage.insertInArray(fname, { from: pippo });56 //const list = await instance.getFuncList();57 const receipt = await instance.deleteFunction(fname, { from: pippo, value: 10 });58 const deposit = await instance.getDeposit(1);59 expectEvent(receipt, 'deleteRequest', { funcname: fname, id: new BN(1) });60 assert.equal(deposit, expected, 'function was not deleted correctly');61 });62 it('should correctly send request to edit a function', async () => {63 const expected = 10;64 const fname = "test_func";65 const fsign = "test_sign";66 const fhash = "test_hash";67 //mock deployed function68 await storage.insertNewFunction(fname, "sign", 10, pippo, "description", { from: pippo });69 await storage.insertInArray(fname, { from: pippo });70 //const list = await instance.getFuncList();71 const receipt = await instance.editFunction(fname, fsign, fhash, { from: pippo, value: 10 });72 const deposit = await instance.getDeposit(1);73 expectEvent(receipt, 'editRequest', { name: fname, signature: fsign, funcHash: fhash, requestId: new BN(1) });74 assert.equal(deposit, expected, 'edit request was not sent correctly');75 });76 it('should limit the access to delete a function', async () => {77 const expected = 0;78 const fname = "test_func";79 //mock deployed function80 await storage.insertNewFunction(fname, "sign", 10, pippo, "description", { from: pippo });81 await storage.insertInArray(fname, { from: pippo });82 83 await expectRevert(84 instance.deleteFunction(fname, { from: pluto, value: 10 }),85 "You are not the owner of the function!",86 );87 const deposit = await instance.getDeposit(1);88 assert.equal(deposit, expected, 'function was not deleted correctly');89 });90 it('should limit the access to deployResult', async () => {91 const fname = "test_func";92 await expectRevert(93 instance.deployResult("deploy result message", fname, 1, true, { from: pluto }),94 "You are not the designated address!",95 );96 });97 it('should limit the access to runResult', async () => {98 const fname = "test_func";99 await expectRevert(100 instance.runResult("run result message", 1, true, { from: pluto }),101 "You are not the designated address!",102 );103 });104 it('should limit the access to deleteResult', async () => {105 const fname = "test_func";106 await expectRevert(107 instance.deleteResult("delete result message", fname, 1, true, { from: pluto }),108 "You are not the designated address!",109 );110 });111 it('should limit the access to editResult', async () => {112 const fname = "test_func";113 const fsign = "test_func_signature";114 await expectRevert(115 instance.editResult("edit result message", fname, fsign, 1, true, { from: pluto }),116 "You are not the designated address!",117 );118 });119 it('should emit the event for succesful runResult', async () => {120 const expected = true;121 const fname = "test_func";122 const receipt = await instance.runResult("success message", 1, true,{ from: pippo});123 expectEvent(receipt, 'resultOk', { result: "success message", id: new BN(1) });124 });125 it('should emit the event for succesful deployResult', async () => {126 const expected = true;127 const fname = "test_func";128 const expcInfo = "{\"name\":\"" + fname + "\",\"signature\":\"sign\",\"price\":\"10\",\"description\":\"desc\",\"developer\":\"" + pluto + "\"}"129 await instance.deployFunction(fname, "sign", "desc", "hash", { from: pluto, value: 10 });130 const receipt = await instance.deployResult("success message", fname, 1, true,{ from: pippo});131 const info = await instance.getInfo(fname);132 assert.equal(info, expcInfo.toLowerCase(), 'function was not deployed correctly');133 expectEvent(receipt, 'resultOk', { result: "success message", id: new BN(1) });134 });135 it('should emit the event for succesful editResult', async () => {136 const expected = true;137 const fname = "test_func";138 const sign = "func_sign";139 const receipt = await instance.editResult("success message", fname, sign, 1, true, { from: pippo });140 expectEvent(receipt, 'resultOk', { result: "success message", id: new BN(1) });141 });142 it('should emit the event for unsuccesful runResult', async () => {143 const expected = true;144 const fname = "test_func";145 //await instance.deployFunction(fname, "sign", "description", "hash", { from: pluto, value: 10 });146 const receipt = await instance.runResult("error message", 1, false,{ from: pippo});147 expectEvent(receipt, 'resultError', { result: "error message", id: new BN(1) });148 });149 it('should emit the event for unsuccesful deployResult', async () => {150 const expected = true;151 const fname = "test_func";152 //await instance.deployFunction(fname, "sign", "description", "hash", { from: pluto, value: 10 });153 const receipt = await instance.deployResult("error message", fname, 1, false,{ from: pippo});154 expectEvent(receipt, 'resultError', { result: "error message", id: new BN(1) });155 });156 it('should emit the event for unsuccesful editResult', async () => {157 const expected = true;158 const fname = "test_func";159 const sign = "func_sign";160 //await instance.deployFunction(fname, "sign", "description", "hash", { from: pluto, value: 10 });161 const receipt = await instance.editResult("error message", fname, sign, 1, false,{ from: pippo});162 expectEvent(receipt, 'resultError', { result: "error message", id: new BN(1) });163 });164 it('should correctly edit a function\'s description', async () => {165 const new_desc = "new function description";166 const fname = "test_func";167 const expected = "{\"name\":\"test_func\",\"signature\":\"sign\",\"price\":\"10\",\"description\":\"" + new_desc + "\",\"developer\":\"" + pippo + "\"}";168 //mock deployed function169 await storage.insertNewFunction(fname, "sign", 10, pippo, "description", { from: pippo });170 await storage.insertInArray(fname, { from: pippo });171 172 const receipt = await instance.editFunctionDescr(fname, new_desc, { from: pippo, value: 10 });173 const info = await instance.getInfo(fname);174 assert.equal(info, expected.toLocaleLowerCase(), 'function was not edited correctly');175 });176 it('should correctly emit edit request', async () => {177 const new_desc = "new function description";178 const fname = "test_func";179 const expected = "{\"name\":\"test_func\",\"signature\":\"sign\",\"price\":\"10\",\"description\":\"" + new_desc + "\",\"developer\":\"" + pippo + "\"}";180 //mock deployed function181 await storage.insertNewFunction(fname, "sign", 10, pippo, "description", { from: pippo });182 await storage.insertInArray(fname, { from: pippo });183 const receipt = await instance.editFunctionDescr(fname, new_desc, { from: pippo, value: 10 });184 const info = await instance.getInfo(fname);185 assert.equal(info, expected.toLocaleLowerCase(), 'function was not edited correctly');186 });187 it('should edit the function signature', async () => {188 const fname = "test_func";189 const newsign = "new sign";190 const expected = "{\"name\":\"test_func\",\"signature\":\"" + newsign + "\",\"price\":\"10\",\"description\":\"description\",\"developer\":\"" + pippo + "\"}";191 await storage.insertNewFunction(fname, "sign", 10, pippo, "description", { from: pippo });192 await storage.insertInArray(fname, { from: pippo });193 await instance.editResult("edit was successful", fname, newsign, 1, true, { from: pippo });194 const info = await storage.getFuncInfo(fname);195 assert.equal(info, expected.toLowerCase(), 'developer is not the expected address');196 });197 it('should return the function cost', async () => {198 const fname = "test_func";199 const newsign = "new sign";200 //const expected = "{\"name\":\"test_func\",\"signature\":\"sign\",\"price\":\"10\",\"description\":\"description\",\"developer\":\"" + pippo + "\"}";201 const expected = 10;202 await storage.insertNewFunction(fname, "sign", 10, pippo, "description", { from: pippo });203 await storage.insertInArray(fname, { from: pippo });204 const cost = await instance.getCost( fname, { from: pippo });205 assert.equal(cost, expected, 'developer is not the expected address');206 });207 208 it('should return the function info', async () => {209 const fname = "test_func";210 const expected = "{\"name\":\"" + fname + "\",\"signature\":\"sign\",\"price\":\"15\",\"description\":\"desc\",\"developer\":\"" + pippo + "\"}";211 await storage.insertNewFunction(fname, "sign", 15, pippo, "desc");212 await storage.insertInArray(fname);213 const cost = await instance.getInfo( fname, { from: pippo });214 assert.equal(cost, expected.toLowerCase(), 'the function info is not as expected');215 });...

Full Screen

Full Screen

util.ts

Source:util.ts Github

copy

Full Screen

...38 // if (syncMode) {39 // test_func = wrapAssert(test_func as AssertFuncSync)40 // }41 const repeatAsyncly = (resolve: Resolve, reject: Reject): void => {42 Promise.resolve(test_func())43 .then((result: any) => {44 if (!result) {45 resolve()46 return PROMISE_INTERRUPT47 }48 return iteratee()49 })50 .then((data: any) => {51 if (data !== PROMISE_INTERRUPT) {52 process.nextTick(() => repeatAsyncly(resolve, reject))53 }54 return PROMISE_END55 })56 .catch(reject)57 }58 return new Promise((resolve, reject) => {59 Promise.resolve(test_func())60 .then((result: any) => {61 if (!result) {62 // 第一次測試就不通過63 resolve(null)64 return PROMISE_INTERRUPT65 }66 return iteratee()67 })68 .then((data: any) => {69 if (data !== PROMISE_INTERRUPT) {70 repeatAsyncly(resolve, reject)71 }72 return PROMISE_END73 })74 .catch(reject)75 })76}77// 這個方式簡化了代碼,同時也迴避了stack overflow的問題,但是異常處理非常麻煩,需要try catch,因為https://eslint.org/docs/rules/no-async-promise-executor78export const whilst2 = (iteratee_func: AsyncFunc, test_func: AssertFunc): Promise<any> => {79 if (!test_func) {80 test_func = () => Promise.resolve(true)81 }82 // eslint-disable-next-line no-async-promise-executor83 return new Promise(async (resolve) => {84 while (await test_func()) {85 await iteratee_func()86 }87 return resolve(null)88 })89}90// iteratee test_func, 兩個參數的類型應該一致91export const until = (iteratee: AsyncFunc, test_func: Function): Promise<any> => {92 assertFunction(iteratee, `[kaze][until]: the first argument should be a function which return a promise`)93 assertFunction(test_func, `[kaze][until]: the second argument should be a function`)94 // const iteratee_func = ensureAsyncFunc(iteratee)95 // if (syncMode) {96 // test_func = wrapAssert(test_func as AssertFuncSync)97 // }98 const repeatAsyncly = (resolve: Resolve, reject: Reject): void => {99 iteratee()100 .then(() => {101 return test_func()102 })103 .then((result: any) => {104 if (result) {105 return resolve()106 }107 return process.nextTick(() => repeatAsyncly(resolve, reject))108 })109 .catch(reject)110 }111 return new Promise((resolve, reject) => {112 iteratee()113 .then(() => {114 return test_func()115 })116 .then((result: any) => {117 if (result) {118 // 第一次測試就滿足跳出的條件119 return resolve(null)120 }121 return repeatAsyncly(resolve, reject)122 })123 .catch(reject)124 })125}126// 不帶初始參數 timesSeries127export const repeat = (iteratee: AsyncFunc, times_n: number): Promise<any> => {128 assertFunction(iteratee, `[kaze][repeat]: the first argument should be a function which return a promise`)129 assertInteger(times_n, `[kaze][repeat]: the second argument should be an integer`)130 // const iteratee_func = ensureAsyncFunc(iteratee)131 const countable_func: AsyncFunc & { __times?: number } = wrapCountable(iteratee)132 const test_func = (): Promise<any> => {133 return new Promise((resolve) => {134 countable_func.__times = countable_func.__times || 0135 resolve(countable_func.__times < times_n) // 從0算起136 })137 }138 return whilst(countable_func, test_func)139}140// 不帶初始參數141export const forever = (iteratee: AsyncFunc): Promise<any> => {142 assertFunction(iteratee, `[kaze][forever]: the first argument should be a function which return a promise`)143 // const iteratee_func = ensureAsyncFunc(iteratee)144 const test_func = (): Promise<boolean> => Promise.resolve(true)145 return whilst(iteratee, test_func)146}147export const race = (arr: PromiseHood[]): Promise<any> => {148 assertPromiseHoodArray(arr, `[kaze][race]: the first argument should be an array of functions or promises`)149 return Promise.race(150 arr.map((item) => {151 const func = ensureAsyncFunc(item)152 return func()153 }),154 )155}156export const parallel = (arr: PromiseHood[]): Promise<any> => {157 assertPromiseHoodArray(arr, `[kaze][parallel]: the argument should be an array of functions or promises`)158 return Promise.all(159 arr.map((item) => {160 const func = ensureAsyncFunc(item)161 return func()162 }),163 )164}165// parallelLimit,既是同步,又是異步,不知返回什麼才好166export const parallelLimit = (arr: PromiseHood[], n: number): Promise<any> => {167 assertPromiseHoodArray(arr, `[kaze][parallelLimit]: the first argument should be an array of functions or promises`)168 assertInteger(n, `[kaze][parallelLimit]: the second argument should be an integer`)169 const runner = new Corunner(n)170 const func_arr = arr.map(item => ensureAsyncFunc(item))171 runner.push(func_arr)172 return runner.start()173}174// 內部函數,無需參數檢查,假定test_func永不出錯,邏輯因之更簡單175const whileas = (iteratee_func: AsyncFunc, test_func: Function): Promise<any> => {176 // assertFunction(iteratee_func, `[kaze][whileas]: the first argument should be a function`)177 // assertFunction(test_func, `[kaze][whileas]: the second argument should be a function`)178 // if (syncMode) {179 // test_func = wrapAssert(test_func as AssertFuncSync)180 // }181 const repeatAsyncly = (resolve: Resolve, reject: Reject): void => {182 Promise.resolve(test_func())183 .then((result: any) => {184 if (!result) {185 reject("數組為空、次數超限")186 return PROMISE_INTERRUPT187 }188 return iteratee_func()189 })190 .then((data: any) => {191 if (data !== PROMISE_INTERRUPT) {192 resolve(data)193 }194 return PROMISE_END195 })196 .catch(() => {197 process.nextTick(() => repeatAsyncly(resolve, reject))198 })199 }200 return new Promise((resolve, reject) => {201 Promise.resolve(test_func())202 .then((result: any) => {203 if (!result) {204 // 第一次測試就不通過205 reject(new Error("數組為空、次數超限"))206 return PROMISE_INTERRUPT207 }208 return iteratee_func()209 })210 .then((data: any) => {211 if (data !== PROMISE_INTERRUPT) {212 resolve(data)213 }214 return PROMISE_END215 })...

Full Screen

Full Screen

test_autoparams.py

Source:test_autoparams.py Github

copy

Full Screen

...5class C: pass6class TestInjectAutoparams(BaseTestInject):7 def test_autoparams_by_class(self):8 @inject.autoparams()9 def test_func(val: int = None):10 return val11 inject.configure(lambda binder: binder.bind(int, 123))12 assert test_func() == 12313 assert test_func(val=321) == 32114 def test_autoparams_multi(self):15 @inject.autoparams()16 def test_func(a: A, b: B, *, c: C):17 return a, b, c18 def config(binder):19 binder.bind(A, 1)20 binder.bind(B, 2)21 binder.bind(C, 3)22 inject.configure(config)23 assert test_func() == (1, 2, 3)24 assert test_func(10) == (10, 2, 3)25 assert test_func(10, 20) == (10, 20, 3)26 assert test_func(10, 20, c=30) == (10, 20, 30)27 assert test_func(a='a') == ('a', 2, 3)28 assert test_func(b='b') == (1, 'b', 3)29 assert test_func(c='c') == (1, 2, 'c')30 assert test_func(a=10, c=30) == (10, 2, 30)31 assert test_func(c=30, b=20, a=10) == (10, 20, 30)32 assert test_func(10, b=20) == (10, 20, 3)33 def test_autoparams_strings(self):34 @inject.autoparams()35 def test_func(a: 'A', b: 'B', *, c: 'C'):36 return a, b, c37 def config(binder):38 binder.bind(A, 1)39 binder.bind(B, 2)40 binder.bind(C, 3)41 inject.configure(config)42 assert test_func() == (1, 2, 3)43 assert test_func(10) == (10, 2, 3)44 assert test_func(10, 20) == (10, 20, 3)45 assert test_func(10, 20, c=30) == (10, 20, 30)46 assert test_func(a='a') == ('a', 2, 3)47 assert test_func(b='b') == (1, 'b', 3)48 assert test_func(c='c') == (1, 2, 'c')49 assert test_func(a=10, c=30) == (10, 2, 30)50 assert test_func(c=30, b=20, a=10) == (10, 20, 30)51 assert test_func(10, b=20) == (10, 20, 3)52 def test_autoparams_with_defaults(self):53 @inject.autoparams()54 def test_func(a=1, b: 'B' = None, *, c: 'C' = 300):55 return a, b, c56 def config(binder):57 binder.bind(B, 2)58 binder.bind(C, 3)59 inject.configure(config)60 assert test_func() == (1, 2, 3)61 assert test_func(10) == (10, 2, 3)62 assert test_func(10, 20) == (10, 20, 3)63 assert test_func(10, 20, c=30) == (10, 20, 30)64 assert test_func(a='a') == ('a', 2, 3)65 assert test_func(b='b') == (1, 'b', 3)66 assert test_func(c='c') == (1, 2, 'c')67 assert test_func(a=10, c=30) == (10, 2, 30)68 assert test_func(c=30, b=20, a=10) == (10, 20, 30)69 assert test_func(10, b=20) == (10, 20, 3)70 def test_autoparams_on_method(self):71 class Test:72 @inject.autoparams()73 def func(self, a=1, b: 'B' = None, *, c: 'C' = None):74 return self, a, b, c75 def config(binder):76 binder.bind(B, 2)77 binder.bind(C, 3)78 inject.configure(config)79 test = Test()80 assert test.func() == (test, 1, 2, 3)81 assert test.func(10) == (test, 10, 2, 3)82 assert test.func(10, 20) == (test, 10, 20, 3)83 assert test.func(10, 20, c=30) == (test, 10, 20, 30)84 assert test.func(a='a') == (test, 'a', 2, 3)85 assert test.func(b='b') == (test, 1, 'b', 3)86 assert test.func(c='c') == (test, 1, 2, 'c')87 assert test.func(a=10, c=30) == (test, 10, 2, 30)88 assert test.func(c=30, b=20, a=10) == (test, 10, 20, 30)89 assert test.func(10, b=20) == (test, 10, 20, 3)90 def test_autoparams_on_classmethod(self):91 class Test:92 # note inject must be *before* classmethod!93 @classmethod94 @inject.autoparams()95 def func(cls, a=1, b: 'B' = None, *, c: 'C' = None):96 return cls, a, b, c97 def config(binder):98 binder.bind(B, 2)99 binder.bind(C, 3)100 inject.configure(config)101 assert Test.func() == (Test, 1, 2, 3)102 assert Test.func(10) == (Test, 10, 2, 3)103 assert Test.func(10, 20) == (Test, 10, 20, 3)104 assert Test.func(10, 20, c=30) == (Test, 10, 20, 30)105 assert Test.func(a='a') == (Test, 'a', 2, 3)106 assert Test.func(b='b') == (Test, 1, 'b', 3)107 assert Test.func(c='c') == (Test, 1, 2, 'c')108 assert Test.func(a=10, c=30) == (Test, 10, 2, 30)109 assert Test.func(c=30, b=20, a=10) == (Test, 10, 20, 30)110 assert Test.func(10, b=20) == (Test, 10, 20, 3)111 def test_autoparams_on_classmethod_ob_object(self):112 class Test:113 # note inject must be *before* classmethod!114 @classmethod115 @inject.autoparams()116 def func(cls, a=1, b: 'B' = None, *, c: 'C' = None):117 return cls, a, b, c118 def config(binder):119 binder.bind(B, 2)120 binder.bind(C, 3)121 inject.configure(config)122 test = Test123 assert test.func() == (Test, 1, 2, 3)124 assert test.func(10) == (Test, 10, 2, 3)125 assert test.func(10, 20) == (Test, 10, 20, 3)126 assert test.func(10, 20, c=30) == (Test, 10, 20, 30)127 assert test.func(a='a') == (Test, 'a', 2, 3)128 assert test.func(b='b') == (Test, 1, 'b', 3)129 assert test.func(c='c') == (Test, 1, 2, 'c')130 assert test.func(a=10, c=30) == (Test, 10, 2, 30)131 assert test.func(c=30, b=20, a=10) == (Test, 10, 20, 30)132 assert test.func(10, b=20) == (Test, 10, 20, 3)133 def test_autoparams_only_selected(self):134 @inject.autoparams('a', 'c')135 def test_func(a: 'A', b: 'B', *, c: 'C'):136 return a, b, c137 def config(binder):138 binder.bind(A, 1)139 binder.bind(B, 2)140 binder.bind(C, 3)141 inject.configure(config)142 self.assertRaises(TypeError, test_func)143 self.assertRaises(TypeError, test_func, a=1, c=3)144 def test_autoparams_omits_return_type(self):145 @inject.autoparams()146 def test_func(a: str) -> int:147 return a148 def config(binder):149 binder.bind(str, 'bazinga')150 inject.configure(config)...

Full Screen

Full Screen

generic_utils_test.py

Source:generic_utils_test.py Github

copy

Full Screen

...70 'test_function_type',71 ('simple function', 'closured function'))72def test_func_dump_and_load(test_function_type):73 if test_function_type == 'simple function':74 def test_func():75 return r'\u'76 elif test_function_type == 'closured function':77 def get_test_func():78 x = r'\u'79 def test_func():80 return x81 return test_func82 test_func = get_test_func()83 else:84 raise Exception('Unknown test case for test_func_dump_and_load')85 serialized = func_dump(test_func)86 deserialized = func_load(serialized)87 assert deserialized.__code__ == test_func.__code__88 assert deserialized.__defaults__ == test_func.__defaults__89 assert deserialized.__closure__ == test_func.__closure__90def test_func_dump_and_load_closure():91 y = 092 test_func = lambda x: x + y93 serialized, _, closure = func_dump(test_func)94 deserialized = func_load(serialized, closure=closure)95 assert deserialized.__code__ == test_func.__code__96 assert deserialized.__defaults__ == test_func.__defaults__...

Full Screen

Full Screen

test_cache.py

Source:test_cache.py Github

copy

Full Screen

...34 self.patch.stop()35class TestCachedResult(BaseCacheCase):36 def test_default(self):37 @cached_result()38 def test_func():39 return datetime.datetime.utcnow().isoformat()40 v1 = test_func()41 v2 = test_func()42 self.assertEquals(v1, v2)43 def test_with_prefix(self):44 @cached_result(prefix='test_func')45 def test_func():46 return datetime.datetime.utcnow().isoformat()47 v1 = test_func()48 v2 = test_func()49 self.assertEquals(v1, v2)50 def test_timeout(self):51 @cached_result(timeout=1)52 def test_func():53 return datetime.datetime.utcnow().isoformat()54 v1 = test_func()55 time.sleep(2)56 v2 = test_func()57 self.assertNotEquals(v1, v2)58class TestClsCachedResult(BaseCacheCase):59 def test_default(self):60 class SillyTest:61 @cls_cached_result()62 def test_func(self, arg1, arg2):63 return datetime.datetime.utcnow().isoformat()64 obj = SillyTest()65 v1 = obj.test_func('arg1', 'arg2')66 v2 = obj.test_func('arg1', 'arg2')67 self.assertEquals(v1, v2)68 def test_with_prefix(self):69 class SillyTest:70 @cls_cached_result(prefix='test_func')71 def test_func(self, arg1, arg2):72 return datetime.datetime.utcnow().isoformat()73 obj = SillyTest()74 v1 = obj.test_func('arg1', 'arg2')75 v2 = obj.test_func('arg1', 'arg2')76 self.assertEquals(v1, v2)77 def test_timeout(self):78 class SillyTest:79 @cls_cached_result(timeout=1)80 def test_func(self, arg1, arg2):81 return datetime.datetime.utcnow().isoformat()82 obj = SillyTest()83 v1 = obj.test_func('arg1', 'arg2')84 time.sleep(2)85 v2 = obj.test_func('arg1', 'arg2')...

Full Screen

Full Screen

test_utils.py

Source:test_utils.py Github

copy

Full Screen

...12 obj = object()13 counter = 014 MAX_CACHE_SIZE = 215 @create_async_cache(MAX_CACHE_SIZE)16 async def test_func(param):17 nonlocal counter18 counter += 119 return param20 with self.subTest("Verify empty cache"):21 self.assertEqual(len(test_func.__cache__), 0)22 result = await test_func(obj)23 with self.subTest("Verify correct result"):24 self.assertIs(result, obj)25 with self.subTest("Verify cache size 1"):26 self.assertEqual(len(test_func.__cache__), 1)27 for i in range(3):28 with self.subTest("Verify counter", i=i):29 self.assertEqual(counter, 1)30 for i in range(2):31 await test_func(object())32 with self.subTest("Verify cache size 2", i=i):33 self.assertEqual(len(test_func.__cache__), 2)34 if i == 0:35 with self.subTest("Verify old cache exists", i=i):36 self.assertIn(obj, test_func.__cache__.values())37 elif i == 1:38 with self.subTest("Verify old cache gone", i=i):39 self.assertNotIn(obj, test_func.__cache__.values())40 with self.subTest("Verify counter"):41 self.assertEqual(counter, 3)42 async def test_clear_key(self):43 @create_async_cache(10)44 async def test_func(param):45 return param46 VAR_1 = 1.047 VAR_2 = "2"48 VAR_3 = 349 VAR_4 = object()50 await test_func(VAR_4)51 await test_func(VAR_3)52 await test_func(VAR_2)53 await test_func(VAR_1)54 with self.subTest("Verify all cache exists"):55 for i in (VAR_1, VAR_2, VAR_3, VAR_4):56 self.assertIn(i, test_func.__cache__.values())57 test_func.clear_key(VAR_2)58 with self.subTest(f"Verify {VAR_1}, {VAR_3}, {VAR_4} cache exists"):59 for i in (VAR_1, VAR_3, VAR_4):60 self.assertIn(i, test_func.__cache__.values())61 with self.subTest(f"Verify {VAR_2} cache doesn't exist"):62 self.assertNotIn(VAR_2, test_func.__cache__.values())63 test_func.clear_key(VAR_4)64 with self.subTest(f"Verify {VAR_4} cache doesn't exist"):65 self.assertNotIn(VAR_4, test_func.__cache__.values())66 async def test_clear_all(self):67 MAX_SIZE = 568 @create_async_cache(MAX_SIZE)69 async def test_func(param):70 return param71 for i in range(MAX_SIZE):72 await test_func(i)73 with self.subTest("Verify cache full"):74 self.assertEqual(len(test_func.__cache__), MAX_SIZE)75 test_func.clear_all()76 with self.subTest("Verify cache empty"):...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.test_func(function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10wpt.test_func(function(err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18wpt.test_func(function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26wpt.test_func(function(err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34wpt.test_func(function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42wpt.test_func(function(err, data) {43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var wpt = require('wpt');50wpt.test_func(function(err, data) {51 if (err) {52 console.log(err);53 } else {54 console.log(data);55 }56});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var test = new wpt('API_KEY');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var path = require('path');3var url = require('url');4var util = require('util');5var http = require('http');6var https = require('https');7var child_process = require('child_process');8var events = require('events');9var crypto = require('crypto');10var assert = require('assert');11var async = require('async');12var webdriver = require('selenium-webdriver');13var webdriver_http = require('selenium-webdriver/http');14var webdriver_proxy = require('selenium-webdriver/proxy');15var webdriver_logging = require('selenium-webdriver/lib/logging');16var webdriver_chrome = require('selenium-webdriver/chrome');17var webdriver_firefox = require('selenium-webdriver/firefox');18var webdriver_ie = require('selenium-webdriver/ie');19var webdriver_opera = require('selenium-webdriver/opera');20var webdriver_safari = require('selenium-webdriver/safari');21var webdriver_edge = require('selenium-webdriver/edge');22var webdriver_remote = require('selenium-webdriver/remote');23var webdriver_test = require('./webdriver_test');24var webdriver_test_harness = require('./webdriver_test_harness');25var webdriver_testharnessreport = require('./webdriver_testharnessreport');26var webdriver_testharnessreport_body = require('./webdriver_testharnessreport_body');27var webdriver_testharnessreport_status = require('./webdriver_testharnessreport_status');28var webdriver_testharnessreport_properties = require('./webdriver_testharnessreport_properties');29var webdriver_testharnessreport_id = require('./webdriver_testharnessreport_id');30var webdriver_testharnessreport_extra = require('./webdriver_testharnessreport_extra');31var webdriver_testharnessreport_test = require('./webdriver_testharnessreport_test');32var webdriver_testharnessreport_message = require('./webdriver_testharnessreport_message');33var webdriver_testharnessreport_stack = require('./webdriver_testharnessreport_stack');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = new wpt('A.9e2b7c1d6e1d7c2aaf0c8d0cbe6a8c7a');3 if (err) return console.error(err);4 console.log(data);5});6test.getTestStatus('170605_3B_3b1f3f9e9e6a3a8c8d8f8f8f8f8f8f8f', function(err, data) {7 if (err) return console.error(err);8 console.log(data);9});10test.getTestResults('170605_3B_3b1f3f9e9e6a3a8c8d8f8f8f8f8f8f8f', function(err, data) {11 if (err) return console.error(err);12 console.log(data);13});14test.getLocations(function(err, data) {15 if (err) return console.error(err);16 console.log(data);17});18test.getTesters(function(err, data) {19 if (err) return console.error(err);20 console.log(data);21});22test.getTesters(function(err, data) {23 if (err) return console.error(err);24 console.log(data);25});26test.getTesters(function(err, data) {27 if (err) return console.error(err);28 console.log(data);29});30test.getTesters(function(err, data) {31 if (err) return console.error(err);32 console.log(data);33});34test.getTesters(function(err, data) {35 if (err) return console.error(err);36 console.log(data);37});38test.getTesters(function(err, data) {39 if (err) return console.error(err);

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful