utility function to generate a mock plugin object
556753
function mockPlugin(name, deferInit = false) {
        class MockPlugin {
            constructor(params, ws) {
                this.ws = ws;
                // using the instance factory unfortunately makes it
                // difficult to use the spyOn function, so we use this
                // instead
                this.isInitialised = false;
            }
            init() {
                this.isInitialised = true;
            }
            destroy() {}
        }
        return {
            name,
            deferInit,
            staticProps: {
                [`${name}Static`]: 'static property value'
            },
            instance: MockPlugin
        };
    }
758832
function mock (mock) {
  if (mock === false) {
    mocking = false
  } else {
    mocking = true
    cli.stderr = ''
    cli.stdout = ''
  }
}
943418
function MockRpc(endpoint) {
    events.EventEmitter.call(this);
    this._endpoint = endpoint;
    this._handlers = {};
    glNetwork[endpoint] = this;
}
1239407
function _loadMock (mockData, options) {
    // require mockData to be object
    if (!mockData || typeof mockData !== 'object' || !mockData.data || typeof mockData.data !== 'object') {
        if (options.ignoreMockDataErrors) {
            return
        }
        else {
            throw new Error('automock error: mock data must be object')
        }
    }
    // require mockData to have type
    if (typeof mockData.type !== 'string') {
        if (options.ignoreMockDataErrors) {
            return
        }
        else {
            throw new Error('automock error: mock data must have type')
        }
    }
    // get automock module name by mock data type
    var moduleName = moduleNameByMockDataType[mockData.type]
    // require type to be defined with module name
    if (!moduleName) {
        if (options.ignoreInvalidMockDataType) {
            return
        }
        else {
            throw new Error('automock error: invalid mock data type - '+mockData.type)
        }
    }
    // load mock into target module
    automock.module[moduleName].loadMock(mockData, options)
}
275682
def from_plugin_classname(plugin_classname, exclude_lines_regex=None, **kwargs):
    
    klass = globals()[plugin_classname]

    # Make sure the instance is a BasePlugin type, before creating it.
    if not issubclass(klass, BasePlugin):
        raise TypeError

    try:
        instance = klass(exclude_lines_regex=exclude_lines_regex, **kwargs)
    except TypeError:
        log.warning(
            'Unable to initialize plugin!',
        )
        raise

    return instance
1278154
function _withPlugins(fn) {
  return function() {
    const args = Array.from(arguments);
    const opts = args[1] || {};
    args[1] = Object.assign({}, opts, {
      plugins: loadPlugins(opts.plugins, opts.pluginSearchDirs)
    });
    return fn.apply(null, args);
  };
}
1164017
function withSandbox (config, fn) {
  return () => {
    const S = {
      mocks: {},
      verify () {
        return this.sandbox.verify();
      },
    };
    beforeEach(function beforeEach () {
      S.sandbox = sinon.createSandbox();
      S.mocks[SANDBOX] = S.sandbox;
      for (let [key, value] of _.toPairs(config.mocks)) {
        S.mocks[key] = S.sandbox.mock(value);
      }
    });
    afterEach(function afterEach () {
      S.sandbox.restore();
      for (let k of _.keys(S.mocks)) {
        delete S.mocks[k];
      }
      delete S.mocks[SANDBOX];
    });
    fn(S);
  };
}
856759
def call(self, methodname, *args, **kwargs):
        """"""

        for plugin in self._plugins:
            method = getattr(plugin, methodname, None)
            if method is None:
                continue
            yield method(*args, **kwargs)
928298
function plugin(options) {
    if (!options || typeof options !== 'object') {
        throw new Error('AjvMoment#plugin requires options');
    }
    if (!options.ajv) {
        throw new Error(`AjvMoment#plugin options requries an 'ajv' attribute (ajv instance)`);
    }
    if (!options.moment) {
        throw new Error(`AjvMoment#plugin options requries a 'moment' attribute (moment.js)`);
    }
    const { ajv, moment } = options;
    ajv.moment = moment;
    const keywordSettings = {
        type: 'string',
        statements: true,
        errors: true,
        inline
    };
    if (ajv) {
        ajv.addKeyword('moment', keywordSettings);
    }
    return keywordSettings;
}
279788
def _create_mock(self, endpoint_desc, session, request_params, mock_desc, loop):
        
        try:
            mock_def = mock_manager.next_mock(self.service_client.name,
                                              endpoint_desc['endpoint'])

            if isinstance(mock_def, PatchMockDescDefinition):
                mock_desc.update(mock_def.patch)
            else:
                return mock_def.mock
        except NoMock:
            pass

        return self.loader.factory(mock_desc.get('mock_type'),
                                   endpoint_desc, session,
                                   request_params, mock_desc,
                                   loop=loop)
