Best Python code snippet using green
job-realm.js
Source:job-realm.js
1// `debugGetQueuedJobs` is available only in debug build.2if (!getBuildConfiguration().debug) {3 quit();4}5function testOne(func) {6 assertEq(debugGetQueuedJobs().length, 0);7 func();8 drainJobQueue();9 assertEq(debugGetQueuedJobs().length, 0);10 if (func.length == 1) {11 func({sameCompartmentAs: globalThis});12 drainJobQueue();13 assertEq(debugGetQueuedJobs().length, 0);14 }15}16function assertGlobal(obj, expectedGlobal) {17 const global = objectGlobal(obj);18 if (global) {19 assertEq(global === expectedGlobal, true);20 } else {21 // obj is a wrapper.22 // expectedGlobal should be other global than this.23 assertEq(expectedGlobal !== globalThis, true);24 }25}26testOne(() => {27 // Just creating a promise shouldn't enqueue any jobs.28 Promise.resolve(10);29 assertEq(debugGetQueuedJobs().length, 0);30});31testOne(() => {32 // Calling then should create a job for each.33 Promise.resolve(10).then(() => {});34 Promise.resolve(10).then(() => {});35 Promise.resolve(10).then(() => {});36 assertEq(debugGetQueuedJobs().length, 3);37});38testOne(() => {39 // The reaction job should use the function's realm.40 Promise.resolve(10).then(() => {});41 var jobs = debugGetQueuedJobs();42 assertEq(jobs.length, 1);43 assertGlobal(jobs[0], globalThis);44});45testOne(newGlobalOptions => {46 // The reaction job should use the function's realm.47 var g = newGlobal(newGlobalOptions);48 g.eval(`49Promise.resolve(10).then(() => {});50`);51 var jobs = debugGetQueuedJobs();52 assertEq(jobs.length, 1);53 assertGlobal(jobs[0], g);54});55testOne(newGlobalOptions => {56 // The reaction job should use the function's realm.57 var g = newGlobal(newGlobalOptions);58 g.Promise.resolve(10).then(g.eval(`() => {}`));59 var jobs = debugGetQueuedJobs();60 assertEq(jobs.length, 1);61 assertGlobal(jobs[0], g);62});63testOne(newGlobalOptions => {64 // The reaction job should use the function's realm.65 var g = newGlobal(newGlobalOptions);66 g.Promise.resolve(10).then(() => {});67 var jobs = debugGetQueuedJobs();68 assertEq(jobs.length, 1);69 assertGlobal(jobs[0], globalThis);70});71testOne(newGlobalOptions => {72 // The reaction job should use the bound function's target function's realm.73 var g = newGlobal(newGlobalOptions);74 g.Promise.resolve(10)75 .then(Function.prototype.bind.call(g.eval(`() => {}`), this));76 var jobs = debugGetQueuedJobs();77 assertEq(jobs.length, 1);78 assertGlobal(jobs[0], g);79});80testOne(newGlobalOptions => {81 // The reaction job should use the bound function's target function's realm.82 var g = newGlobal(newGlobalOptions);83 g.Promise.resolve(10)84 .then(g.Function.prototype.bind.call(() => {}, g));85 var jobs = debugGetQueuedJobs();86 assertEq(jobs.length, 1);87 assertGlobal(jobs[0], globalThis);88});89testOne(newGlobalOptions => {90 // The reaction job should use the bound function's target function's realm,91 // recursively92 var g = newGlobal(newGlobalOptions);93 g.Promise.resolve(10)94 .then(95 g.Function.prototype.bind.call(96 Function.prototype.bind.call(97 g.Function.prototype.bind.call(98 () => {},99 g),100 this),101 g)102 );103 var jobs = debugGetQueuedJobs();104 assertEq(jobs.length, 1);105 assertGlobal(jobs[0], globalThis);106});107testOne(newGlobalOptions => {108 // The reaction job should use the bound function's target function's realm,109 // recursively110 var g = newGlobal(newGlobalOptions);111 Promise.resolve(10)112 .then(113 g.Function.prototype.bind.call(114 Function.prototype.bind.call(115 g.Function.prototype.bind.call(116 Function.prototype.bind.call(117 g.eval(`() => {}`),118 this),119 g),120 this),121 g)122 );123 var jobs = debugGetQueuedJobs();124 assertEq(jobs.length, 1);125 assertGlobal(jobs[0], g);126});127testOne(newGlobalOptions => {128 // The reaction job should use the proxy's target function's realm.129 var g = newGlobal(newGlobalOptions);130 g.handler = () => {};131 g.eval(`132Promise.resolve(10).then(new Proxy(handler, {}));133`);134 var jobs = debugGetQueuedJobs();135 assertEq(jobs.length, 1);136 assertGlobal(jobs[0], globalThis);137});138testOne(newGlobalOptions => {139 // The reaction job should use the proxy's target function's realm.140 var g = newGlobal(newGlobalOptions);141 g.eval(`142var handler = () => {};143`);144 Promise.resolve(10).then(new Proxy(g.handler, {}));145 var jobs = debugGetQueuedJobs();146 assertEq(jobs.length, 1);147 assertGlobal(jobs[0], g);148});149testOne(newGlobalOptions => {150 // The reaction job should use the proxy's target function's realm,151 // recursively.152 var g = newGlobal(newGlobalOptions);153 g.handler = () => {};154 g.outerProxy = Proxy;155 g.eval(`156Promise.resolve(10).then(157 new outerProxy(new Proxy(new outerProxy(new Proxy(handler, {}), {}), {}), {})158);159`);160 var jobs = debugGetQueuedJobs();161 assertEq(jobs.length, 1);162 assertGlobal(jobs[0], globalThis);163});164testOne(newGlobalOptions => {165 // The reaction job should use the proxy's target function's realm,166 // recursively.167 var g = newGlobal(newGlobalOptions);168 g.eval(`169var handler = () => {};170`);171 Promise.resolve(10)172 .then(new Proxy(new g.Proxy(new Proxy(g.handler, {}), {}), {}));173 var jobs = debugGetQueuedJobs();174 assertEq(jobs.length, 1);175 assertGlobal(jobs[0], g);176});177testOne(() => {178 // The thenable job should use the `then` function's realm.179 Promise.resolve({180 then: () => {}181 });182 var jobs = debugGetQueuedJobs();183 assertEq(jobs.length, 1);184 assertGlobal(jobs[0], globalThis);185});186testOne(newGlobalOptions => {187 // The thenable job should use the `then` function's realm.188 var g = newGlobal(newGlobalOptions);189 Promise.resolve(g.eval(`190({191 then: () => {}192});193`));194 var jobs = debugGetQueuedJobs();195 assertEq(jobs.length, 1);196 assertGlobal(jobs[0], g);197});198testOne(newGlobalOptions => {199 // The thenable job should use the `then` function's realm.200 var g = newGlobal(newGlobalOptions);201 Promise.resolve({202 then: g.eval(`() => {}`),203 });204 var jobs = debugGetQueuedJobs();205 assertEq(jobs.length, 1);206 assertGlobal(jobs[0], g);207});208testOne(newGlobalOptions => {209 // The thenable job should use the bound function's target function's realm.210 var g = newGlobal(newGlobalOptions);211 Promise.resolve({212 then: Function.prototype.bind.call(g.eval(`() => {}`), this),213 });214 var jobs = debugGetQueuedJobs();215 assertEq(jobs.length, 1);216 assertGlobal(jobs[0], g);217});218testOne(newGlobalOptions => {219 // The thenable job should use the bound function's target function's realm.220 var g = newGlobal(newGlobalOptions);221 Promise.resolve({222 then: g.Function.prototype.bind.call(() => {}, g),223 });224 var jobs = debugGetQueuedJobs();225 assertEq(jobs.length, 1);226 assertGlobal(jobs[0], globalThis);227});228testOne(newGlobalOptions => {229 // The thenable job should use the bound function's target function's realm,230 // recursively.231 var g = newGlobal(newGlobalOptions);232 Promise.resolve({233 then: Function.prototype.bind.call(234 g.Function.prototype.bind.call(235 Function.prototype.bind.call(236 g.eval(`() => {}`),237 this),238 g),239 this)240 });241 var jobs = debugGetQueuedJobs();242 assertEq(jobs.length, 1);243 assertGlobal(jobs[0], g);244});245testOne(newGlobalOptions => {246 // The thenable job should use the bound function's target function's realm,247 // recursively.248 var g = newGlobal(newGlobalOptions);249 Promise.resolve({250 then: g.Function.prototype.bind.call(251 Function.prototype.bind.call(252 g.Function.prototype.bind.call(253 () => {},254 g),255 this),256 g),257 });258 var jobs = debugGetQueuedJobs();259 assertEq(jobs.length, 1);260 assertGlobal(jobs[0], globalThis);261});262testOne(newGlobalOptions => {263 // The thenable job should use the proxy's target function's realm.264 var g = newGlobal(newGlobalOptions);265 Promise.resolve({266 then: new Proxy(g.eval(`() => {}`), {}),267 });268 var jobs = debugGetQueuedJobs();269 assertEq(jobs.length, 1);270 assertGlobal(jobs[0], g);271});272testOne(newGlobalOptions => {273 // The thenable job should use the proxy's target function's realm.274 var g = newGlobal(newGlobalOptions);275 Promise.resolve({276 then: new g.Proxy(() => {}, {}),277 });278 var jobs = debugGetQueuedJobs();279 assertEq(jobs.length, 1);280 assertGlobal(jobs[0], globalThis);281});282testOne(newGlobalOptions => {283 // The thenable job should use the proxy's target function's realm,284 // recursively.285 var g = newGlobal(newGlobalOptions);286 Promise.resolve({287 then: new Proxy(new g.Proxy(new Proxy(g.eval(`() => {}`), {}), {}), {}),288 });289 var jobs = debugGetQueuedJobs();290 assertEq(jobs.length, 1);291 assertGlobal(jobs[0], g);292});293testOne(newGlobalOptions => {294 // The thenable job should use the proxy's target function's realm,295 // recursively.296 var g = newGlobal(newGlobalOptions);297 Promise.resolve({298 then: new g.Proxy(new Proxy(new g.Proxy(() => {}, {}), {}), {}),299 });300 var jobs = debugGetQueuedJobs();301 assertEq(jobs.length, 1);302 assertGlobal(jobs[0], globalThis);303});...
test_clients.py
Source:test_clients.py
1import shutil2import unittest3from pathlib import (4 Path,5)6from minos.common import (7 DatabaseClient,8 DatabaseOperation,9 ProgrammingException,10)11from minos.plugins.lmdb import (12 LmdbDatabaseClient,13 LmdbDatabaseOperation,14 LmdbDatabaseOperationType,15)16from tests.utils import (17 BASE_PATH,18)19class TestLmdbDatabaseClient(unittest.IsolatedAsyncioTestCase):20 def setUp(self) -> None:21 super().setUp()22 self.path = BASE_PATH / "order.lmdb"23 def test_subclass(self) -> None:24 self.assertTrue(issubclass(LmdbDatabaseClient, DatabaseClient))25 def tearDown(self) -> None:26 shutil.rmtree(self.path, ignore_errors=True)27 shutil.rmtree(".lmdb", ignore_errors=True)28 async def test_constructor_default_path(self):29 async with LmdbDatabaseClient():30 self.assertTrue(Path(".lmdb").exists())31 async def test_is_valid(self):32 async with LmdbDatabaseClient(self.path) as client:33 self.assertTrue(await client.is_valid())34 async def test_execute_raises_unsupported(self):35 class _DatabaseOperation(DatabaseOperation):36 """For testing purposes."""37 async with LmdbDatabaseClient(self.path) as client:38 with self.assertRaises(ValueError):39 await client.execute(_DatabaseOperation())40 async def test_execute_create_text(self):41 create_op = LmdbDatabaseOperation(LmdbDatabaseOperationType.CREATE, "TestOne", "first", "Text Value")42 read_op = LmdbDatabaseOperation(LmdbDatabaseOperationType.READ, "TestOne", "first")43 async with LmdbDatabaseClient(self.path) as client:44 await client.execute(create_op)45 await client.execute(read_op)46 self.assertEqual("Text Value", await client.fetch_one())47 async def test_execute_create_int(self):48 create_op = LmdbDatabaseOperation(LmdbDatabaseOperationType.CREATE, "TestOne", "first", 123)49 read_op = LmdbDatabaseOperation(LmdbDatabaseOperationType.READ, "TestOne", "first")50 async with LmdbDatabaseClient(self.path) as client:51 await client.execute(create_op)52 await client.execute(read_op)53 self.assertEqual(123, await client.fetch_one())54 async def test_execute_create_dict(self):55 create_op = LmdbDatabaseOperation(56 LmdbDatabaseOperationType.CREATE, "TestOne", "first", {"key_one": "hello", "key_two": "minos"}57 )58 read_op = LmdbDatabaseOperation(LmdbDatabaseOperationType.READ, "TestOne", "first")59 async with LmdbDatabaseClient(self.path) as client:60 await client.execute(create_op)61 await client.execute(read_op)62 self.assertEqual({"key_one": "hello", "key_two": "minos"}, await client.fetch_one())63 async def test_execute_create_multi_dict(self):64 create_op = LmdbDatabaseOperation(65 LmdbDatabaseOperationType.CREATE,66 "TestOne",67 "first",68 {"key_one": "hello", "key_two": {"sub_key": "this is a sub text"}},69 )70 read_op = LmdbDatabaseOperation(LmdbDatabaseOperationType.READ, "TestOne", "first")71 async with LmdbDatabaseClient(self.path) as client:72 await client.execute(create_op)73 await client.execute(read_op)74 self.assertEqual(75 {"key_one": "hello", "key_two": {"sub_key": "this is a sub text"}}, await client.fetch_one()76 )77 async def test_execute_create_list(self):78 create_op = LmdbDatabaseOperation(LmdbDatabaseOperationType.CREATE, "TestOne", "first", ["hello", "minos"])79 read_op = LmdbDatabaseOperation(LmdbDatabaseOperationType.READ, "TestOne", "first")80 async with LmdbDatabaseClient(self.path) as client:81 await client.execute(create_op)82 await client.execute(read_op)83 self.assertEqual(["hello", "minos"], await client.fetch_one())84 async def test_execute_create_multi_table(self):85 create_op_1 = LmdbDatabaseOperation(LmdbDatabaseOperationType.CREATE, "TestOne", "first", "Text Value")86 create_op_2 = LmdbDatabaseOperation(87 LmdbDatabaseOperationType.CREATE, "TestTwo", "first_double", "Text Double Value"88 )89 create_op_3 = LmdbDatabaseOperation(LmdbDatabaseOperationType.CREATE, "TestTwo", "first", "Text Value Diff")90 read_op_1 = LmdbDatabaseOperation(LmdbDatabaseOperationType.READ, "TestOne", "first")91 read_op_2 = LmdbDatabaseOperation(LmdbDatabaseOperationType.READ, "TestTwo", "first_double")92 read_op_3 = LmdbDatabaseOperation(LmdbDatabaseOperationType.READ, "TestTwo", "first")93 async with LmdbDatabaseClient(self.path) as client:94 await client.execute(create_op_1)95 await client.execute(create_op_2)96 await client.execute(create_op_3)97 await client.execute(read_op_1)98 self.assertEqual("Text Value", await client.fetch_one())99 await client.execute(read_op_2)100 self.assertEqual("Text Double Value", await client.fetch_one())101 await client.execute(read_op_3)102 self.assertEqual("Text Value Diff", await client.fetch_one())103 async def test_execute_delete(self):104 create_op_1 = LmdbDatabaseOperation(LmdbDatabaseOperationType.CREATE, "TestOne", "first", "Text Value")105 create_op_2 = LmdbDatabaseOperation(LmdbDatabaseOperationType.CREATE, "TestOne", "second", "Text Second Value")106 delete_op_1 = LmdbDatabaseOperation(LmdbDatabaseOperationType.DELETE, "TestOne", "first")107 read_op_1 = LmdbDatabaseOperation(LmdbDatabaseOperationType.READ, "TestOne", "second")108 read_op_2 = LmdbDatabaseOperation(LmdbDatabaseOperationType.READ, "TestOne", "first")109 async with LmdbDatabaseClient(self.path) as client:110 await client.execute(create_op_1)111 await client.execute(create_op_2)112 await client.execute(delete_op_1)113 await client.execute(read_op_1)114 self.assertEqual("Text Second Value", await client.fetch_one())115 await client.execute(read_op_2)116 with self.assertRaises(ProgrammingException):117 self.assertEqual(None, await client.fetch_one())118 async def test_execute_update(self):119 create_op = LmdbDatabaseOperation(LmdbDatabaseOperationType.CREATE, "TestOne", "first", "Text Value")120 update_op = LmdbDatabaseOperation(LmdbDatabaseOperationType.UPDATE, "TestOne", "first", "Updated Text Value")121 read_op = LmdbDatabaseOperation(LmdbDatabaseOperationType.READ, "TestOne", "first")122 async with LmdbDatabaseClient(self.path) as client:123 await client.execute(create_op)124 await client.execute(read_op)125 self.assertEqual("Text Value", await client.fetch_one())126 await client.execute(update_op)127 await client.execute(read_op)128 self.assertEqual("Updated Text Value", await client.fetch_one())129if __name__ == "__main__":...
dictionary-delete-compact.js
Source:dictionary-delete-compact.js
...41 }42}43var o = {};44function test(useFreshObject) {45 function testOne(f) {46 if (useFreshObject) {47 o = {};48 }49 f();50 }51 for (var i = 6; i < 12; i++) {52 testOne(_ => deleteRange(i, 1000));53 }54 testOne(_ => deleteRange(100, 1000));55 testOne(_ => deleteRange(0, 1000));56 testOne(_ => deleteRange(1, 1000));57 testOne(_ => deleteRange(8, 990));58 testOne(_ => deleteMany(3));59 testOne(_ => deleteMany(7));60 testOne(_ => deleteMany(8));61 testOne(_ => deleteMany(15));62 testOne(_ => deleteMany(111));63}64test(true);65o = {};...
test-game.js
Source:test-game.js
1const Game = require("../src/game");2const Scout = require("../src/units/scout");3const gameTestingStrategies = require("../src/strategies/game-testing-strategies.js");4const StratOne = gameTestingStrategies.StratOne;5const StratTwo = gameTestingStrategies.StratTwo;6console.log(`\nTesting Simple Strategies`);7let testOne = new Game([StratOne, StratTwo], 13, {"Economic": null, "Movement": 3, "Combat": null}, 3);8console.log("0 player 0\n\n", testOne.players[0])9console.log("0 player 1\n\n", testOne.players[1])10testOne.generateState();11testOne.completeTurn();12console.log("\n\n1 player 0\n\n", testOne.players[0])13console.log("1 player 1\n\n", testOne.players[1])14testOne.turn += 1;15testOne.generateState();16testOne.completeTurn();17console.log("\n\n2 player 0\n\n", testOne.players[0])18console.log("2 player 1\n\n", testOne.players[1])19testOne.turn += 1;20testOne.generateState();21testOne.completeTurn();22console.log("\n\n3 player 0\n\n", testOne.players[0])23console.log("3 player 1\n\n", testOne.players[1])...
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!!