Esempio n. 1
0
 def assault(self):
     stats = AssaultStats.from_cfg(
         self.name, self.info.get("assault", Configuration()))
     for equipment in self.equipments:
         stats = stats.update_from_cfg(
             equipment.info.get("assault", Configuration()))
     return stats
Esempio n. 2
0
 def range(self):
     """TODO"""
     stats = RangeStats.from_cfg(self.name,
                                 self.info.get("range", Configuration()))
     for equipment in self.equipments:
         stats = stats.update_from_cfg(
             equipment.info.get("range", Configuration()))
     return stats
Esempio n. 3
0
def _all_tomls():
    file_paths = pathlib.Path(__file__).parent.glob("*.toml")
    toml = Configuration()
    for path in file_paths:
        print(path)
        toml.update_from_file(path)

    return toml
Esempio n. 4
0
def test_ini_handle_int_key_gracefully(cfg_with_int_key):
    """Test that INI format handles int keys gracefully"""
    roundtripped = Configuration.from_str(
        cfg_with_int_key.as_str(format="ini"), format="ini")

    # INI converts integer keys to strings
    assert roundtripped.answer.entry_keys == ["42"]
Esempio n. 5
0
def test_yaml_handle_int_key_gracefully(cfg_with_int_key):
    """Test that YAML format handles int keys gracefully"""
    roundtripped = Configuration.from_str(
        cfg_with_int_key.as_str(format="yaml"), format="yaml")

    # YAML supports integer keys
    assert roundtripped.as_dict() == cfg_with_int_key.as_dict()
Esempio n. 6
0
def test_json_handle_int_key_gracefully(cfg_with_int_key):
    """Test that JSON format handles int keys gracefully"""
    roundtripped = Configuration.from_str(
        cfg_with_int_key.as_str(format="json"), format="json")

    # JSON converts integer keys to strings
    assert roundtripped.answer.entry_keys == ["42"]
    assert roundtripped.long_answer.parts.entry_keys == ["1", "2"]
def generate_powerpoint(template_url, cfg, data, output_path):
    """Generate PowerPoint report from data based on cfg. Store to output_path"""
    template = files.get_url_or_asset(template_url,
                                      local_assets="geong_common.assets")
    template_cfg = Configuration.from_str(template.read_text(), format="toml")
    template_ppt = (template.parent /
                    template_cfg.replace("template")).read_bytes()

    prs = pptx.Presentation(io.BytesIO(template_ppt))
    add_slides(prs, template_cfg, cfg, data)
    prs.save(output_path)
Esempio n. 8
0
def read(cfg_name: str, *directories: pathlib.Path) -> Configuration:
    """Read one configuration from file

    Args:
        cfg_name:     Name of configuration, `.toml`-suffix is added
        directories:  Prioritized list of directories

    Returns:
        A configuration object
    """
    cfg = Configuration(cfg_name)
    for file_path in _config_paths(cfg_name,
                                   [pathlib.Path(d) for d in directories]):
        cfg.update_from_file(file_path)

    if not cfg:
        raise FileNotFoundError(
            f"Configuration {cfg_name!r} not found in {', '.join(directories)}"
        )

    return cfg
Esempio n. 9
0
 def _orders(self, order_type):
     unit_orders = self.info.orders.get(order_type,
                                        Configuration()).as_dict()
     for items in (self.models + self.equipments).as_dict().values():
         item = items[0]
         for speed, orders in (item.info.get("orders_gained",
                                             {}).get(order_type,
                                                     {}).items()):
             for order in orders:
                 if order not in unit_orders.get(speed, []):
                     unit_orders.setdefault(speed, []).append(order)
     return unit_orders
Esempio n. 10
0
def cfg_with_int_key():
    """Configuration with a key that is an integer"""
    return Configuration.from_dict({
        "answer": {
            42: "Life, the Universe, and Everything"
        },
        "long_answer": {
            "parts": {
                1: "The Answer to the Ultimate Question of",
                2: "Life, the Universe, and Everything",
            },
        },
    })
def read_config(cfg_name: str) -> Configuration:
    """Read one configuration from file

    Args:
        cfg_name:  Name of configuration, used for documentation

    Returns:
        A configuration object
    """
    if cfg_name not in _CFGS:
        cfg = _CFGS[cfg_name] = Configuration(cfg_name)
        for file_path in config_paths(cfg_name):
            cfg.update_from_file(file_path)

    return _CFGS[cfg_name]
Esempio n. 12
0
def synthetic_config():
    return Configuration.from_str(
        """
        [models]
        target          = "value"
        label_column    = "type"

          [models.type_1]
          label           = "type_1"
          factors         = ["key"]

            [models.type_1.key]
            label           = "Key"
            values          = ["A", "B", "C"]

          [models.type_2]
          label           = "type_2"
          factors         = []
        """,
        format="toml",
    ).models
Esempio n. 13
0
def test_read_yaml_sources(sample_dir):
    """Test that source is set correctly when reading a YAML file"""
    cfg_path = sample_dir / "sample.yaml"
    cfg = Configuration.from_file(cfg_path)

    assert cfg.sources == {f"{cfg_path} (YAML reader)"}
Esempio n. 14
0
def test_read_yaml(sample_dir):
    """Test that reading a YAML file succeeds"""
    Configuration.from_file(sample_dir / "sample.yaml")
Esempio n. 15
0
def test_read_json_sources(sample_dir):
    """Test that source is set correctly when reading a JSON file"""
    cfg_path = sample_dir / "sample.json"
    cfg = Configuration.from_file(cfg_path)

    assert cfg.sources == {f"{cfg_path} (JSON reader)"}
Esempio n. 16
0
def test_read_json(sample_dir):
    """Test that reading an JSON file succeeds"""
    Configuration.from_file(sample_dir / "sample.json")
Esempio n. 17
0
def test_read_ini_sources(sample_dir):
    """Test that source is set correctly when reading an INI file"""
    cfg_path = sample_dir / "sample.ini"
    cfg = Configuration.from_file(cfg_path)

    assert cfg.sources == {f"{cfg_path} (INI reader)"}
Esempio n. 18
0
def test_read_ini(sample_dir):
    """Test that reading an INI file succeeds"""
    Configuration.from_file(sample_dir / "sample.ini")
def get(module_name: str):
    """Get the configuration for the given module"""
    cfg, *sections = module_name.split(".")
    return _CFGS.get(cfg, Configuration()).get(sections, Configuration())
Esempio n. 20
0
def test_json_roundtrip(cfg):
    """Test that a configuration can be recovered after being stored as JSON"""
    roundtripped = Configuration.from_str(cfg.as_str(format="json"),
                                          format="json")

    assert roundtripped.as_dict() == cfg.as_dict()
Esempio n. 21
0
def sample_cfg(sample_dir):
    """Sample configuration"""
    return Configuration.from_file(sample_dir / "sample.toml")
Esempio n. 22
0
def read_config(cfg_file: str) -> Configuration:
    """Read one configuration from file"""
    with resources.path(__package__, cfg_file) as cfg_path:
        return Configuration.from_file(cfg_path, name=cfg_path.stem)