Best Python code snippet using locust
will-interrupt-process-test.js
Source:will-interrupt-process-test.js  
1'use strict';2let willInterruptProcess = require('../../../lib/utilities/will-interrupt-process');3let MockProcess = require('../../helpers/mock-process');4let captureExit;5let td = require('testdouble');6let chai = require('../../chai');7let expect = chai.expect;8describe('will interrupt process', function () {9  let cb;10  beforeEach(function () {11    captureExit = require('capture-exit');12    cb = td.function();13  });14  afterEach(function () {15    willInterruptProcess.release();16  });17  describe('capture', function () {18    it('throws if already captured', function () {19      const mockProcess = new MockProcess();20      willInterruptProcess.capture(mockProcess);21      try {22        willInterruptProcess.capture(mockProcess);23        expect(true).to.equal(false);24      } catch (e) {25        expect(e.message).to.include('process already captured');26        expect(e.message).to.include('will-interrupt-process-test.js');27      }28    });29    it('throws if the process is not an EventEmitter instance', function () {30      const dissallowedArgs = [null, true, '', [], {}];31      dissallowedArgs.forEach((arg) => {32        try {33          willInterruptProcess.capture(arg);34          expect(true).to.equal(false);35        } catch (e) {36          expect(e.message).to.equal('attempt to capture bad process instance');37        }38      });39    });40    it('sets process maxListeners count', function () {41      const mockProcess = new MockProcess();42      willInterruptProcess.capture(mockProcess);43      expect(mockProcess.getMaxListeners()).to.equal(1000);44    });45  });46  describe('addHandler', function () {47    it('throws if process is not captured', function () {48      try {49        willInterruptProcess.addHandler(() => {});50        expect(true).to.equal(false);51      } catch (e) {52        expect(e.message).to.equal('process is not captured');53      }54      const mockProcess = new MockProcess();55      willInterruptProcess.capture(mockProcess);56      willInterruptProcess.release();57    });58    it('throws if process is released', function () {59      willInterruptProcess.capture(new MockProcess());60      willInterruptProcess.release();61      try {62        willInterruptProcess.addHandler(() => {});63        expect(true).to.equal(false);64      } catch (e) {65        expect(e.message).to.equal('process is not captured');66      }67    });68  });69  describe('capture-exit', function () {70    it('adds exit handler', function () {71      willInterruptProcess.capture(new MockProcess());72      willInterruptProcess.addHandler(cb);73      expect(captureExit.listenerCount()).to.equal(1);74    });75    it('removes exit handler', function () {76      willInterruptProcess.capture(new MockProcess());77      willInterruptProcess.addHandler(cb);78      willInterruptProcess.addHandler(function () {});79      willInterruptProcess.removeHandler(cb);80      expect(captureExit.listenerCount()).to.equal(1);81    });82    it('removes all exit handlers', function () {83      willInterruptProcess.capture(new MockProcess());84      willInterruptProcess.addHandler(cb);85      willInterruptProcess.addHandler(function () {});86      willInterruptProcess.release();87      expect(captureExit.listenerCount()).to.equal(0);88    });89  });90  describe('process interruption signal listeners', function () {91    let _process;92    beforeEach(function () {93      _process = new MockProcess();94      willInterruptProcess.capture(_process);95    });96    it('sets up interruption signal listeners when the first handler added', function () {97      willInterruptProcess.addHandler(cb);98      expect(_process.getSignalListenerCounts()).to.eql({99        SIGINT: 1,100        SIGTERM: 1,101        message: 1,102      });103    });104    it('sets up interruption signal listeners only once', function () {105      willInterruptProcess.addHandler(cb);106      willInterruptProcess.addHandler(function () {});107      expect(_process.getSignalListenerCounts()).to.eql({108        SIGINT: 1,109        SIGTERM: 1,110        message: 1,111      });112    });113    it('cleans up interruption signal listener', function () {114      // will-interrupt-process doesn't have any public API to get actual handlers count115      // so here we make a side test to ensure that we don't add the same callback twice116      willInterruptProcess.addHandler(cb);117      willInterruptProcess.removeHandler(cb);118      expect(_process.getSignalListenerCounts()).to.eql({119        SIGINT: 0,120        SIGTERM: 0,121        message: 0,122      });123    });124    it(`doesn't clean up interruption signal listeners if there are remaining handlers`, function () {125      willInterruptProcess.addHandler(cb);126      willInterruptProcess.addHandler(() => cb());127      willInterruptProcess.removeHandler(cb);128      expect(_process.getSignalListenerCounts()).to.eql({129        SIGINT: 1,130        SIGTERM: 1,131        message: 1,132      });133    });134    it('cleans up all interruption signal listeners', function () {135      willInterruptProcess.addHandler(cb);136      willInterruptProcess.addHandler(function () {});137      willInterruptProcess.addHandler(() => cb);138      willInterruptProcess.release();139      expect(_process.getSignalListenerCounts()).to.eql({140        SIGINT: 0,141        SIGTERM: 0,142        message: 0,143      });144    });145  });146  describe('Windows CTRL + C Capture', function () {147    it('exits on CTRL+C when TTY', function () {148      let _process = new MockProcess({149        exit: td.function(),150        platform: 'win',151        stdin: {152          isTTY: true,153        },154      });155      willInterruptProcess.capture(_process);156      willInterruptProcess.addHandler(cb);157      _process.stdin.emit('data', [0x03]);158      td.verify(_process.exit());159    });160    it('adds and reverts rawMode on Windows', function () {161      const _process = new MockProcess({162        platform: 'win',163        stdin: {164          isRaw: false,165          isTTY: true,166        },167      });168      willInterruptProcess.capture(_process);169      willInterruptProcess.addHandler(cb);170      expect(_process.stdin.isRaw).to.equal(true);171      willInterruptProcess.removeHandler(cb);172      expect(_process.stdin.isRaw).to.equal(false);173    });174    it('does not enable raw capture when not a Windows', function () {175      const _process = new MockProcess({176        exit: td.function(),177        stdin: {178          isTTY: true,179          setRawMode: td.function(),180        },181      });182      willInterruptProcess.capture(_process);183      willInterruptProcess.addHandler(cb);184      td.verify(_process.stdin.setRawMode(true), {185        times: 0,186      });187      _process.stdin.emit('data', [0x03]);188      td.verify(_process.exit(), { times: 0 });189    });190    it('does not enable raw capture when not a TTY', function () {191      const _process = new MockProcess({192        exit: td.function(),193        platform: 'win',194        stdin: {195          setRawMode: td.function(),196        },197      });198      willInterruptProcess.capture(_process);199      willInterruptProcess.addHandler(cb);200      td.verify(_process.stdin.setRawMode(true), {201        times: 0,202      });203      _process.stdin.emit('data', [0x03]);204      td.verify(_process.exit(), { times: 0 });205    });206  });...Actionable.class.js
Source:Actionable.class.js  
1class Actionable {2	constructor(){3		// Actions directed towards an item or character4		this.directActions = {5			use: function(thing,player,otherThing){ return { print: "Cannot use " + thing.name, interrupt: false }; },6			consume: function(thing,player,otherThing){ return { print: "Cannot consume " + thing.name, interrupt: false }; },7			damage: function(thing,player,otherThing){ return { print: "Cannot damage " + thing.name, interrupt: false }; },8			destroy: function(thing,player,otherThing){ return { print: "Cannot destroy " + thing.name, interrupt: false }; },9			repair: function(thing,player,otherThing){ return { print: "Cannot repair " + thing.name, interrupt: false }; },10			taste: function(thing,player,otherThing){ return { print: "Cannot taste " + thing.name, interrupt: false }; },11			smell: function(thing,player,otherThing){ return { print: "Cannot smell " + thing.name, interrupt: false }; },12			touch: function(thing,player,otherThing){ return { print: "Cannot touch " + thing.name, interrupt: false }; }13		};14		this.indirectActions = {15			any: function(player){ return {interrupt:false,print:""}; },16			switchTo: function(player,otherPlayer){ return {interrupt:false,print:""}; },17			say: function(player,npc){ return {interrupt:false,print:""}; },18			speakTo: function(player,npc){ return {interrupt:false,print:""}; },19			goTo: function(player,oldRoom,newRoom){ return {interrupt:false,print:""}; },20			take: function(player,item,container){ return {interrupt:false,print:""}; },21			wear: function(player,wearing){ return {interrupt:false,print:""}; },22			remove: function(player,wearing){ return {interrupt:false,print:""}; },23			open: function(player,container){ return {interrupt:false,print:""}; },24			close: function(player,container){ return {interrupt:false,print:""}; },25			give: function(player,npc,item){ return {interrupt:false,print:""}; },26			lookAround: function(player,room){ return {interrupt:false,print:""}; },27			lookAt: function(player,any){ return {interrupt:false,print:""}; },28			use: function(player,thing,otherThing){ return {interrupt:false,print:""}; },29			leaveConversation: function(player,npc){ return {interrupt:false,print:""}; },30			consume: function(player, any, item){return {interrupt:false,print:""};},31			damage: function(player, any, item){return {interrupt:false,print:""};},32			destroy: function(player, any, item){return {interrupt:false,print:""};},33			repair: function(player, any, item){return {interrupt:false,print:""};},34			taste: function(player, any, item){return {interrupt:false,print:""};},35			smell: function(player, any, item){return {interrupt:false,print:""};},36			touch: function(player, any, item){return {interrupt:false,print:""};}37		};38	}39	setIndirectAction(action, callback){40		this.indirectActions[Actionable.verbSynonym(action)] = callback;41		return this;42	}43	setDirectAction(action, callback){44		this.directActions[Actionable.verbSynonym(action)] = callback;45		return this;46	}47	directAction(action,a,b,c,d){48		this.directActions[action](this,a,b,c,d);49	}50	indirectAction(action,a,b,c,d){51		this.indirectActions[action](this,a,b,c,d);52	}53}54Actionable.verbSynonym = function(action){55	switch(action){56		case "eat":57		case "drink":58		case "swallow":59		case "consume":60			return "consume";61		case "operate":62		case "use":63			return "use";64		case "repair":65		case "mend":66		case "fix":67		case "heal":68			return "repair";69		case "break":70		case "tear":71		case "erase":72		case "annihilate":73		case "destroy":74			return "destroy";75		case "damage":76		case "hit":77		case "punch":78		case "kick":79			return "damage";80		case "smell":81		case "sniff":82			return "smell";83		case "taste":84		case "lick":85			return "taste";86		case "feel":87		case "touch":88			return "touch";89	}90};91Actionable.verbs = [92	"eat",93	"drink",94	"swallow",95	"consume",96	"operate",97	"use",98	"break",99	"tear",100	"destroy",101	"damage",102	"hit",103	"punch",104	"kick",105	"smell",106	"sniff",107	"taste",108	"lick",109	"feel",110	"touch"111];112Actionable.actions = [113	"switchTo",114	"say",115	"speakTo",116	"goTo",117	"take",118	"wear",119	"remove",120	"open",121	"close",122	"give",123	"lookAround",124	"lookAt",125	"leaveConversation"126];127Actionable.globalActions = {128	any: function(actionable,player){ return {interrupt:false,print:""}; },129	switchTo: function(actionable,player,otherPlayer){ return {interrupt:false,print:""}; },130	say: function(actionable,player,npc){ return {interrupt:false,print:""}; },131	speakTo: function(actionable,player,npc){ return {interrupt:false,print:""}; },132	goTo: function(actionable,player,oldRoom,newRoom){ return {interrupt:false,print:""}; },133	take: function(actionable,player,item,container){ return {interrupt:false,print:""}; },134	wear: function(actionable,player,wearing){ return {interrupt:false,print:""}; },135	remove: function(actionable,player,wearing){ return {interrupt:false,print:""}; },136	open: function(actionable,player,container){ return {interrupt:false,print:""}; },137	close: function(actionable,player,container){ return {interrupt:false,print:""}; },138	give: function(actionable,player,npc,item){ return {interrupt:false,print:""}; },139	lookAround: function(actionable,player,room){ return {interrupt:false,print:""}; },140	lookAt: function(actionable,player,any){ return {interrupt:false,print:""}; },141	use: function(actionable,player,thing,otherThing){ return {interrupt:false,print:""}; },142	leaveConversation: function(actionable,player,npc){ return {interrupt:false,print:""}; },143	consume: function(actionable,player,any,item){return {interrupt:false,print:""};},144	damage: function(actionable,player,any,item){return {interrupt:false,print:""};},145	destroy: function(actionable,player,any,item){return {interrupt:false,print:""};},146	repair: function(actionable,player,any,item){return {interrupt:false,print:""};},147	taste: function(actionable,player,any,item){return {interrupt:false,print:""};},148	smell: function(actionable,player,any,item){return {interrupt:false,print:""};},149	touch: function(actionable,player,any,item){return {interrupt:false,print:""};}...groups_8.js
Source:groups_8.js  
1var searchData=2[3  ['interrupt_20line_20selection_20masks',['Interrupt line selection masks',['../group__group__canfd__interrupt__line__masks.html',1,'']]],4  ['initialization_20functions',['Initialization Functions',['../group__group__ctb__functions__init.html',1,'']]],5  ['interrupt_20functions',['Interrupt Functions',['../group__group__ctb__functions__interrupts.html',1,'']]],6  ['initialization_20functions',['Initialization Functions',['../group__group__ctdac__functions__init.html',1,'']]],7  ['interrupt_20functions',['Interrupt Functions',['../group__group__ctdac__functions__interrupts.html',1,'']]],8  ['interrupt_20masks',['Interrupt Masks',['../group__group__dmac__macros__interrupt__masks.html',1,'']]],9  ['initialization_20functions',['Initialization Functions',['../group__group__gpio__functions__init.html',1,'']]],10  ['interrupt_20trigger_20type',['Interrupt trigger type',['../group__group__gpio__interrupt_trigger.html',1,'']]],11  ['i2s_20_20_20_20_20_20_20_20_20_20_28inter_2dic_20sound_29',['I2S          (Inter-IC Sound)',['../group__group__i2s.html',1,'']]],12  ['interrupt_20masks',['Interrupt Masks',['../group__group__i2s__macros__interrupt__masks.html',1,'']]],13  ['ipc_20_20_20_20_20_20_20_20_20_20_28inter_20process_20communication_29',['IPC          (Inter Process Communication)',['../group__group__ipc.html',1,'']]],14  ['ipc_20driver_20layer_20_28ipc_5fdrv_29',['IPC driver layer (IPC_DRV)',['../group__group__ipc__drv.html',1,'']]],15  ['ipc_20pipes_20layer_20_28ipc_5fpipe_29',['IPC pipes layer (IPC_PIPE)',['../group__group__ipc__pipe.html',1,'']]],16  ['ipc_20semaphores_20layer_20_28ipc_5fsema_29',['IPC semaphores layer (IPC_SEMA)',['../group__group__ipc__sema.html',1,'']]],17  ['interrupt_20masks',['Interrupt Masks',['../group__group__pdm__pcm__macros__interrupt__masks.html',1,'']]],18  ['interrupt_20functions',['Interrupt Functions',['../group__group__profile__functions__interrupt.html',1,'']]],19  ['interrupt',['Interrupt',['../group__group__rtc__interrupt__functions.html',1,'']]],20  ['initialization_20and_20basic_20functions',['Initialization and Basic Functions',['../group__group__sar__functions__basic.html',1,'']]],21  ['interrupt_20functions',['Interrupt Functions',['../group__group__sar__functions__interrupt.html',1,'']]],22  ['interrupt_20masks',['Interrupt Masks',['../group__group__sar__macros__interrupt.html',1,'']]],23  ['i2c_20interrupt_20statuses',['I2C Interrupt Statuses',['../group__group__scb__common__macros__i2c__intr.html',1,'']]],24  ['i2c_20_28scb_29',['I2C (SCB)',['../group__group__scb__i2c.html',1,'']]],25  ['interrupt',['Interrupt',['../group__group__scb__i2c__interrupt__functions.html',1,'']]],26  ['i2c_20address_20callback_20events',['I2C Address Callback Events',['../group__group__scb__i2c__macros__addr__callback__events.html',1,'']]],27  ['i2c_20callback_20events',['I2C Callback Events',['../group__group__scb__i2c__macros__callback__events.html',1,'']]],28  ['i2c_20master_20status',['I2C Master Status',['../group__group__scb__i2c__macros__master__status.html',1,'']]],29  ['i2c_20slave_20status',['I2C Slave Status',['../group__group__scb__i2c__macros__slave__status.html',1,'']]],30  ['interrupt',['Interrupt',['../group__group__scb__spi__interrupt__functions.html',1,'']]],31  ['interrupt',['Interrupt',['../group__group__scb__uart__interrupt__functions.html',1,'']]],32  ['interrupt',['Interrupt',['../group__group__sd__host__interrupt__functions.html',1,'']]],33  ['initialization_20functions',['Initialization Functions',['../group__group__smartio__functions__init.html',1,'']]],34  ['interrupt_20macros',['Interrupt Macros',['../group__group__smif__macros__isr.html',1,'']]],35  ['internal_20low_2dspeed_20oscillator_20_28ilo_29',['Internal Low-Speed Oscillator (ILO)',['../group__group__sysclk__ilo.html',1,'']]],36  ['i_2fos_20freeze',['I/Os Freeze',['../group__group__syspm__functions__iofreeze.html',1,'']]],37  ['input_20modes',['Input Modes',['../group__group__tcpwm__input__modes.html',1,'']]],38  ['interrupt_20sources',['Interrupt Sources',['../group__group__tcpwm__interrupt__sources.html',1,'']]],39  ['interrupt_20functions',['Interrupt Functions',['../group__group__usbfs__dev__drv__functions__interrupts.html',1,'']]],40  ['interrupt_20cause',['Interrupt Cause',['../group__group__usbfs__dev__drv__macros__intr__cause.html',1,'']]],41  ['interrupt_20level',['Interrupt Level',['../group__group__usbfs__dev__drv__macros__intr__level.html',1,'']]],42  ['initialization_20functions',['Initialization Functions',['../group__group__usbfs__dev__hal__functions__common.html',1,'']]]...group__interrupt__api.js
Source:group__interrupt__api.js  
1var group__interrupt__api =2[3    [ "IntDisable", "group__interrupt__api.html#ga9af6b00884dc44e92b3d05ff821b5334", null ],4    [ "IntEnable", "group__interrupt__api.html#ga49fc9c3d1a0f8c42a20249f8c5d360ce", null ],5    [ "IntMasterDisable", "group__interrupt__api.html#gaf482c22ce8e4fe4e9480cc3ae7130be7", null ],6    [ "IntMasterEnable", "group__interrupt__api.html#ga6a025de3cd6adfe4cbe232b9e2cc8e4d", null ],7    [ "IntPendClear", "group__interrupt__api.html#gab708e168ca0f1f554bb141e5b0fd1bdc", null ],8    [ "IntPendGet", "group__interrupt__api.html#ga7843482cd5c741817352dd02f8db2ae1", null ],9    [ "IntPendSet", "group__interrupt__api.html#gafe17b56764bff1bcb95bd53acde4ac98", null ],10    [ "IntPriorityGet", "group__interrupt__api.html#gac6a7849e23f4a84c1bcaad2e9bcc27b2", null ],11    [ "IntPriorityGroupingGet", "group__interrupt__api.html#ga86595146bc7ea51280d5abbb45fcf02a", null ],12    [ "IntPriorityGroupingSet", "group__interrupt__api.html#ga341c2244311b2c8c84b0a5546fc3dff1", null ],13    [ "IntPriorityMaskGet", "group__interrupt__api.html#ga8213cffc914d37e50991582446974d4d", null ],14    [ "IntPriorityMaskSet", "group__interrupt__api.html#ga7f2e15c88658ef2008746a25db8e2902", null ],15    [ "IntPrioritySet", "group__interrupt__api.html#ga0432ddf52557352ac987f7dd211c2017", null ],16    [ "IntRegister", "group__interrupt__api.html#ga0a32aafea7f4904d2a64ee18b45f96c9", null ],17    [ "IntUnregister", "group__interrupt__api.html#ga5dffc81c27c005f83e9bfc30f775982a", null ],18    [ "INT_PRI_LEVEL0", "group__interrupt__api.html#gab61a1033eedd40d461dfede1d4f5c6a7", null ],19    [ "INT_PRI_LEVEL1", "group__interrupt__api.html#ga1d6ecb610527793f03d3203de7a80034", null ],20    [ "INT_PRI_LEVEL2", "group__interrupt__api.html#ga0102c20c74afe11aebc014724c2ccb5b", null ],21    [ "INT_PRI_LEVEL3", "group__interrupt__api.html#gaaa045cd825e2c4d221b8bb40cc3ea3c3", null ],22    [ "INT_PRI_LEVEL4", "group__interrupt__api.html#gac6806a86286d205a85cfb025da8aad01", null ],23    [ "INT_PRI_LEVEL5", "group__interrupt__api.html#ga8a9fec83729e5cc0a2482bd7d7032919", null ],24    [ "INT_PRI_LEVEL6", "group__interrupt__api.html#ga802ea1c0f39325323e92f779be82ce88", null ],25    [ "INT_PRI_LEVEL7", "group__interrupt__api.html#gad25e66ddc2f35bbf6c368d7f83bb861e", null ],26    [ "INT_PRIORITY_MASK", "group__interrupt__api.html#ga4f282f2e30e2247079e7c9b530ae030a", null ]...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!!
