Esempio n. 1
0
def test_vinstre():
    """Test table output behaviour"""

    cfg = config.ConfigParserFMU()
    cfx = config.ConfigParserFMU()

    assert isinstance(cfg, config.ConfigParserFMU)

    cfg.parse(JFILE1)
    cfx.parse(JFILE1, smart_braces=False)

    cfg.to_table(
        rootname="VI",
        destination=fmux.tmpdir,
        template=fmux.tmpdir,
        entry="global.FWL",
        sep="      ",
    )

    cfg.to_ipl(
        rootname="vinstre_global_variables",
        destination=fmux.tmpdir,
        template=fmux.tmpdir,
        tool="rms",
    )

    cfg.to_yaml(
        rootname="vinstre_global_variables_rms",
        destination=fmux.tmpdir,
        template=fmux.tmpdir,
        tool="rms",
    )

    status1 = ut.compare_yaml_files(
        join(TMPD, "vinstre_global_variables_rms.yml"),
        join(TCMP, "vinstre_global_variables_rms.yml"),
    )
    status2 = ut.compare_yaml_files(
        join(TMPD, "vinstre_global_variables_rms.yml.tmpl"),
        join(TCMP, "vinstre_global_variables_rms.yml.tmpl"),
    )
    assert status1 is True
    assert status2 is True

    cfx.to_yaml(
        rootname="vinstre_global_variables_rms_nobraces",
        destination=fmux.tmpdir,
        template=fmux.tmpdir,
        tool="rms",
    )

    assert cfx.config["rms"]["FWL3"][1] == "1236.0 ~ <>"
    assert cfg.config["rms"]["FWL3"][1] == "1236.0 ~ <FWL3_1>"
Esempio n. 2
0
def test_yaml_has_duplicates_ogre():
    """The YAML file has duplicates; should raise error"""

    cfg = config.ConfigParserFMU()

    with pytest.raises(SystemExit):
        cfg.parse(TFILE3)
Esempio n. 3
0
def test_process_value1(tmp_path):
    """s03"""

    inp = b"""
    global:
        WELLCONCEPT: REV1_A15 ~ <WELL_CONS>
    """

    target = tmp_path / "generic.yml"
    with target.open("w") as out:
        out.write(inp.decode("utf-8"))

    cfg = fcfg.ConfigParserFMU()
    cfg.parse(str(target.resolve()))

    outfolder = tmp_path
    out = str(outfolder.resolve())

    cfg.to_yaml(rootname="s03", destination=out, template=out)

    actual = ut.yaml_load(join(out, "s03.yml"))

    assert actual["global"]["WELLCONCEPT"] == "REV1_A15"

    tmpl = ut.yaml_load(join(out, "s03.yml.tmpl"))

    assert tmpl["global"]["WELLCONCEPT"] == "<WELL_CONS>"
Esempio n. 4
0
def test_process_value2(tmp_path):
    """s04"""

    inp = b"""
    global:
        WHATEVER: &onx ONX ~ <ONX>
        WHATEVER2: *onx
        NUMBER1: 2.0 ~ <NUM1>
    """

    target = tmp_path / "generic.yml"
    with target.open("w") as out:
        out.write(inp.decode("utf-8"))

    cfg = fcfg.ConfigParserFMU()
    cfg.parse(str(target))

    out = str(tmp_path.resolve())

    cfg.to_yaml(rootname="s04", destination=out, template=out)

    actual = ut.yaml_load(join(out, "s04.yml"))

    assert actual["global"]["WHATEVER"] == "ONX"
    assert actual["global"]["NUMBER1"] == 2.0

    tmpl = ut.yaml_load(join(out, "s04.yml.tmpl"))

    assert tmpl["global"]["WHATEVER"] == "<ONX>"
Esempio n. 5
0
def test_filepath(tmp_path):
    """Test when filepath is present as substitute, s05"""

    inp = b"""
    global:
        MYFILE: /tmp/fil ~ <FILE>
    """

    target = tmp_path / "generic.yml"
    with target.open("w") as out:
        out.write(inp.decode("utf-8"))

    cfg = fcfg.ConfigParserFMU()
    cfg.parse(str(target))

    out = str(tmp_path.resolve())

    cfg.to_yaml(rootname="s05", destination=out, template=out)

    actual = ut.yaml_load(join(out, "s05.yml"))

    assert actual["global"]["MYFILE"] == "/tmp/fil"

    tmpl = ut.yaml_load(join(out, "s05.yml.tmpl"))

    assert tmpl["global"]["MYFILE"] == "<FILE>"
