How to use _load method in prospector

Best Python code snippet using prospector_python

load-plugins.spec.js

Source:load-plugins.spec.js Github

copy

Full Screen

1/* global describe:true, it:true */2// Test setup:3import { expect, NOOP, sinon } from '../test-setup';4// Dependencies:5import fs from 'fs';6import module from 'module';7import path from 'path';8import * as tractorLogger from 'tractor-logger';9import { TractorError } from 'tractor-error-handler';10// Under test:11import { loadPlugins } from './load-plugins';12describe('tractor-plugin-loader:', () => {13 describe('load-plugins:', () => {14 it('should do nothing if there is not any installed plugins', () => {15 let nodeModules = [];16 sinon.stub(fs, 'readdirSync').returns(nodeModules);17 sinon.stub(tractorLogger, 'info');18 let plugins = loadPlugins();19 expect(plugins.length).to.equal(0);20 fs.readdirSync.restore();21 tractorLogger.info.restore();22 });23 it('should create a plugin for each installed plugin', () => {24 let nodeModules = ['tractor-plugin-test'];25 let pluginModule = {};26 sinon.stub(fs, 'readdirSync').returns(nodeModules);27 sinon.stub(module, '_load').returns(pluginModule);28 sinon.stub(tractorLogger, 'info');29 let plugins = loadPlugins();30 expect(plugins.length).to.equal(1);31 expect(pluginModule.fullName).to.equal('tractor-plugin-test');32 expect(pluginModule.name).to.equal('test');33 fs.readdirSync.restore();34 module._load.restore();35 tractorLogger.info.restore();36 });37 it('should create a plugin for an ES2015 module', () => {38 let nodeModules = ['tractor-plugin-test'];39 let pluginModule = {40 default: {}41 };42 sinon.stub(fs, 'readdirSync').returns(nodeModules);43 sinon.stub(module, '_load').returns(pluginModule);44 sinon.stub(tractorLogger, 'info');45 let plugins = loadPlugins();46 expect(plugins.length).to.equal(1);47 fs.readdirSync.restore();48 module._load.restore();49 tractorLogger.info.restore();50 });51 it('should throw if the plugin cannot be loaded', () => {52 let nodeModules = ['tractor-plugin-test'];53 sinon.stub(fs, 'readdirSync').returns(nodeModules);54 sinon.stub(module, '_load').throws(new Error());55 sinon.stub(tractorLogger, 'info');56 expect(() => {57 loadPlugins();58 }).to.throw(TractorError, `could not require 'tractor-plugin-test'`);59 fs.readdirSync.restore();60 module._load.restore();61 tractorLogger.info.restore();62 });63 it('should decorate the `description` with display values', () => {64 let nodeModules = ['tractor-plugin-test-plugin'];65 let pluginModule = {};66 sinon.stub(fs, 'readdirSync').returns(nodeModules);67 sinon.stub(module, '_load').returns(pluginModule);68 sinon.stub(tractorLogger, 'info');69 let plugins = loadPlugins();70 let [test] = plugins;71 expect(test.description.name).to.equal('Test Plugin');72 expect(test.description.variableName).to.equal('testPlugin');73 expect(test.description.url).to.equal('test-plugin');74 fs.readdirSync.restore();75 module._load.restore();76 tractorLogger.info.restore();77 });78 it('should not overwrite an existing `description`', () => {79 let nodeModules = ['tractor-plugin-test-plugin'];80 let pluginModule = {81 description: {}82 };83 sinon.stub(fs, 'readdirSync').returns(nodeModules);84 sinon.stub(module, '_load').returns(pluginModule);85 sinon.stub(tractorLogger, 'info');86 let plugins = loadPlugins();87 let [test] = plugins;88 expect(test.description).to.equal(pluginModule.description);89 fs.readdirSync.restore();90 module._load.restore();91 tractorLogger.info.restore();92 });93 it('should decorate the `description` with the version', () => {94 let nodeModules = ['tractor-plugin-test-plugin'];95 let pluginModule = {};96 let pluginPackage = {97 version: '0.1.0'98 };99 sinon.stub(process, 'cwd').returns('');100 sinon.stub(fs, 'readdirSync').returns(nodeModules);101 sinon.stub(module, '_load')102 .withArgs('node_modules/tractor-plugin-test-plugin').returns(pluginModule)103 .withArgs('node_modules/tractor-plugin-test-plugin/package.json').returns(pluginPackage);104 sinon.stub(tractorLogger, 'info');105 let plugins = loadPlugins();106 let [test] = plugins;107 expect(test.description.version).to.equal('0.1.0');108 process.cwd.restore();109 fs.readdirSync.restore();110 module._load.restore();111 tractorLogger.info.restore();112 });113 it('should have a default `create` function that is a noop', () => {114 let nodeModules = ['tractor-plugin-test'];115 let pluginModule = {};116 sinon.stub(fs, 'readdirSync').returns(nodeModules);117 sinon.stub(module, '_load').returns(pluginModule);118 sinon.stub(tractorLogger, 'info');119 let plugins = loadPlugins();120 let [test] = plugins;121 expect(() => {122 test.create();123 }).to.not.throw();124 fs.readdirSync.restore();125 module._load.restore();126 tractorLogger.info.restore();127 });128 it('should not overwrite an existing `create` function', () => {129 let nodeModules = ['tractor-plugin-test'];130 let pluginModule = {131 create: NOOP132 };133 sinon.stub(fs, 'readdirSync').returns(nodeModules);134 sinon.stub(module, '_load').returns(pluginModule);135 sinon.stub(pluginModule, 'create');136 sinon.stub(tractorLogger, 'info');137 let plugins = loadPlugins();138 let [test] = plugins;139 test.create();140 expect(pluginModule.create).to.have.been.called();141 fs.readdirSync.restore();142 module._load.restore();143 tractorLogger.info.restore();144 });145 it('should have a default `init` function that is a noop', () => {146 let nodeModules = ['tractor-plugin-test'];147 let pluginModule = {};148 sinon.stub(fs, 'readdirSync').returns(nodeModules);149 sinon.stub(module, '_load').returns(pluginModule);150 sinon.stub(tractorLogger, 'info');151 let plugins = loadPlugins();152 let [test] = plugins;153 expect(() => {154 test.init();155 }).to.not.throw();156 fs.readdirSync.restore();157 module._load.restore();158 tractorLogger.info.restore();159 });160 it('should not overwrite an existing `init` function', () => {161 let nodeModules = ['tractor-plugin-test'];162 let pluginModule = {163 init: NOOP164 };165 sinon.stub(fs, 'readdirSync').returns(nodeModules);166 sinon.stub(module, '_load').returns(pluginModule);167 sinon.stub(pluginModule, 'init');168 sinon.stub(tractorLogger, 'info');169 let plugins = loadPlugins();170 let [test] = plugins;171 test.init();172 expect(pluginModule.init).to.have.been.called();173 fs.readdirSync.restore();174 module._load.restore();175 tractorLogger.info.restore();176 });177 it('should have a default `plugin` function that is a noop', () => {178 let nodeModules = ['tractor-plugin-test'];179 let pluginModule = {};180 sinon.stub(fs, 'readdirSync').returns(nodeModules);181 sinon.stub(module, '_load').returns(pluginModule);182 sinon.stub(tractorLogger, 'info');183 let plugins = loadPlugins();184 let [test] = plugins;185 expect(() => {186 test.plugin();187 }).to.not.throw();188 fs.readdirSync.restore();189 module._load.restore();190 tractorLogger.info.restore();191 });192 it('should not overwrite an existing `plugin` function', () => {193 let nodeModules = ['tractor-plugin-test'];194 let pluginModule = {195 plugin: NOOP196 };197 sinon.stub(fs, 'readdirSync').returns(nodeModules);198 sinon.stub(module, '_load').returns(pluginModule);199 sinon.stub(pluginModule, 'plugin');200 sinon.stub(tractorLogger, 'info');201 let plugins = loadPlugins();202 let [test] = plugins;203 test.plugin();204 expect(pluginModule.plugin).to.have.been.called();205 fs.readdirSync.restore();206 module._load.restore();207 tractorLogger.info.restore();208 });209 it('should have a default `run` function that is a noop', () => {210 let nodeModules = ['tractor-plugin-test'];211 let pluginModule = {};212 sinon.stub(fs, 'readdirSync').returns(nodeModules);213 sinon.stub(module, '_load').returns(pluginModule);214 sinon.stub(tractorLogger, 'info');215 let plugins = loadPlugins();216 let [test] = plugins;217 expect(() => {218 test.run();219 }).to.not.throw();220 fs.readdirSync.restore();221 module._load.restore();222 tractorLogger.info.restore();223 });224 it('should not overwrite an existing `run` function', () => {225 let nodeModules = ['tractor-plugin-test'];226 let pluginModule = {227 run: NOOP228 };229 sinon.stub(fs, 'readdirSync').returns(nodeModules);230 sinon.stub(module, '_load').returns(pluginModule);231 sinon.stub(pluginModule, 'run');232 sinon.stub(tractorLogger, 'info');233 let plugins = loadPlugins();234 let [test] = plugins;235 test.run();236 expect(pluginModule.run).to.have.been.called();237 fs.readdirSync.restore();238 module._load.restore();239 tractorLogger.info.restore();240 });241 it('should have a default `serve` function that is a noop', () => {242 let nodeModules = ['tractor-plugin-test'];243 let pluginModule = {};244 sinon.stub(fs, 'readdirSync').returns(nodeModules);245 sinon.stub(module, '_load').returns(pluginModule);246 sinon.stub(tractorLogger, 'info');247 let plugins = loadPlugins();248 let [test] = plugins;249 expect(() => {250 test.serve();251 }).to.not.throw();252 fs.readdirSync.restore();253 module._load.restore();254 tractorLogger.info.restore();255 });256 it('should not overwrite an existing `serve` function', () => {257 let nodeModules = ['tractor-plugin-test'];258 let pluginModule = {259 serve: NOOP260 };261 sinon.stub(fs, 'readdirSync').returns(nodeModules);262 sinon.stub(module, '_load').returns(pluginModule);263 sinon.stub(pluginModule, 'serve');264 sinon.stub(tractorLogger, 'info');265 let plugins = loadPlugins();266 let [test] = plugins;267 test.serve();268 expect(pluginModule.serve).to.have.been.called();269 fs.readdirSync.restore();270 module._load.restore();271 tractorLogger.info.restore();272 });273 it('should have a default `upgrade` function that is a noop', () => {274 let nodeModules = ['tractor-plugin-test'];275 let pluginModule = {};276 sinon.stub(fs, 'readdirSync').returns(nodeModules);277 sinon.stub(module, '_load').returns(pluginModule);278 sinon.stub(tractorLogger, 'info');279 let plugins = loadPlugins();280 let [test] = plugins;281 expect(() => {282 test.upgrade();283 }).to.not.throw();284 fs.readdirSync.restore();285 module._load.restore();286 tractorLogger.info.restore();287 });288 it('should not overwrite an existing `upgrade` function', () => {289 let nodeModules = ['tractor-plugin-test'];290 let pluginModule = {291 upgrade: NOOP292 };293 sinon.stub(fs, 'readdirSync').returns(nodeModules);294 sinon.stub(module, '_load').returns(pluginModule);295 sinon.stub(pluginModule, 'upgrade');296 sinon.stub(tractorLogger, 'info');297 let plugins = loadPlugins();298 let [test] = plugins;299 test.upgrade();300 expect(pluginModule.upgrade).to.have.been.called();301 fs.readdirSync.restore();302 module._load.restore();303 tractorLogger.info.restore();304 });305 it('should try to load the UI bundle and set the `hasUI` flag to true if it works', () => {306 let nodeModules = ['tractor-plugin-test'];307 let pluginModule = {};308 sinon.stub(fs, 'accessSync').returns(true);309 sinon.stub(fs, 'readdirSync').returns(nodeModules);310 sinon.stub(module, '_load').returns(pluginModule);311 sinon.stub(process, 'cwd').returns('.');312 sinon.stub(tractorLogger, 'info');313 let plugins = loadPlugins();314 let [test] = plugins;315 expect(test.script).to.equal(path.join('node_modules', 'tractor-plugin-test', 'dist', 'client', 'bundle.js'));316 expect(test.description.hasUI).to.equal(true);317 fs.accessSync.restore();318 fs.readdirSync.restore();319 module._load.restore();320 process.cwd.restore();321 tractorLogger.info.restore();322 });323 it('should try to load the UI bundle and set the `hasUI` flag to false if it fails', () => {324 let nodeModules = ['tractor-plugin-test'];325 let pluginModule = {};326 sinon.stub(fs, 'accessSync').throws(new Error());327 sinon.stub(fs, 'readdirSync').returns(nodeModules);328 sinon.stub(module, '_load').returns(pluginModule);329 sinon.stub(process, 'cwd').returns('.');330 sinon.stub(tractorLogger, 'info');331 let plugins = loadPlugins();332 let [test] = plugins;333 expect(test.description.hasUI).to.equal(false);334 fs.accessSync.restore();335 fs.readdirSync.restore();336 module._load.restore();337 process.cwd.restore();338 tractorLogger.info.restore();339 });340 });...

