Beispiel #1
0
    def _warn_if_reactor_is_not_running(cls):
        if reactor.running or util.in_unittest():
            return

        msg = 'connection attempted without running Twisted reactor'
        detail = ('The reconnect mechanism is based on having a running Twisted reactor. '
                  'Either ensure that Twisted is running, don\'t expect reconnecting to happen or '
                  'implement a checker thread.')
        warning = exceptions.PipedWarning(msg, detail)
        warnings.warn(warning)
Beispiel #2
0
def _plugin_error_handler(package):
    f = failure.Failure()
    f.trap(ImportError)

    logger = log.error

    # set the logger to info when running unit tests in order to avoid flooding
    if util.in_unittest():
        logger = log.info

    logger('Failed loading plugins from package %r: %s(%s)' % (package.__name__, f.type.__name__, f.getErrorMessage()))
    def configure(self, runtime_environment):
        self.runtime_environment = runtime_environment
        self.dependency_manager = runtime_environment.dependency_manager
        self.persisted_contexts = runtime_environment.get_configuration_value('persisted_contexts', dict())

        # State that we can provide all configured contexts.
        resource_manager = runtime_environment.resource_manager
        for context_name, context in self.persisted_contexts.items():
            resource_manager.register('persisted_context.%s' % context_name, provider=self)

        # Hook up the shutdown-event
        if not util.in_unittest():
            reactor.addSystemEventTrigger('before', 'shutdown', self.persist_contexts)
Beispiel #4
0
    def _load_config(self, config, visited_files):
        """ Handles the configuration object, including referenced configurations as
            specified. Also handles replacement of special options like runmodes.
        """
        current_configuration_file = visited_files[-1]

        # if a configuration file does not contain anything, yaml.load returns None,
        # but we consider an empty configuration file to be an empty dict instead
        if config is None:
            config = dict()

        self._fail_if_configuration_is_invalid(config, current_configuration_file)

        includes = config.get('includes', dict())

        config = self._load_includes(config, includes, visited_files)

        # see if we have any special options for this mode
        if 'runmodes' in config:
            # currently we only support "unittest" as the runmode:
            if util.in_unittest():
                config = util.merge_dicts(config, config['runmodes'].get('unittest', dict()), replace_primitives=True)

        return config
Beispiel #5
0
 def test_trial_detection(self):
     self.assertTrue(util.in_unittest(), 'Failed to detect that we are running trial')