638326
def import_mock(name, *args, **kwargs):
    """"""
    if any(name.startswith(s) for s in mock_modules):
        return MockModule()
    return orig_import(name, *args, **kwargs)
124024
def _generate_constructor(cls, names):
        """"""

        cache = cls._constructors
        if names in cache:
            return cache[names]
        elif len(cache) > 3:
            cache.clear()

        func = generate_constructor(cls, names)
        cache[names] = func
        return func
360969
function createNewDebugger(scopename, opts = {}) {
    const handler = {

        get(target, propKey, receiver) {

            return function (...args) {

                const origMethod = target[propKey];

                // Always return immediately all but the specified console methods.
                if (!propKey.match(/debug|log|info|group|groupEnd/)) {
                    if(opts.quiet) {return}
                    const result = origMethod.apply(this, args);
                    return result
                }
                
                if (typeof localStorage === "undefined") {
                    // "Your environment does not have localStorage"
                    return
                } else if (!localStorage['cth-debug']) {
                    // Returning because no cth-debug variable is set
                    return
                }

                const pattern = globToRegexp(localStorage['cth-debug'])

                if (pattern.test(scopename)) {
                    if(opts.quiet) {return}
                    const result = origMethod.apply(this, args);
                    return result
                } else {
                    // Return null when a call was rejected (mainly for unit tests)
                    return null
                }
            }
        }
    }
    return new Proxy(console, handler)
}
1374945
function withPlugins(fn) {
  return function() {
    const args = Array.from(arguments);
    let plugins = (args[1] && args[1].plugins) || [];
    if (!isArray(plugins)) {
      plugins = Object.values(plugins);
    }
    args[1] = Object.assign({}, args[1], {
      plugins: internalPlugins.concat(plugins)
    });
    return fn.apply(null, args);
  };
}
226787
function plugin(suite) {
	// Instance
	var instance = {
		devices: [],
		// Register the plugin's name
		name: pkg.name
	};
	// Options
	var options = util.extend({}, defaultConfig, suite.options);

	// // Dependencies
	// // Add the plugin's `root`
	// suite.addRoot(path.join(__dirname, 'defaults'));
	// // API
	// suite.api.browser = {};

	// Listen for a new Session creation
	suite.on('create session', function (session) {
		session.on('pre run', function () {
			instance.devices.each = util.forEachSeries(instance.devices);
			// var devices = [];
			// before(function () {
			//   this.plugins.browser = {};
			//   this.plugins.browser.devices = devices;
			//   devices.each = util.forEachSeries(devices);
			// });

			before(function (done) {
				this.timeout(options.timeout);

				// this.plugins[name] = ctx;

				if (!instance.devices.length) {
					// throw new Error(name + ': A device must be in use to run tests.');
					throw new Error('A device must be in use to run tests.');
				}

				// Load the choosen devices
				instance.devices.each(function (device, next) {
					device.start(next);
				}, done);
			});

			after(function (done) {
				instance.devices.each(function (device, next) {
					device.stop(next);
				}, done);
			});
		});
	});

	return instance;
}
1365241
function generate(plugins, dest) {
  const pluginNames = plugins.map((plugin) => {
    return path.basename(plugin, '.js');
  });

  const pluginCombinations = combine(pluginNames);

  pluginCombinations.forEach((pluginCombination) => {
    fs.writeFileSync(
      path.resolve(dest, `${pluginCombination.join(',')}.js`),
      template(pluginCombination),
    );
  });
}
129213
function( mockHandler, requestSettings ) {
			if ( mockHandler.logging === false ||
				 ( typeof mockHandler.logging === 'undefined' && $.mockjaxSettings.logging === false ) ) {
				return;
			}
			if ( window.console && console.log ) {
				var message = 'MOCK ' + requestSettings.type.toUpperCase() + ': ' + requestSettings.url;
				var request = $.extend({}, requestSettings);

				if (typeof console.log === 'function') {
					console.log(message, request);
				} else {
					try {
						console.log( message + ' ' + JSON.stringify(request) );
					} catch (e) {
						console.log(message);
					}
				}
			}
		}