Full Screen

Full Screen

test_factory.py

Source:test_factory.py Github

copy

Full Screen

...38 self.assertEqual(ldr.catalog, {})39 @patch('builtins.__import__')40 @patch('os.path.isdir')41 @patch('os.listdir')42 def test__load(self, _listdir, _isdir, _import):43 listing = [44 ['p1', Mock(__name__='p1', PROVIDES=['A', 'B'])],45 ['p2', Mock(__name__='p2', PROVIDES=['C', 'D'])],46 ['p3', Mock(__name__='p3', PROVIDES=['E', 'F'])],47 ['p4', Mock(__name__='p4', PROVIDES=['G', 'H'])],48 ['p5', AttributeError],49 ['p6', ImportError],50 ['f1', None],51 ]52 loaded = self._loaded(listing)53 def isdir(p):54 return os.path.basename(p).startswith('p')55 _listdir.return_value = [p[0] for p in listing]56 _isdir.side_effect = isdir57 _import.side_effect = [p[1] for p in listing]58 _list, catalog = Loader._load()59 self.assertEqual(_list, loaded[0])60 self.assertEqual(catalog, loaded[1])61 def _loaded(self, listing):62 _list = []63 catalog = {}64 for name, pkg in listing:65 if not name.startswith('p'):66 continue67 if not isinstance(pkg, Mock):68 continue69 _list.append(pkg)70 catalog[name] = pkg71 catalog['.'.join((PACKAGE, name))] = pkg72 for c in pkg.PROVIDES:73 catalog[c] = pkg74 return _list, catalog75 @patch('gofer.messaging.adapter.factory.Loader._load')76 def test_load(self, _load):77 _load.return_value = ([], {})78 ldr = Loader()79 _list, catalog = ldr.load()80 _load.assert_called_with()81 self.assertEqual(_list, _load.return_value[0])82 self.assertEqual(catalog, _load.return_value[1])83 self.assertEqual(ldr.list, _load.return_value[0])84 self.assertEqual(ldr.catalog, _load.return_value[1])85 @patch('gofer.messaging.adapter.factory.Loader._load')86 def test_already_loaded(self, _load):87 ldr = Loader()88 ldr.list = [1, 2]89 ldr.catalog = {'A': 1, 'B': 2}90 _list, catalog = ldr.load()...

