Best JavaScript code snippet using storybook-root
ScriptPropertiesSpec.js
Source:ScriptPropertiesSpec.js
1'use strict';2var TestHelper = require('../../../TestHelper');3var TestContainer = require('mocha-test-container-support');4/* global bootstrapModeler, inject */5var propertiesPanelModule = require('lib'),6 domQuery = require('min-dom').query,7 coreModule = require('bpmn-js/lib/core').default,8 selectionModule = require('diagram-js/lib/features/selection').default,9 modelingModule = require('bpmn-js/lib/features/modeling').default,10 propertiesProviderModule = require('lib/provider/activiti'),11 activitiModdlePackage = require('activiti-bpmn-moddle/resources/activiti'),12 getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject;13describe('script-properties', function() {14 var diagramXML = require('./ScriptProperties.bpmn');15 var testModules = [16 coreModule, selectionModule, modelingModule,17 propertiesPanelModule,18 propertiesProviderModule19 ];20 var container;21 beforeEach(function() {22 container = TestContainer.get(this);23 });24 beforeEach(bootstrapModeler(diagramXML, {25 modules: testModules,26 moddleExtensions: { activiti: activitiModdlePackage }27 }));28 beforeEach(inject(function(commandStack, propertiesPanel) {29 var undoButton = document.createElement('button');30 undoButton.textContent = 'UNDO';31 undoButton.addEventListener('click', function() {32 commandStack.undo();33 });34 container.appendChild(undoButton);35 propertiesPanel.attachTo(container);36 }));37 function selectListener(container, idx, dataEntrySelector) {38 var listeners = domQuery('div[data-entry=' + dataEntrySelector + '] select[name=selectedExtensionElement]', container);39 listeners.options[idx].selected = 'selected';40 TestHelper.triggerEvent(listeners, 'change');41 }42 it('should fetch the inline script properties of a script task', inject(function(propertiesPanel, selection, elementRegistry) {43 var shape = elementRegistry.get('ScriptTask_1');44 selection.select(shape);45 var scriptFormat = domQuery('div[data-entry="script-implementation"] input[name=scriptFormat]', propertiesPanel._container),46 scriptType = domQuery('div[data-entry="script-implementation"] select[name="scriptType"]', propertiesPanel._container),47 scriptValue = domQuery('div[data-entry="script-implementation"] textarea[name="scriptValue"]', propertiesPanel._container),48 businessObject = getBusinessObject(shape);49 expect(scriptFormat.value).to.equal('groovy');50 expect(scriptType.value).to.equal('script');51 expect(scriptValue.value).to.equal('printf(\'hello world\')');52 expect(businessObject.get('scriptFormat')).to.equal(scriptFormat.value);53 expect(businessObject.get('script')).to.equal(scriptValue.value);54 }));55 it('should fetch the external resource script properties of a script task', inject(function(propertiesPanel, selection, elementRegistry) {56 var shape = elementRegistry.get('ScriptTask_Resource');57 selection.select(shape);58 var scriptFormat = domQuery('div[data-entry="script-implementation"] input[name=scriptFormat]', propertiesPanel._container),59 scriptType = domQuery('div[data-entry="script-implementation"] select[name="scriptType"]', propertiesPanel._container),60 scriptResourceValue = domQuery('div[data-entry="script-implementation"] input[name="scriptResourceValue"]', propertiesPanel._container),61 scriptResultVariable = domQuery('div[data-entry="scriptResultVariable"] input[name="scriptResultVariable"]', propertiesPanel._container),62 businessObject = getBusinessObject(shape);63 expect(scriptFormat.value).to.equal('dmn');64 expect(scriptType.value).to.equal('scriptResource');65 expect(scriptResourceValue.value).to.equal('org/camunda/bpm/DmnScriptTaskTest.dmn10.xml');66 expect(scriptResultVariable.value).to.equal('decisionResult');67 expect(businessObject.get('scriptFormat')).to.equal(scriptFormat.value);68 expect(businessObject.get('activiti:resource')).to.equal(scriptResourceValue.value);69 expect(businessObject.get('activiti:resultVariable')).to.equal(scriptResultVariable.value);70 }));71 it('should fill script properties to an empty script task', inject(function(propertiesPanel, selection, elementRegistry) {72 var shape = elementRegistry.get('ScriptTask_Empty');73 selection.select(shape);74 var scriptFormat = domQuery('div[data-entry="script-implementation"] input[name=scriptFormat]', propertiesPanel._container),75 scriptType = domQuery('div[data-entry="script-implementation"] select[name="scriptType"]', propertiesPanel._container),76 scriptValue = domQuery('div[data-entry="script-implementation"] textarea[name="scriptValue"]', propertiesPanel._container),77 scriptResultVariable = domQuery('div[data-entry="scriptResultVariable"] input[name="scriptResultVariable"]', propertiesPanel._container),78 businessObject = getBusinessObject(shape);79 // given80 expect(scriptFormat.value).is.empty;81 // 'script' is the default value82 expect(scriptType.value).to.equal('script');83 expect(scriptValue.value).is.empty;84 expect(scriptResultVariable.value).is.empty;85 expect(businessObject).not.to.have.property('scriptFormat');86 expect(businessObject).not.to.have.property('script');87 expect(businessObject).not.to.have.property('activiti:resultVariable');88 expect(businessObject).not.to.have.property('activiti:resource');89 // when90 TestHelper.triggerValue(scriptFormat, 'groovy');91 TestHelper.triggerValue(scriptValue, 'printf(\'my first script\')');92 TestHelper.triggerValue(scriptResultVariable, 'myVar');93 // then94 expect(scriptFormat.value).to.equal('groovy');95 expect(scriptType.value).to.equal('script');96 expect(scriptValue.value).to.equal('printf(\'my first script\')');97 expect(scriptResultVariable.value).to.equal('myVar');98 expect(businessObject.get('scriptFormat')).to.equal(scriptFormat.value);99 expect(businessObject.get('script')).to.equal(scriptValue.value);100 expect(businessObject.get('activiti:resultVariable')).to.equal(scriptResultVariable.value);101 expect(businessObject).not.to.have.property('activiti:resource');102 }));103 it('should change the script type from external resource to inline script for a script task', inject(function(propertiesPanel, selection, elementRegistry) {104 var shape = elementRegistry.get('ScriptTask_Resource');105 selection.select(shape);106 var scriptFormat = domQuery('div[data-entry="script-implementation"] input[name=scriptFormat]', propertiesPanel._container),107 scriptType = domQuery('div[data-entry="script-implementation"] select[name="scriptType"]', propertiesPanel._container),108 scriptResourceValue = domQuery('div[data-entry="script-implementation"] input[name="scriptResourceValue"]', propertiesPanel._container),109 scriptValue = domQuery('div[data-entry="script-implementation"] textarea[name="scriptValue"]', propertiesPanel._container),110 scriptResultVariable = domQuery('div[data-entry="scriptResultVariable"] input[name="scriptResultVariable"]', propertiesPanel._container),111 businessObject = getBusinessObject(shape);112 // given113 expect(scriptFormat.value).to.equal('dmn');114 expect(scriptType.value).to.equal('scriptResource');115 expect(scriptResourceValue.value).to.equal('org/camunda/bpm/DmnScriptTaskTest.dmn10.xml');116 expect(scriptResultVariable.value).to.equal('decisionResult');117 expect(scriptValue.value).is.empty;118 expect(businessObject.get('scriptFormat')).to.equal(scriptFormat.value);119 expect(businessObject.get('activiti:resource')).to.equal(scriptResourceValue.value);120 expect(businessObject.get('activiti:resultVariable')).to.equal(scriptResultVariable.value);121 // when122 // select 'inline script'123 scriptType.options[0].selected = 'selected';124 TestHelper.triggerEvent(scriptType, 'change');125 TestHelper.triggerValue(scriptValue, 'printf(\'hello world\')');126 // then127 expect(scriptFormat.value).to.equal('dmn');128 expect(scriptType.value).to.equal('script');129 expect(scriptValue.value).to.equal('printf(\'hello world\')');130 expect(scriptResourceValue.value).is.empty;131 expect(scriptResultVariable.value).to.equal('decisionResult');132 expect(businessObject.get('scriptFormat')).to.equal(scriptFormat.value);133 expect(businessObject).not.to.have.property('activiti:resource');134 expect(businessObject.get('script')).to.equal(scriptValue.value);135 expect(businessObject.get('activiti:resultVariable')).to.equal(scriptResultVariable.value);136 }));137 it('should remove the result variable value of a script task', inject(function(propertiesPanel, selection, elementRegistry) {138 var shape = elementRegistry.get('ScriptTask_Resource');139 selection.select(shape);140 var scriptResultVariable = domQuery('div[data-entry=scriptResultVariable] input[name="scriptResultVariable"]', propertiesPanel._container),141 clearButton = domQuery(142 '[data-entry=scriptResultVariable] > .bpp-field-wrapper > button[data-action=clear]',143 propertiesPanel._container144 ),145 businessObject = getBusinessObject(shape);146 // given147 expect(scriptResultVariable.value).to.equal('decisionResult');148 expect(businessObject.get('activiti:resultVariable')).to.equal(scriptResultVariable.value);149 // when150 TestHelper.triggerEvent(clearButton, 'click');151 // then152 expect(scriptResultVariable.value).is.empty;153 expect(businessObject).not.to.have.property('resultVariable');154 }));155 it('should remove the script format value of a script task', inject(function(propertiesPanel, selection, elementRegistry) {156 var shape = elementRegistry.get('ScriptTask_1');157 selection.select(shape);158 var scriptFormat = domQuery('div[data-entry="script-implementation"] input[name="scriptFormat"]', propertiesPanel._container),159 clearButton = domQuery(160 '[data-entry=script-implementation] > .bpp-row > .bpp-field-wrapper > button[data-action="script.clearScriptFormat"]',161 propertiesPanel._container162 ),163 businessObject = getBusinessObject(shape);164 // given165 expect(scriptFormat.value).to.equal('groovy');166 expect(businessObject.get('scriptFormat')).to.equal(scriptFormat.value);167 // when168 TestHelper.triggerEvent(clearButton, 'click');169 // then170 expect(scriptFormat.value).is.empty;171 expect(businessObject.get('scriptFormat')).is.undefined;172 }));173 it('should remove the script resource value of a script task', inject(function(propertiesPanel, selection, elementRegistry) {174 var shape = elementRegistry.get('ScriptTask_Resource');175 selection.select(shape);176 var scriptResourceValue = domQuery('div[data-entry="script-implementation"] input[name="scriptResourceValue"]', propertiesPanel._container),177 clearButton = domQuery(178 '[data-entry=script-implementation] > .bpp-row > .bpp-field-wrapper > button[data-action="script.clearScriptResource"]',179 propertiesPanel._container180 ),181 businessObject = getBusinessObject(shape);182 // given183 expect(scriptResourceValue.value).to.equal('org/camunda/bpm/DmnScriptTaskTest.dmn10.xml');184 expect(businessObject.get('activiti:resource')).to.equal(scriptResourceValue.value);185 // when186 TestHelper.triggerEvent(clearButton, 'click');187 // then188 expect(scriptResourceValue.value).is.empty;189 expect(scriptResourceValue.className).to.equal('invalid');190 expect(businessObject.get('activiti:resource')).to.equal('');191 }));192 it('should fetch the external resource script properties of a sequence flow', inject(function(propertiesPanel, selection, elementRegistry) {193 var shape = elementRegistry.get('SequenceFlow_5');194 selection.select(shape);195 var conditionType = domQuery('div[data-entry="condition"] select[name=conditionType]', propertiesPanel._container),196 scriptFormat = domQuery('div[data-entry="condition"] input[name=scriptFormat]', propertiesPanel._container),197 scriptType = domQuery('div[data-entry="condition"] select[name="scriptType"]', propertiesPanel._container),198 scriptResourceValue = domQuery('div[data-entry="condition"] input[name="scriptResourceValue"]', propertiesPanel._container),199 businessObject = getBusinessObject(shape).conditionExpression;200 expect(conditionType.value).to.equal('script');201 expect(scriptFormat.value).to.equal('groovy');202 expect(scriptType.value).to.equal('scriptResource');203 expect(scriptResourceValue.value).to.equal('org/camunda/bpm/condition.groovy');204 expect(businessObject.get('language')).to.equal(scriptFormat.value);205 expect(businessObject.get('activiti:resource')).to.equal(scriptResourceValue.value);206 }));207 it('should fetch the inline script properties of a sequence flow', inject(function(propertiesPanel, selection, elementRegistry) {208 var shape = elementRegistry.get('SequenceFlow_4');209 selection.select(shape);210 var conditionType = domQuery('div[data-entry="condition"] select[name=conditionType]', propertiesPanel._container),211 scriptFormat = domQuery('div[data-entry="condition"] input[name=scriptFormat]', propertiesPanel._container),212 scriptType = domQuery('div[data-entry="condition"] select[name="scriptType"]', propertiesPanel._container),213 scriptValue = domQuery('div[data-entry="condition"] textarea[name="scriptValue"]', propertiesPanel._container),214 businessObject = getBusinessObject(shape).conditionExpression;215 expect(conditionType.value).to.equal('script');216 expect(scriptFormat.value).to.equal('groovy');217 expect(scriptType.value).to.equal('script');218 expect(scriptValue.value).to.equal('status == \'complete\'');219 expect(businessObject.get('language')).to.equal(scriptFormat.value);220 expect(businessObject.body).to.equal(scriptValue.value);221 }));222 it('should add inline script properties for a sequence flow', inject(function(propertiesPanel, selection, elementRegistry) {223 var shape = elementRegistry.get('SequenceFlow_3');224 selection.select(shape);225 var conditionType = domQuery('div[data-entry="condition"] select[name=conditionType]', propertiesPanel._container),226 scriptFormat = domQuery('div[data-entry="condition"] input[name=scriptFormat]', propertiesPanel._container),227 scriptType = domQuery('div[data-entry="condition"] select[name="scriptType"]', propertiesPanel._container),228 scriptValue = domQuery('div[data-entry="condition"] textarea[name="scriptValue"]', propertiesPanel._container),229 businessObject = getBusinessObject(shape);230 // given231 expect(businessObject).not.to.have.property('conditionExpression');232 expect(businessObject).not.to.have.property('script');233 // when234 // select 'script'235 conditionType.options[1].selected = 'selected';236 TestHelper.triggerEvent(conditionType, 'change');237 TestHelper.triggerValue(scriptFormat, 'groovy');238 TestHelper.triggerValue(scriptValue, 'status == \'complete\'');239 // then240 expect(conditionType.value).to.equal('script');241 expect(scriptFormat.value).to.equal('groovy');242 expect(scriptType.value).to.equal('script');243 expect(scriptValue.value).to.equal('status == \'complete\'');244 expect(businessObject.conditionExpression).is.not.empty;245 expect(businessObject.conditionExpression.get('language')).to.equal(scriptFormat.value);246 expect(businessObject.conditionExpression.body).to.equal(scriptValue.value);247 }));248 it('should change the script type from external resource to inline script for a sequence flow', inject(function(propertiesPanel, selection, elementRegistry) {249 var shape = elementRegistry.get('SequenceFlow_5');250 selection.select(shape);251 var conditionType = domQuery('div[data-entry="condition"] select[name=conditionType]', propertiesPanel._container),252 scriptFormat = domQuery('div[data-entry="condition"] input[name=scriptFormat]', propertiesPanel._container),253 scriptType = domQuery('div[data-entry="condition"] select[name="scriptType"]', propertiesPanel._container),254 scriptResourceValue = domQuery('div[data-entry="condition"] input[name="scriptResourceValue"]', propertiesPanel._container),255 scriptValue = domQuery('div[data-entry="condition"] textarea[name="scriptValue"]', propertiesPanel._container),256 businessObject = getBusinessObject(shape).conditionExpression;257 // given258 expect(conditionType.value).to.equal('script');259 expect(scriptFormat.value).to.equal('groovy');260 expect(scriptType.value).to.equal('scriptResource');261 expect(scriptResourceValue.value).to.equal('org/camunda/bpm/condition.groovy');262 expect(scriptValue.value).is.empty;263 expect(businessObject.get('language')).to.equal(scriptFormat.value);264 expect(businessObject.get('activiti:resource')).to.equal(scriptResourceValue.value);265 // when266 // select 'inline script'267 scriptType.options[0].selected = 'selected';268 TestHelper.triggerEvent(scriptType, 'change');269 TestHelper.triggerValue(scriptValue, 'printf(\'hello world\')');270 // then271 expect(scriptFormat.value).to.equal('groovy');272 expect(scriptType.value).to.equal('script');273 expect(scriptValue.value).to.equal('printf(\'hello world\')');274 expect(scriptResourceValue.value).is.empty;275 // refresh businessObject after changes276 businessObject = getBusinessObject(shape).conditionExpression;277 expect(businessObject.get('language')).to.equal(scriptFormat.value);278 expect(businessObject).not.to.have.property('activiti:resource');279 expect(businessObject.body).to.equal(scriptValue.value);280 }));281 it('should remove the script format value of a sequence flow', inject(function(propertiesPanel, selection, elementRegistry) {282 var shape = elementRegistry.get('SequenceFlow_4');283 selection.select(shape);284 var scriptFormat = domQuery('div[data-entry="condition"] input[name="scriptFormat"]', propertiesPanel._container),285 clearButton = domQuery(286 '[data-entry=condition] button[data-action="script.clearScriptFormat"]',287 propertiesPanel._container288 ),289 businessObject = getBusinessObject(shape).conditionExpression;290 // given291 expect(scriptFormat.value).to.equal('groovy');292 expect(businessObject.get('language')).to.equal(scriptFormat.value);293 // when294 TestHelper.triggerEvent(clearButton, 'click');295 // then296 expect(scriptFormat.value).is.empty;297 expect(scriptFormat.className).to.equal('invalid');298 businessObject = getBusinessObject(shape).conditionExpression;299 expect(businessObject.get('language')).to.equal('');300 }));301 it('should fetch the inline script properties of an execution listener', inject(function(propertiesPanel, selection, elementRegistry) {302 var shape = elementRegistry.get('StartEvent_1');303 selection.select(shape);304 var eventType = domQuery('div[data-entry=listener-event-type] select[name=eventType]', propertiesPanel._container),305 listenerType = domQuery('div[data-entry=listener-type] select[name=listenerType]', propertiesPanel._container),306 scriptFormat = domQuery('div[data-entry=listener-script-value] input[name=scriptFormat]', propertiesPanel._container),307 scriptType = domQuery('div[data-entry=listener-script-value] select[name="scriptType"]', propertiesPanel._container),308 scriptValue = domQuery('div[data-entry=listener-script-value] textarea[name="scriptValue"]', propertiesPanel._container),309 businessObject = getBusinessObject(shape).extensionElements.values;310 selectListener(propertiesPanel._container, 0, 'executionListeners');311 expect(eventType.value).to.equal('start');312 expect(listenerType.value).to.equal('script');313 expect(scriptFormat.value).to.equal('groovy');314 expect(scriptType.value).to.equal('script');315 expect(scriptValue.value).to.equal('${sourceCode}');316 expect(businessObject.length).to.equal(1);317 expect(businessObject[0].get('event')).to.equal(eventType.value);318 expect(businessObject[0].script.get('scriptFormat')).to.equal(scriptFormat.value);319 expect(businessObject[0].script.value).to.equal(scriptValue.value);320 }));321 it('should add inline script properties for an execution listener', inject(function(propertiesPanel, selection, elementRegistry) {322 var shape = elementRegistry.get('ServiceTask_1');323 selection.select(shape);324 var addListenerButton = domQuery('div[data-entry=executionListeners] button[data-action=createElement]', propertiesPanel._container),325 businessObject = getBusinessObject(shape);326 var eventType = domQuery('div[data-entry=listener-event-type] select[name=eventType]', propertiesPanel._container),327 listenerType = domQuery('div[data-entry=listener-type] select[name=listenerType]', propertiesPanel._container),328 scriptFormat = domQuery('div[data-entry=listener-script-value] input[name=scriptFormat]', propertiesPanel._container),329 scriptType = domQuery('div[data-entry=listener-script-value] select[name="scriptType"]', propertiesPanel._container),330 scriptValue = domQuery('div[data-entry=listener-script-value] textarea[name="scriptValue"]', propertiesPanel._container);331 // given332 expect(businessObject).not.to.have.property('extensionElements');333 // when334 TestHelper.triggerEvent(addListenerButton, 'click');335 // select 'script'336 listenerType.options[3].selected = 'selected';337 TestHelper.triggerEvent(listenerType, 'change');338 TestHelper.triggerValue(scriptFormat, 'groovy');339 TestHelper.triggerValue(scriptValue, '${sourceCode}');340 // then341 expect(listenerType.value).to.equal('script');342 expect(eventType.value).to.equal('start');343 expect(scriptFormat.value).to.equal('groovy');344 expect(scriptType.value).to.equal('script');345 expect(scriptValue.value).to.equal('${sourceCode}');346 expect(businessObject.extensionElements).is.not.empty;347 expect(businessObject.extensionElements.values).to.have.length(1);348 businessObject = businessObject.extensionElements.values[0];349 expect(businessObject.get('event')).to.equal(eventType.value);350 expect(businessObject.script.get('scriptFormat')).to.equal(scriptFormat.value);351 expect(businessObject.script.value).to.equal(scriptValue.value);352 }));353 it('should change the script type from inline script to external resource for an execution listener', inject(function(propertiesPanel, selection, elementRegistry) {354 var shape = elementRegistry.get('StartEvent_1');355 selection.select(shape);356 var eventType = domQuery('div[data-entry=listener-event-type] select[name=eventType]', propertiesPanel._container),357 listenerType = domQuery('div[data-entry=listener-type] select[name=listenerType]', propertiesPanel._container),358 scriptFormat = domQuery('div[data-entry=listener-script-value] input[name=scriptFormat]', propertiesPanel._container),359 scriptType = domQuery('div[data-entry=listener-script-value] select[name="scriptType"]', propertiesPanel._container),360 scriptValue = domQuery('div[data-entry=listener-script-value] textarea[name="scriptValue"]', propertiesPanel._container),361 scriptResourceValue = domQuery('div[data-entry=listener-script-value] input[name="scriptResourceValue"]', propertiesPanel._container),362 businessObject = getBusinessObject(shape).extensionElements.values;363 selectListener(propertiesPanel._container, 0, 'executionListeners');364 // given365 expect(businessObject.length).to.equal(1);366 expect(listenerType.value).to.equal('script');367 expect(eventType.value).to.equal('start');368 expect(scriptFormat.value).to.equal('groovy');369 expect(scriptType.value).to.equal('script');370 expect(scriptResourceValue.value).is.empty;371 expect(scriptValue.value).to.equal('${sourceCode}');372 expect(businessObject[0].get('event')).to.equal(eventType.value);373 expect(businessObject[0].script.get('scriptFormat')).to.equal(scriptFormat.value);374 expect(businessObject[0].script.value).to.equal(scriptValue.value);375 expect(businessObject[0].script).not.to.have.property('resource');376 // when377 // select 'external resource'378 scriptType.options[1].selected = 'selected';379 TestHelper.triggerEvent(scriptType, 'change');380 TestHelper.triggerValue(scriptResourceValue, 'myResource.xml');381 // then382 // refresh business object383 businessObject = getBusinessObject(shape).extensionElements.values;384 expect(businessObject.length).to.equal(1);385 expect(listenerType.value).to.equal('script');386 expect(eventType.value).to.equal('start');387 expect(scriptFormat.value).to.equal('groovy');388 expect(scriptType.value).to.equal('scriptResource');389 expect(scriptResourceValue.value).to.equal('myResource.xml');390 expect(businessObject[0].get('event')).to.equal(eventType.value);391 expect(businessObject[0].script.get('scriptFormat')).to.equal(scriptFormat.value);392 expect(businessObject[0].script.get('resource')).to.equal(scriptResourceValue.value);393 expect(businessObject[0]).not.to.have.property('value');394 }));...
test_cmd_line_script.py
Source:test_cmd_line_script.py
...32import sys33assertIdentical(globals(), sys.modules[__name__].__dict__)34print 'sys.argv[0]==%r' % sys.argv[0]35"""36def _make_test_script(script_dir, script_basename, source=test_source):37 return make_script(script_dir, script_basename, source)38def _make_test_zip_pkg(zip_dir, zip_basename, pkg_name, script_basename,39 source=test_source, depth=1):40 return make_zip_pkg(zip_dir, zip_basename, pkg_name, script_basename,41 source, depth)42# There's no easy way to pass the script directory in to get43# -m to work (avoiding that is the whole point of making44# directories and zipfiles executable!)45# So we fake it for testing purposes with a custom launch script46launch_source = """\47import sys, os.path, runpy48sys.path.insert(0, %s)49runpy._run_module_as_main(%r)50"""51def _make_launch_script(script_dir, script_basename, module_name, path=None):52 if path is None:53 path = "os.path.dirname(__file__)"54 else:55 path = repr(path)56 source = launch_source % (path, module_name)57 return make_script(script_dir, script_basename, source)58class CmdLineTest(unittest.TestCase):59 def _check_script(self, script_name, expected_file,60 expected_argv0, expected_package,61 *cmd_line_switches):62 run_args = cmd_line_switches + (script_name,)63 exit_code, data = run_python(*run_args)64 if verbose:65 print 'Output from test script %r:' % script_name66 print data67 self.assertEqual(exit_code, 0)68 printed_file = '__file__==%r' % expected_file69 printed_argv0 = 'sys.argv[0]==%r' % expected_argv070 printed_package = '__package__==%r' % expected_package71 if verbose:72 print 'Expected output:'73 print printed_file74 print printed_package75 print printed_argv076 self.assertIn(printed_file, data)77 self.assertIn(printed_package, data)78 self.assertIn(printed_argv0, data)79 def _check_import_error(self, script_name, expected_msg,80 *cmd_line_switches):81 run_args = cmd_line_switches + (script_name,)82 exit_code, data = run_python(*run_args)83 if verbose:84 print 'Output from test script %r:' % script_name85 print data86 print 'Expected output: %r' % expected_msg87 self.assertIn(expected_msg, data)88 def test_basic_script(self):89 with temp_dir() as script_dir:90 script_name = _make_test_script(script_dir, 'script')91 self._check_script(script_name, script_name, script_name, None)92 def test_script_compiled(self):93 with temp_dir() as script_dir:94 script_name = _make_test_script(script_dir, 'script')95 compiled_name = compile_script(script_name)96 os.remove(script_name)97 self._check_script(compiled_name, compiled_name, compiled_name, None)98 def test_directory(self):99 with temp_dir() as script_dir:100 script_name = _make_test_script(script_dir, '__main__')101 self._check_script(script_dir, script_name, script_dir, '')102 def test_directory_compiled(self):103 with temp_dir() as script_dir:104 script_name = _make_test_script(script_dir, '__main__')105 compiled_name = compile_script(script_name)106 os.remove(script_name)107 self._check_script(script_dir, compiled_name, script_dir, '')108 def test_directory_error(self):109 with temp_dir() as script_dir:110 msg = "can't find '__main__' module in %r" % script_dir111 self._check_import_error(script_dir, msg)112 def test_zipfile(self):113 with temp_dir() as script_dir:114 script_name = _make_test_script(script_dir, '__main__')115 zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name)116 self._check_script(zip_name, run_name, zip_name, '')117 def test_zipfile_compiled(self):118 with temp_dir() as script_dir:119 script_name = _make_test_script(script_dir, '__main__')120 compiled_name = compile_script(script_name)121 zip_name, run_name = make_zip_script(script_dir, 'test_zip', compiled_name)122 self._check_script(zip_name, run_name, zip_name, '')123 def test_zipfile_error(self):124 with temp_dir() as script_dir:125 script_name = _make_test_script(script_dir, 'not_main')126 zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name)127 msg = "can't find '__main__' module in %r" % zip_name128 self._check_import_error(zip_name, msg)129 def test_module_in_package(self):130 with temp_dir() as script_dir:131 pkg_dir = os.path.join(script_dir, 'test_pkg')132 make_pkg(pkg_dir)133 script_name = _make_test_script(pkg_dir, 'script')134 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script')135 self._check_script(launch_name, script_name, script_name, 'test_pkg')136 def test_module_in_package_in_zipfile(self):137 with temp_dir() as script_dir:138 zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script')139 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script', zip_name)140 self._check_script(launch_name, run_name, run_name, 'test_pkg')141 def test_module_in_subpackage_in_zipfile(self):142 with temp_dir() as script_dir:143 zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script', depth=2)144 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.test_pkg.script', zip_name)145 self._check_script(launch_name, run_name, run_name, 'test_pkg.test_pkg')146 def test_package(self):147 with temp_dir() as script_dir:148 pkg_dir = os.path.join(script_dir, 'test_pkg')149 make_pkg(pkg_dir)150 script_name = _make_test_script(pkg_dir, '__main__')151 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')152 self._check_script(launch_name, script_name,153 script_name, 'test_pkg')154 def test_package_compiled(self):155 with temp_dir() as script_dir:156 pkg_dir = os.path.join(script_dir, 'test_pkg')157 make_pkg(pkg_dir)158 script_name = _make_test_script(pkg_dir, '__main__')159 compiled_name = compile_script(script_name)160 os.remove(script_name)161 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')162 self._check_script(launch_name, compiled_name,163 compiled_name, 'test_pkg')164 def test_package_error(self):165 with temp_dir() as script_dir:166 pkg_dir = os.path.join(script_dir, 'test_pkg')167 make_pkg(pkg_dir)168 msg = ("'test_pkg' is a package and cannot "169 "be directly executed")170 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')171 self._check_import_error(launch_name, msg)172 def test_package_recursion(self):173 with temp_dir() as script_dir:174 pkg_dir = os.path.join(script_dir, 'test_pkg')175 make_pkg(pkg_dir)176 main_dir = os.path.join(pkg_dir, '__main__')177 make_pkg(main_dir)178 msg = ("Cannot use package as __main__ module; "179 "'test_pkg' is a package and cannot "180 "be directly executed")181 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')182 self._check_import_error(launch_name, msg)183 def test_dash_m_error_code_is_one(self):184 # If a module is invoked with the -m command line flag185 # and results in an error that the return code to the186 # shell is '1'187 with temp_dir() as script_dir:188 pkg_dir = os.path.join(script_dir, 'test_pkg')189 make_pkg(pkg_dir)190 script_name = _make_test_script(pkg_dir, 'other', "if __name__ == '__main__': raise ValueError")191 rc, out, err = assert_python_failure('-m', 'test_pkg.other', *example_args)192 if verbose > 1:193 print(out)194 self.assertEqual(rc, 1)195def test_main():196 test.test_support.run_unittest(CmdLineTest)197 test.test_support.reap_children()198if __name__ == '__main__':...
Script.js
Source:Script.js
1'use strict';2var domQuery = require('min-dom').query,3 utils = require('../../../../Utils');4function getScriptType(node) {5 return utils.selectedType('select[name=scriptType]', node.parentElement);6}7module.exports = function(scriptLanguagePropName, scriptValuePropName, isFormatRequired) {8 return {9 template:10 '<div class="bpp-row bpp-textfield">' +11 '<label for="cam-script-format">Script Format</label>' +12 '<div class="bpp-field-wrapper">' +13 '<input id="cam-script-format" type="text" name="scriptFormat" />' +14 '<button class="clear" data-action="script.clearScriptFormat" data-show="script.canClearScriptFormat">' +15 '<span>X</span>' +16 '</button>' +17 '</div>' +18 '</div>' +19 '<div class="bpp-row">' +20 '<label for="cam-script-type">Script Type</label>' +21 '<div class="bpp-field-wrapper">' +22 '<select id="cam-script-type" name="scriptType" data-value>' +23 '<option value="script" selected>Inline Script</option>' +24 '<option value="scriptResource">External Resource</option>' +25 '</select>' +26 '</div>' +27 '</div>' +28 '<div class="bpp-row bpp-textfield">' +29 '<label for="cam-script-resource-val" data-show="script.isScriptResource">Resource</label>' +30 '<div class="bpp-field-wrapper" data-show="script.isScriptResource">' +31 '<input id="cam-script-resource-val" type="text" name="scriptResourceValue" />' +32 '<button class="clear" data-action="script.clearScriptResource" data-show="script.canClearScriptResource">' +33 '<span>X</span>' +34 '</button>' +35 '</div>' +36 '</div>' +37 '<div class="bpp-row">' +38 '<label for="cam-script-val" data-show="script.isScript">Script</label>' +39 '<div class="bpp-field-wrapper" data-show="script.isScript">' +40 '<textarea id="cam-script-val" type="text" name="scriptValue"></textarea>' +41 '</div>'+42 '</div>',43 get: function(element, bo) {44 var values = {};45 // read values from xml:46 var boScriptResource = bo.get('activiti:resource'),47 boScript = bo.get(scriptValuePropName),48 boScriptFormat = bo.get(scriptLanguagePropName);49 if (typeof boScriptResource !== 'undefined') {50 values.scriptResourceValue = boScriptResource;51 values.scriptType = 'scriptResource';52 } else {53 values.scriptValue = boScript;54 values.scriptType = 'script';55 }56 values.scriptFormat = boScriptFormat;57 return values;58 },59 set: function(element, values, containerElement) {60 var scriptFormat = values.scriptFormat,61 scriptType = values.scriptType,62 scriptResourceValue = values.scriptResourceValue,63 scriptValue = values.scriptValue;64 // init update65 var update = {66 'activiti:resource': undefined67 };68 update[scriptValuePropName] = undefined;69 update[scriptLanguagePropName] = undefined;70 if (isFormatRequired) {71 // always set language72 update[scriptLanguagePropName] = scriptFormat || '';73 } else74 // set language only when scriptFormat has a value75 if (scriptFormat !== '') {76 update[scriptLanguagePropName] = scriptFormat;77 }78 // set either inline script or resource79 if ('scriptResource' === scriptType) {80 update['activiti:resource'] = scriptResourceValue || '';81 } else {82 update[scriptValuePropName] = scriptValue || '';83 }84 return update;85 },86 validate: function(element, values) {87 var validationResult = {};88 if (values.scriptType === 'script' && !values.scriptValue) {89 validationResult.scriptValue = 'Must provide a value';90 }91 if (values.scriptType === 'scriptResource' && !values.scriptResourceValue) {92 validationResult.scriptResourceValue = 'Must provide a value';93 }94 if (isFormatRequired && (!values.scriptFormat || values.scriptFormat.length === 0)) {95 validationResult.scriptFormat = 'Must provide a value';96 }97 return validationResult;98 },99 clearScriptFormat: function(element, inputNode, btnNode, scopeNode) {100 domQuery('input[name=scriptFormat]', scopeNode).value='';101 return true;102 },103 canClearScriptFormat: function(element, inputNode, btnNode, scopeNode) {104 var input = domQuery('input[name=scriptFormat]', scopeNode);105 return input.value !== '';106 },107 clearScriptResource: function(element, inputNode, btnNode, scopeNode) {108 domQuery('input[name=scriptResourceValue]', scopeNode).value='';109 return true;110 },111 canClearScriptResource: function(element, inputNode, btnNode, scopeNode) {112 var input = domQuery('input[name=scriptResourceValue]', scopeNode);113 return input.value !== '';114 },115 clearScript: function(element, inputNode, btnNode, scopeNode) {116 domQuery('textarea[name=scriptValue]', scopeNode).value='';117 return true;118 },119 canClearScript: function(element, inputNode, btnNode, scopeNode) {120 var input = domQuery('textarea[name=scriptValue]', scopeNode);121 return input.value !== '';122 },123 isScriptResource: function(element, inputNode, btnNode, scopeNode) {124 var scriptType = getScriptType(scopeNode);125 return scriptType === 'scriptResource';126 },127 isScript: function(element, inputNode, btnNode, scopeNode) {128 var scriptType = getScriptType(scopeNode);129 return scriptType === 'script';130 }131 };...
unlock.js
Source:unlock.js
1const assert = require('assert')2const {Script} = require('../chap-script/script')3const {Keypair} = require('../chap-bitcoin-crypto/keypair')4const {encodeBase58Check} = require('../chap-bitcoin-crypto/base58check')5const {conf} = require('../')6const unlockers = [7 (scriptChunks, {keys}) => {8 if (9 scriptChunks.length !== 2 ||10 !(scriptChunks[0] instanceof Buffer) ||11 scriptChunks[1] !== 'OP_CHECKSIG'12 ) {13 return null14 }15 const pubkey = scriptChunks[0]16 const key = (keys || []).find(k => {17 return k.toPublicKey().toString('hex') === pubkey.toString('hex')18 })19 20 if (!key) {21 return null22 }23 const createScript = ({sig}) => Script.asm`${sig}`24 return {25 key,26 type: 'P2PK',27 pubkey,28 address: Keypair.fromPublicKey(pubkey).toAddress(),29 createScript,30 }31 },32 (scriptChunks, {keys}) => {33 if (34 scriptChunks.length !== 5 ||35 scriptChunks[0] !== 'OP_DUP' ||36 scriptChunks[1] !== 'OP_HASH160' ||37 !(scriptChunks[2] instanceof Buffer) ||38 scriptChunks[2].length !== 20 ||39 scriptChunks[3] !== 'OP_EQUALVERIFY' ||40 scriptChunks[4] !== 'OP_CHECKSIG'41 ) {42 return null43 }44 const pubkeyHash = scriptChunks[2]45 console.log('P2PKH key', keys)46 const key = (keys || []).find(k => {47 return k.toPublicHash().toString('hex') === pubkeyHash.toString('hex')48 })49 50 if (!key) {51 return null52 }53 const createScript = ({sig}) => Script.asm`${sig} ${key.toPublicKey()}`54 return {55 type: 'P2PKH',56 pubkeyHash,57 address: encodeBase58Check(Buffer.concat([conf.pubkeyHash, pubkeyHash])),58 createScript,59 }60 },61 scriptChunks => {62 if (63 scriptChunks.length !== 3 ||64 scriptChunks[0] !== 'OP_HASH160' ||65 !(scriptChunks[1] instanceof Buffer) ||66 scriptChunks[1].length !== 20 ||67 scriptChunks[2] !== 'OP_EQUAL'68 ) {69 return null70 }71 return {72 type: 'P2SH',73 scriptHash: scriptChunks[1],74 createScript: ({sig, script}) => Script.asm`${sig} ${script}`,75 }76 }77]78const guessScript = (script, opts = {}) => {79 assert(script instanceof Script)80 const scriptChunks = script.getChunks()81 const found = unlockers.find(unlocker => unlocker(scriptChunks, opts))82 if (found) {83 return found(scriptChunks, opts)84 }85 return null86}87module.exports = {88 guessScript,...
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!!