Ejemplo n.º 1
0
 def test_parses_base_config(self):
     e = element.from_config(self.base_config)
     self.assertEqual(e.name, "test")
     self.assertEqual(e.plottable, False)
     self.assertEqual(e.display_type,
                      Element.DISPLAYTYPE.CONTINUOUS)  # default value
     self.assertEqual(e.offset, 0.0)  # default value
     self.assertEqual(e.scale_factor, 1.0)  # default value
     self.assertEqual(e.default_min, -10.5)
Ejemplo n.º 2
0
def from_config(config: configparser.ConfigParser) -> DataStream:
    """
    Construct a DataStream from a configuration file

    Args:
        config: parsed *.conf file

    Returns: DataStream

    Raises: ConfigurationError

    """
    try:
        main_configs: configparser.ConfigParser = config["Main"]
    except KeyError as e:
        raise ConfigurationError("Missing section [%s]" % e) from e
    try:
        datatype = validate_datatype(main_configs["datatype"])
        keep_us = validate_keep(main_configs.get("keep", fallback="all"))
        decimate = main_configs.getboolean("decimate", fallback=True)
        name = validate_name(main_configs["name"])
        description = main_configs.get("description", fallback="")
        stream = DataStream(name=name,
                            description=description,
                            datatype=datatype,
                            keep_us=keep_us,
                            decimate=decimate)
    except KeyError as e:
        raise ConfigurationError("[Main] missing %s" % e.args[0]) from e
    # now try to load the elements
    element_configs = filter(lambda sec: re.match(r"Element\d", sec),
                             config.sections())
    index = 0
    for name in element_configs:
        try:
            e = element.from_config(config[name])
            e.index = index
            index += 1
            stream.elements.append(e)
        except ConfigurationError as e:
            raise ConfigurationError("element <%s> %s" % (name, e)) from e
    # make sure we have at least one element
    if len(stream.elements) == 0:
        raise ConfigurationError(
            "missing element configurations, must have at least one")
    return stream
Ejemplo n.º 3
0
 def evaluate_bad_values(self, setting_name, bad_settings):
     for setting in bad_settings:
         with self.subTest(setting=setting):
             self.base_config[setting_name] = setting
             with self.assertRaisesRegex(ConfigurationError, setting_name):
                 element.from_config(self.base_config)
Ejemplo n.º 4
0
 def test_sensible_bounds(self):
     """default_min<default_max or both == 0 for autoscale"""
     self.base_config['default_min'] = '10'
     self.base_config['default_max'] = '-10'
     with self.assertRaisesRegex(ConfigurationError, "default_min"):
         element.from_config(self.base_config)
Ejemplo n.º 5
0
 def test_must_have_name(self):
     self.base_config['name'] = ""
     with self.assertRaisesRegex(ConfigurationError, "name"):
         element.from_config(self.base_config)