Full Screen

Full Screen

test_decode_data.py

Source:test_decode_data.py Github

copy

Full Screen

...4class TestDecodeData(unittest.TestCase):5 """Functionally tests the logic of _parse_values6 Focuses on string values, to ignore conversion logic.7 """8 def _load(self, data, n_attribs=1):9 txt = textwrap.dedent('''10 @RELATION testing11 {attribs}12 @DATA13 {data}14 ''').format(attribs='\n'.join('@ATTRIBUTE x%d STRING' % i15 for i in range(n_attribs)),16 data=data)17 return arff.load(txt)['data']18 def assertLoadsAs(self, data, expected, n_attribs=1):19 result = self._load(data, n_attribs)20 self.assertListEqual(result, expected)21 def test_quotes(self):22 self.assertLoadsAs("""'ENACT.NOGOPMAJ,2017'""",23 [['ENACT.NOGOPMAJ,2017']])24 self.assertLoadsAs('''"ENACT.NOGOPMAJ,2017"''',25 [['ENACT.NOGOPMAJ,2017']])26 self.assertLoadsAs(''' 'A','B' , '"','C,D' ''',27 [['A', 'B', '"', 'C,D']],28 n_attribs=4)29 def test_quotes_sparse(self):30 self.assertLoadsAs("""{0 'ENACT.NOGOPMAJ,2017'}""",31 [['ENACT.NOGOPMAJ,2017']])32 self.assertLoadsAs('''{0 "ENACT.NOGOPMAJ,2017"}''',33 [['ENACT.NOGOPMAJ,2017']])...

