예제 #1
0
 def get_fresh_error_instance(self, comm, error_on_init=False):
     r"""Get CommDriver instance with an ErrorComm parent class."""
     args = [self.get_fresh_name()]
     if self.args is not None:  # pragma: debug
         args.append(self.args)
     # args = self.inst_args
     kwargs = self.inst_kwargs
     kwargs.setdefault('icomm_kwargs', {})
     kwargs.setdefault('ocomm_kwargs', {})
     if 'address' in kwargs:
         del kwargs['address']
     if comm in ['ocomm', 'both']:
         kwargs['ocomm_kwargs'].update(base_comm=None,
                                       new_comm_class='ErrorComm',
                                       error_on_init=error_on_init)
     if comm in ['icomm', 'both']:
         kwargs['icomm_kwargs'].update(base_comm=None,
                                       new_comm_class='ErrorComm',
                                       error_on_init=error_on_init)
     driver_class = import_driver(self.driver)
     if error_on_init:
         nt.assert_raises(MagicTestError, driver_class, *args, **kwargs)
     else:
         inst = driver_class(*args, **kwargs)
         self._extra_instances.append(inst)
         return inst
예제 #2
0
    def createOutputDriver(self, yml):
        r"""Create an output driver instance from the yaml information.

        Args:
            yml (yaml): Yaml object containing driver information.

        Returns:
            object: An instance of the specified driver.

        """
        from cis_interface.drivers import FileOutputDriver
        yml['models'] = []
        if yml['args'] in self._inputchannels:
            yml.setdefault('comm_env', {})
            yml['comm_env'] = self._inputchannels[yml['args']]['instance'].comm_env
            # yml['kwargs'].setdefault('comm_env', {})
            # yml['kwargs']['comm_env'] = self._inputchannels[
            #     yml['args']]['instance'].comm_env
        drv_cls = import_driver(yml['driver'])
        if yml['args'] not in self._inputchannels:
            try:
                assert(issubclass(drv_cls,
                                  FileOutputDriver.FileOutputDriver))
            except AssertionError:
                raise Exception(("Output driver %s is not a subclass of " +
                                 "FileOutputDriver and there is not a " +
                                 "corresponding input channel %s.") % (
                                     yml["name"], yml["args"]))
        else:
            
            # TODO: Add input comm environment variables somehow
            pass
        drv = self.createDriver(yml)
        return drv
예제 #3
0
 def get_fresh_error_instance(self, comm, error_on_init=False):
     r"""Get a driver instance with ErrorComm class for one or both comms."""
     args = [self.get_fresh_name()]
     if self.args is not None:
         args.append(self.args)
     # args = self.inst_args
     kwargs = self.inst_kwargs
     if 'comm_address' in kwargs:
         del kwargs['comm_address']
     if comm in ['ocomm', 'both']:
         kwargs['ocomm_kws'].update(
             base_comm=self.ocomm_name, new_comm_class='ErrorComm',
             error_on_init=error_on_init)
     if comm in ['icomm', 'both']:
         kwargs['icomm_kws'].update(
             base_comm=self.icomm_name, new_comm_class='ErrorComm',
             error_on_init=error_on_init)
     driver_class = import_driver(self.driver)
     if error_on_init:
         nt.assert_raises(MagicTestError, driver_class, *args, **kwargs)
     else:
         inst = driver_class(*args, **kwargs)
         inst.icomm._first_send_done = True
         self._extra_instances.append(inst)
         return inst
예제 #4
0
def test_import_driver():
    r"""Check a few drivers."""
    drvs = [('Driver', Driver.Driver),
            ('ModelDriver', ModelDriver.ModelDriver),
            ('IODriver', IODriver.IODriver)]
    for n, dans in drvs:
        dres = drivers.import_driver(n)
        nt.assert_equal(dres, dans)
예제 #5
0
def is_lang_installed(lang):
    r"""Check to see if cis_interface can run models written in a programming
    language on the current machine.

    Args:
        lang (str): Programming language to check.

    Returns:
        bool: True if models in the provided language can be run on the current
            machine, False otherwise.

    """
    from cis_interface import schema, drivers
    s = schema.get_schema()
    drv = drivers.import_driver(s.language2class[lang])
    return drv.is_installed()
예제 #6
0
 def driver_class(self):
     r"""class: Driver class."""
     return import_driver(self.driver_name)
예제 #7
0
def test_import_driver():
    r"""Test creation of default driver."""
    drivers.import_driver()