Esempio n. 1
0
def test_argparse_yamlpath():
    modules_to_import, config_value_overrides, yaml_file_paths = handle_args(
        "-f", "test1.yml",
        "-f", "test2.yml")
    assert len(modules_to_import) == 0
    assert len(config_value_overrides) == 0
    assert len(yaml_file_paths) == 2
Esempio n. 2
0
    def __init__(self, *arguments, runtime_overrides: List[Tuple[str, str, Any]] = None):
        """
        Construct a context from command line arguments.

        * `arguments`: A series of command line arguments which can be parsed
         by the ravestate command line parser (see argparse.py).
        * `runtime_overrides`: A list of config overrides in the form of (modulename, key, value).
         Can be used to set config entries to values other than strings or lists like in command line arguments.
         An example use-case is a module that starts a new context (in separate process) and can set
         config entries to Connection Objects to enable communication between old and new context.
        """
        modules, overrides, config_files = argparse.handle_args(*arguments)
        self._config = Configuration(config_files)
        self._core_config = {
            self.import_modules_config: [],
            self.tick_rate_config: 20
        }
        self._config.add_conf(Module(name=self.core_module_name, config=self._core_config))
        self._lock = RLock()
        self._shutdown_flag = Event()
        self._properties = dict()
        self._spikes = set()
        self._act_per_state_per_signal_age = dict()
        self._signal_causes = dict()
        self._activations_per_state = dict()
        self._run_task = None

        # Register default signals
        for signal in self._default_signals:
            self._add_sig(signal)

        # Register default properties
        for prop in self._default_properties:
            self.add_prop(prop=prop)

        # Load required modules
        for module_name in self._core_config[self.import_modules_config] + modules:
            self.add_module(module_name)

        # Set required config overrides
        for module_name, key, value in overrides:
            self._config.set(module_name, key, value)
        # Set additional config runtime overrides
        if runtime_overrides:
            for module_name, key, value in runtime_overrides:
                self._config.set(module_name, key, value)

        if self._core_config[self.tick_rate_config] < 1:
            logger.error("Attempt to set core config `tickrate` to a value less-than 1!")
            self._core_config[self.tick_rate_config] = 1
Esempio n. 3
0
def test_argparse_define():
    with LogCapture(attributes=strip_prefix) as log_capture:
        modules_to_import, config_value_overrides, yaml_file_paths = handle_args(
            "test",
            "-d", "x",
            "-d", "x", "y", "z",
            "-d", "x", "y", "1", "2")
        log_capture.check("Not enough values for -d argument: expecting 3, got 1!")
        assert len(modules_to_import) == 1
        assert len(config_value_overrides) == 2
        assert len(yaml_file_paths) == 0
        assert "test" in modules_to_import
        assert ("x", "y", "z") in config_value_overrides
        assert ("x", "y", ("1", "2")) in config_value_overrides
Esempio n. 4
0
    def __init__(self, *arguments):
        """
        Construct a context from command line arguments.

        * `arguments`: A series of command line arguments which can be parsed
         by the ravestate command line parser (see argparse.py).
        """
        modules, overrides, config_files = argparse.handle_args(*arguments)
        self._config = Configuration(config_files)
        self._core_config = {
            self._import_modules_config: [],
            self._tick_rate_config: 20
        }
        self._config.add_conf(Module(name=self._core_module_name, config=self._core_config))
        self._lock = Lock()
        self._shutdown_flag = Event()
        self._properties = dict()
        self._spikes = set()
        self._act_per_state_per_signal_age = dict()
        self._signal_causes = dict()
        self._activations_per_state = dict()
        self._run_task = None

        # Register default signals
        for signal in self._default_signals:
            self._add_sig(signal)

        # Register default properties
        for prop in self._default_properties:
            self.add_prop(prop=prop)

        # Set required config overrides
        for module_name, key, value in overrides:
            self._config.set(module_name, key, value)
        if self._core_config[self._tick_rate_config] < 1:
            logger.error("Attempt to set core config `tickrate` to a value less-than 1!")
            self._core_config[self._tick_rate_config] = 1

        # Load required modules
        for module_name in self._core_config[self._import_modules_config]+modules:
            self.add_module(module_name)
Esempio n. 5
0
def test_argparse_empty():
    modules_to_import, config_value_overrides, yaml_file_paths = handle_args()
    assert len(modules_to_import) == 0
    assert len(config_value_overrides) == 0
    assert len(yaml_file_paths) == 0
Esempio n. 6
0
def test_argparse_simple():
    modules_to_import, config_value_overrides, yaml_file_paths = handle_args("test")
    assert len(modules_to_import) == 1
    assert len(config_value_overrides) == 0
    assert len(yaml_file_paths) == 0
    assert "test" in modules_to_import