Esempio n. 6
0
def test_small_float(tmp_path, exponent):
    """Test for issue 1, small floats in input yaml can give non-compliant
    formats in output IPL (IPL does not support Pythons scientific format)

    IPL accepts 1.0E-4, 1.0e-4, 1.0e-04, but NOT 1E-3 or 1e-4, i.e. there must be
    a dot after '1'"""

    inp = (b"""
    rms:
        SMALLFLOAT: 1.0E-%d""" % exponent)

    target = tmp_path / "generic.yml"
    with io.open(str(target.resolve()), "wb") as out:
        out.write(inp)

    cfg = fcfg.ConfigParserFMU()
    cfg.parse(str(target))

    out = str(tmp_path.resolve())

    cfg.to_ipl(rootname="foo", destination=out, template=out)
    ipl_lines = [
        line
        for line in open(join(str(tmp_path.resolve()), "foo.ipl")).readlines()
        if line.startswith("SMALLFLOAT")
    ]
    significand = ipl_lines[0].split(" = ")[1].split("E")[0].split("e")[0]

    # Verify we have a floating point significand if we have written
    # exponential notation
    if "e" in ipl_lines[0].lower():
        assert len(significand) > 1
        assert "." in significand
Esempio n. 7
0
def test_ogre_to_yaml_merge():
    """Test the output for the YAML files, and convert OUTPUT yaml to ipl"""

    cfg = config.ConfigParserFMU()

    cfg.parse(TFILE4)
    rootn = "ogre_yaml"

    cfg.to_yaml(rootname=rootn, destination=fmux.tmpdir, template=fmux.tmpdir)

    newinput = os.path.join(fmux.tmpdir, rootn + ".yml")
    newrootn = "ogre_yaml_selfread"

    cfx = config.ConfigParserFMU()
    cfx.parse(newinput)

    cfx.to_ipl(
        rootname=newrootn, destination=fmux.tmpdir, template=fmux.tmpdir, tool="rms"
    )
Esempio n. 8
0
def test_basic_ogre():
    """Test basic behaviour"""

    cfg = config.ConfigParserFMU()

    assert isinstance(cfg, config.ConfigParserFMU)

    cfg.parse(TFILE2)

    # cfg.show()

    assert len(cfg.config["rms"]["horizons"]) == 6
Esempio n. 9
0
def main(args=None):
    """The fmuconfigrunner is a script that takes ..."""

    args = _do_parse_args(args)

    cfg = fmu_config.ConfigParserFMU()

    logger.info("OK %s", cfg)

    if isinstance(args.config, str):
        if not os.path.isfile(args.config):
            raise IOError("Input file does not exist")
        cfg.parse(args.config)

    if args.mode == "ipl":
        logger.info("Mode is IPL")
        cfg.to_ipl(
            rootname=args.rootname,
            destination=args.destination,
            template=args.template,
            tool=args.tool,
        )

    elif args.mode in ("yaml", "yml"):
        logger.info("Mode is YAML")
        cfg.to_yaml(
            rootname=args.rootname,
            destination=args.destination,
            template=args.template,
            tool=args.tool,
        )

    elif args.mode in ("json", "jason"):
        logger.info("Mode is JASON")
        cfg.to_json(
            rootname=args.rootname,
            destination=args.destination,
            template=args.template,
            tool=args.tool,
        )

    elif args.mode == "table":
        logger.info("Mode is TABLE")
        cfg.to_table(
            rootname=args.rootname,
            destination=args.destination,
            template=args.template,
            entry=args.tool,
            sep=args.sep,
        )
    else:
        raise RuntimeError("Invalid options for mode")
