def test_return_correct_type(self): from pyfusion import config # a setting of type float: sample_freq = config.pf_get('Diagnostic', 'test_types', 'sample_freq') self.assertTrue(type(sample_freq) == float) # a setting of type int: n_samples = config.pf_get('Diagnostic', 'test_types', 'n_samples') self.assertTrue(type(n_samples) == int) # a setting of type boolean: test_bool = config.pf_get('Diagnostic', 'test_types', 'testboolean') self.assertTrue(type(test_bool) == bool) # test unknown type raises exception from pyfusion.conf.exceptions import UnknownVariableTypeError self.assertRaises(UnknownVariableTypeError, config.pf_get, 'Diagnostic', 'test_types', 'unknowntype')
def test_config_as_dict(self): from pyfusion import config, conf config_option_list = config.pf_options('Acquisition', 'test_fakedata') config_map = lambda x: (x, config.pf_get('Acquisition', 'test_fakedata', x)) config_dict_1 = dict(map(config_map, config_option_list)) config_dict_2 = conf.utils.get_config_as_dict('Acquisition', 'test_fakedata') self.assertEqual(config_dict_1, config_dict_2)
def test_config_as_dict(self): from pyfusion import config, conf config_option_list = config.pf_options('Acquisition', 'test_fakedata') config_map = lambda x: ( x, config.pf_get('Acquisition', 'test_fakedata', x)) config_dict_1 = dict(map(config_map, config_option_list)) config_dict_2 = conf.utils.get_config_as_dict('Acquisition', 'test_fakedata') self.assertEqual(config_dict_1, config_dict_2)
def testDeviceConnection(self): """Check that using config loads the correct acquisition.""" from pyfusion.devices.base import Device test_device = Device('TestDevice') from pyfusion import conf, config acq_name = config.pf_get('Device', 'TestDevice', 'acq_name') test_acq = conf.utils.import_setting('Acquisition', acq_name, 'acq_class') self.assertTrue(isinstance(test_device.acquisition, test_acq)) # test that device.acq shortcut works self.assertEqual(test_device.acquisition, test_device.acq)
def testDeviceConnection(self): """Check that using config loads the correct acquisition.""" from pyfusion.devices.base import Device test_device = Device("TestDevice") from pyfusion import conf, config acq_name = config.pf_get("Device", "TestDevice", "acq_name") test_acq = conf.utils.import_setting("Acquisition", acq_name, "acq_class") self.assertTrue(isinstance(test_device.acquisition, test_acq)) # test that device.acq shortcut works self.assertEqual(test_device.acquisition, test_device.acq)
def getdata(self, shot, config_name=None, **kwargs): """Get the data and return prescribed subclass of BaseData. :param shot: shot number :param config_name: ?? bdb name of a fetcher class in the configuration file :returns: an instance of a subclass of \ :py:class:`~pyfusion.data.base.BaseData` or \ :py:class:`~pyfusion.data.base.BaseDataSet` This method needs to know which data fetcher class to use, if a config_name argument is supplied then the ``[Diagnostic:config_name]`` section must exist in the configuration file and contain a ``data_fetcher`` class specification, for example:: [Diagnostic:H1_mirnov_array_1_coil_1] data_fetcher = pyfusion.acquisition.H1.fetch.H1DataFetcher mds_path = \h1data::top.operations.mirnov:a14_14:input_1 coords_cylindrical = 1.114, 0.7732, 0.355 coord_transform = H1_mirnov If a ``data_fetcher`` keyword argument is supplied, it overrides the configuration file specification. The fetcher class is instantiated, including any supplied keyword arguments, and the result of the ``fetch`` method of the fetcher class is returned. """ from pyfusion import config # if there is a data_fetcher arg, use that, otherwise get from config if 'data_fetcher' in kwargs: fetcher_class_name = kwargs['data_fetcher'] else: fetcher_class_name = config.pf_get('Diagnostic', config_name, 'data_fetcher') fetcher_class = import_from_str(fetcher_class_name) ## Problem: no check to see if it is a diag of the right device!?? d = fetcher_class(self, shot, config_name=config_name, **kwargs).fetch() d.history += "\n:: shot: {s} :: config: {c}".format(s=shot, c=config_name) return d
def test_kwarg_config_handler(self): from pyfusion.conf.utils import kwarg_config_handler from pyfusion import config # config values should be overridden by kwargs # test against [Device:TestDevice] # take acquisition from config, and database from kwarsg # give an additional kwarg not in config test_kwargs = {'database': 'dummy_database', 'other_var': 'other_val'} output_vars = kwarg_config_handler('Device', 'TestDevice', **test_kwargs) #make sure test_kwargs are returned for kwarg_item in test_kwargs.items(): self.assertTrue(kwarg_item in output_vars.items()) # make sure that config vars not in test_kwargs are included in kwargs for config_var in config.pf_options('Device', 'TestDevice'): if not config_var in test_kwargs.keys(): self.assertEqual( output_vars[config_var], config.pf_get('Device', 'TestDevice', config_var))
def getdata(self, shot, config_name=None, **kwargs): """Get the data and return prescribed subclass of BaseData. :param shot: shot number :param config_name: ?? bdb name of a fetcher class in the configuration file :returns: an instance of a subclass of \ :py:class:`~pyfusion.data.base.BaseData` or \ :py:class:`~pyfusion.data.base.BaseDataSet` This method needs to know which data fetcher class to use, if a config_name argument is supplied then the ``[Diagnostic:config_name]`` section must exist in the configuration file and contain a ``data_fetcher`` class specification, for example:: [Diagnostic:H1_mirnov_array_1_coil_1] data_fetcher = pyfusion.acquisition.H1.fetch.H1DataFetcher mds_path = \h1data::top.operations.mirnov:a14_14:input_1 coords_cylindrical = 1.114, 0.7732, 0.355 coord_transform = H1_mirnov If a ``data_fetcher`` keyword argument is supplied, it overrides the configuration file specification. The fetcher class is instantiated, including any supplied keyword arguments, and the result of the ``fetch`` method of the fetcher class is returned. """ from pyfusion import config # if there is a data_fetcher arg, use that, otherwise get from config if kwargs.has_key('data_fetcher'): fetcher_class_name = kwargs['data_fetcher'] else: fetcher_class_name = config.pf_get('Diagnostic', config_name, 'data_fetcher') fetcher_class = import_from_str(fetcher_class_name) d = fetcher_class(self, shot, config_name=config_name, **kwargs).fetch() d.history += "\n:: shot: %d\n:: config: %s" % (shot, config_name) return d
def test_kwarg_config_handler(self): from pyfusion.conf.utils import kwarg_config_handler from pyfusion import config # config values should be overridden by kwargs # test against [Device:TestDevice] # take acquisition from config, and database from kwarsg # give an additional kwarg not in config test_kwargs = {'database': 'dummy_database', 'other_var': 'other_val'} output_vars = kwarg_config_handler('Device', 'TestDevice', **test_kwargs) #make sure test_kwargs are returned for kwarg_item in test_kwargs.items(): self.assertTrue(kwarg_item in output_vars.items()) # make sure that config vars not in test_kwargs are included in kwargs for config_var in config.pf_options('Device', 'TestDevice'): if not config_var in test_kwargs.keys(): self.assertEqual(output_vars[config_var], config.pf_get('Device', 'TestDevice', config_var))