Ejemplo n.º 1
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"]
Ejemplo n.º 2
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()
Ejemplo n.º 3
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)
Ejemplo n.º 5
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
Ejemplo n.º 6
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()