Esempio n. 10
0
def test_to_yaml_ogre():
    """Test the output for the YAML files, both templated and normal for rms"""

    cfg = config.ConfigParserFMU()

    assert isinstance(cfg, config.ConfigParserFMU)

    cfg.parse(TFILE2)
    rootn = "ogre_yaml"

    cfg.to_yaml(
        rootname=rootn, destination=fmux.tmpdir, template=fmux.tmpdir, tool="rms"
    )

    # now read the files again to assert tests
    with open(os.path.join(fmux.tmpdir, rootn + ".yml"), "r") as stream:
        cfg_yml = yaml.safe_load(stream)

    with open(os.path.join(fmux.tmpdir, rootn + ".yml.tmpl"), "r") as stream:
        cfg_tmpl = yaml.safe_load(stream)

    assert cfg_yml["KH_MULT_CSAND"] == 1.0
    assert cfg_tmpl["KH_MULT_CSAND"] == "<KH_MULT_CSAND>"

    status1 = ut.compare_yaml_files(
        join(TMPD, rootn + ".yml"),
        join(TCMP, rootn + ".yml"),
    )
    status2 = ut.compare_yaml_files(
        join(TMPD, rootn + ".yml.tmpl"),
        join(TCMP, rootn + ".yml.tmpl"),
    )
    assert status1 is True
    assert status2 is True

    # IPL version
    rootn = "ogre_ipl"
    cfg.to_ipl(
        rootname=rootn, destination=fmux.tmpdir, template=fmux.tmpdir, tool="rms"
    )

    status1 = ut.compare_text_files(
        join(TMPD, rootn + ".ipl"),
        join(TCMP, rootn + ".ipl"),
    )
    status2 = ut.compare_text_files(
        join(TMPD, rootn + ".ipl.tmpl"),
        join(TCMP, rootn + ".ipl.tmpl"),
    )
    assert status1 is True
    assert status2 is True
Esempio n. 11
0
def test_ipl_ogre():
    """Test basic behaviour"""

    cfg = config.ConfigParserFMU()

    assert isinstance(cfg, config.ConfigParserFMU)

    cfg.parse(TFILE2)

    # cfg.show()
    # cfg.show(style='json')

    # export the config as a global variables IPL
    logger.info("Test dir is %s", fmux.tmpdir)
    cfg.to_ipl(
        destination=os.path.join(fmux.tmpdir), template=os.path.join(fmux.tmpdir)
    )
Esempio n. 12
0
def test_to_json_ogre():
    """Test the output for the JSON files, both templated and normal for
    rms section.
    """

    cfg = config.ConfigParserFMU()

    assert isinstance(cfg, config.ConfigParserFMU)

    cfg.parse(TFILE2)
    rootn = "ogre_json"

    cfg.to_json(
        rootname=rootn, destination=fmux.tmpdir, template=fmux.tmpdir, tool="rms"
    )

    with open(os.path.join(fmux.tmpdir, rootn + ".json"), "r") as myfile:
        cfg_json = json.load(myfile)

    assert cfg_json["KH_MULT_CSAND"] == str(1.0)
Esempio n. 13
0
def test_dict_with_scalar_and_lists1(tmp_path):
    """s01, testing small inline snippets"""

    inp = b"""
    global:
        ADICT_WITH_SCALAR_OR_LISTS:
            1: ascalar
            3: [item1, item2, 33, 44.0]
    """

    target = tmp_path / "generic.yml"

    with target.open("w") as out:
        out.write(inp.decode("utf-8"))

    cfg = fcfg.ConfigParserFMU()
    cfg.parse(str(target.resolve()))

    assert cfg._config["global"]["ADICT_WITH_SCALAR_OR_LISTS"][1] == "ascalar"
    assert cfg._config["global"]["ADICT_WITH_SCALAR_OR_LISTS"][3][2] == 33
Esempio n. 14
0
def test_dict_with_scalar_and_lists2(tmp_path):
    """s02"""

    inp = b"""
    global:
        ACOMPLICATED:
            1: ascalar
            2: number ~ <>
            3: [2, 33, [12, 13, 14], manana]
    """

    target = tmp_path / "generic.yml"

    with target.open("w") as out:
        out.write(inp.decode("utf-8"))

    cfg = fcfg.ConfigParserFMU()
    cfg.parse(str(target.resolve()))

    assert cfg._config["global"]["ACOMPLICATED"][1] == "ascalar"
    assert cfg._config["global"]["ACOMPLICATED"][3][0] == 2
    assert cfg._config["global"]["ACOMPLICATED"][3][3] == "manana"