Full Screen

Full Screen

loader.js

Source:loader.js Github

copy

Full Screen

1(function(w) {2 var _load = {};3 _load.isMobile = /mobile/i.test(navigator.userAgent);4 _load.isIE = (/MSIE/i.test(navigator.userAgent));5 _load.isDevel = true;6 _load.t = (_load.isDevel) ? '' : 'min.';7 _load.s3 = (_load.isDevel) ? '' : 'http://istitchapp.s3-website-us-east-1.amazonaws.com/pub';8 /**9 * Import Javascript10 */11 _load.requireScript = function(f, c) {12 var head = document.getElementsByTagName("head")[0];13 var script = document.createElement('script');14 var cb = (c) ? c : function() {15 };16 script.src = '' + f;17 script.type = 'text/javascript';18 script.onload = cb;19 script.onreadystatechange = function() {20 if (this.readyState == 'complete') {21 cb();22 }23 }24 head.appendChild(script);25 //head.parentNode.insertBefore(script);26 }27 /**28 * Import CSS29 */30 _load.requireStyle = function(f, c) {31 var head = document.getElementsByTagName("head")[0];32 var style = document.createElement('link');33 var cb = (c) ? c : function() {34 };35 style.href = '' + f;36 style.rel = 'stylesheet';37 style.onload = cb;38 style.onreadystatechange = function() {39 if (this.readyState == 'complete') {40 cb();41 }42 }43 head.appendChild(style);44 //head.parentNode.insertBefore(style);45 }46 /**47 * Console48 */49 if ( typeof console == "undefined") {50 this.console = {51 log : function() {52 }53 };54 }55 /**56 * Simple mobile / desktop switch57 */58 if (_load.isMobile) {59 //MOBILE60 /**61 * Android issue62 * Don't use callback in css files or you you're gonna have a bad time!63 */64 _load.requireStyle(_load.s3+'/css/mobile.' + _load.t + 'css', false);65 _load.requireStyle(_load.s3+'/css/themes/my-custom-theme.min.css', false);66 _load.requireStyle('http://code.jquery.com/mobile/1.3.0/jquery.mobile.structure-1.3.0.min.css', false);67 //_load.requireStyle('http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css',false);68 _load.requireScript('http://code.jquery.com/jquery-1.9.1.min.js', function() {69 _load.requireScript('http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js', function() {70 _load.requireScript(_load.s3+'/js/stitch.' + _load.t + 'js', function() {71 _load.requireScript(_load.s3+'/js/mobile.' + _load.t + 'js', false);72 });73 });74 });75 /*_load.requireScript('/js/lib/binaryajax.min.js', function() {76 _load.requireScript('/js/lib/canvasResize.min.js', function() {77 _load.requireScript('/js/lib/exif.min.js', function() {78 _load.requireScript('/js/stitch.' + _load.t + 'js', false);79 });80 });81 });*/82 _load.requireScript(_load.s3+'/js/lib/canvasResizeAll.min.js', false);83 } else {84 //DESKTOP85 _load.requireStyle('http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.no-icons.min.css', function() {86 _load.requireStyle('http://netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css', function() {87 _load.requireStyle(_load.s3+'/css/desktop.' + _load.t + 'css', false);88 });89 });90 _load.requireScript('http://code.jquery.com/jquery-1.9.1.min.js', function() {91 _load.requireScript('http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js', function() {92 _load.requireScript(_load.s3+'/js/lib/routie/routie.min.js', function() {93 _load.requireScript(_load.s3+'/js/stitch.' + _load.t + 'js', function() {94 _load.requireScript(_load.s3+'/js/desktop.' + _load.t + 'js', function() {95 });96 });97 });98 });99 });100 //IF MSIE than there is no need to load libs for image processing :(101 if (!(_load.isIE)) {102 /*_load.requireScript('/js/lib/binaryajax.min.js', function() {103 _load.requireScript('/js/lib/canvasResize.js', function() {104 _load.requireScript('/js/lib/exif.min.js', function() {105 });106 });107 });*/108 _load.requireScript(_load.s3+'/js/lib/canvasResizeAll.min.js', false);109 }110 }111})(window);112/**113 * GOOGLE ANALYTICS114 */115var _gaq = _gaq || [];116_gaq.push(['_setAccount', (/istitchapp/i.test(document.location)) ? 'UA-39213885-1' : 'UA-XXXXX-Y']);117_gaq.push(['_setCustomVar', 1, 'APP', (/mobile/i.test(navigator.userAgent)) ? 'Mobile' : 'Desktop', 1]);118_gaq.push(['_trackPageview']);119(function() {120 var ga = document.createElement('script');121 ga.type = 'text/javascript';122 ga.async = true;123 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';124 var s = document.getElementsByTagName('script')[0];125 s.parentNode.insertBefore(ga, s);...

Full Screen

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 prospector 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