Exemple #1
0
    def __init__(self, filepath):
        """Initializes a node set object from a node sets file.

        Args:
            filepath (str/Path): Path to a SONATA node sets file.

        Returns:
            NodeSets: A NodeSets object.
        """
        self.content = utils.load_json(filepath)
        self.resolved = _resolve(self.content)
Exemple #2
0
    def __init__(self, filepath):
        """Initializes a Config object from a path to the actual config.

        Args:
            filepath (str): Path the SONATA configuration file.

        Returns:
             Config: A Config object.
        """
        configdir = str(Path(filepath).parent.resolve())
        content = utils.load_json(str(filepath))
        self.manifest = Config._resolve_manifest(content.pop('manifest', {}),
                                                 configdir)
        self.content = content
Exemple #3
0
    def __init__(self, config):
        """Initializes a Config object from a path to the actual config.

        Args:
            config (str/dict): Path to the SONATA configuration file or dict containing the config.

        Returns:
             Config: A Config object.
        """
        if isinstance(config, dict):
            content = config.copy()
            configdir = None
        else:
            configdir = str(Path(config).parent.resolve())
            content = utils.load_json(str(config))
        self.manifest = Config._resolve_manifest(content.pop('manifest', {}),
                                                 configdir)
        self.content = content
Exemple #4
0
def _resolve_config(filepath):
    """Resolve the config file if global ('network' and 'simulation' keys).

    Args:
        filepath (str): the path to the configuration file.

    Returns:
        dict: the complete simulation config file.
    """
    filepath = Path(filepath)
    content = utils.load_json(str(filepath))
    parent = filepath.parent
    if "simulation" in content and "network" in content:
        simulation_path = parent / content["simulation"]
        res = Config(str(simulation_path)).resolve()
        if "network" not in res:
            res["network"] = str(parent / content["network"])
        return res
    return Config(str(filepath)).resolve()
Exemple #5
0
def test_load_json():
    actual = test_module.load_json(str(TEST_DATA_DIR / 'circuit_config.json'))
    assert actual['manifest']['$BASE_DIR'] == '.'
Exemple #6
0
def test_load_json():
    actual = test_module.load_json(str(TEST_DATA_DIR / "circuit_config.json"))
    assert actual["manifest"]["$BASE_DIR"] == "."