Ejemplo n.º 1
0
def test_vfpprod(tmpdir):
    """VFPPROD contains multiple record data, for which E100
    fails if the record-ending slash is not on the same line as the data
    """
    tmpdir.chdir()
    vfpstr = """
VFPPROD
  10 2021.3 LIQ WCT GOR THP GRAT METRIC BHP /
  50 150 300 500 1000 1500 2000 3000 4000 5000 6500 8000 10000 /
  50 100 150 200 250 300 400 500 /
  0 0.1 0.2 0.3 0.4 0.5 0.65 0.8 0.95 /
  300 332 350 400 500 1000 2000 5000 10000 30000 /
  0 /
  1 1 1 1
  50.35 50.32 50.34 50.36 50.8 52.03 53.91 58.73 64.01 69.69 78.1 86.34 97.46 /
  1 1 2 1
  50.34 50.31 50.34 50.36 50.85 52.38 54.45 59.58 65.46 71.53 80.43 89.28 101.43 /
  1 1 3 1
"""
    assert opm.io.Parser().parse_string(vfpstr, OPMIO_PARSECONTEXT)

    # Call eclcompress as script on vfpstr:
    with open("vfpfile.inc", "w") as testdeck:
        testdeck.write(vfpstr)
    sys.argv = ["eclcompress", "--keeporiginal", "vfpfile.inc"]
    main()

    # Check that OPM can parse the output (but in this case, OPM allows
    # having the slashes on the next line, so it is not a good test)
    assert opm.io.Parser().parse_string(open("vfpfile.inc").read(), OPMIO_PARSECONTEXT)

    # Verify that a slash at record-end is still there. This test will pass
    # whether eclcompress is just skipping the file, or of it is able to
    # compress it correctly.
    assert "8000 10000 /" in open("vfpfile.inc").read()
Ejemplo n.º 2
0
def test_main(tmpdir):
    """Test installed endpoint"""

    tmpdir.chdir()

    with open("testdeck.inc", "w") as testdeck:
        for line in FILELINES:
            testdeck.write(line + "\n")

    if os.path.exists("testdeck.inc.orig"):
        os.unlink("testdeck.inc.orig")

    sys.argv = ["eclcompress", "--keeporiginal", "testdeck.inc"]
    main()

    assert os.path.exists("testdeck.inc.orig")
    assert os.path.exists("testdeck.inc")
    compressedlines = open("testdeck.inc").readlines()
    compressedbytes = sum([len(x) for x in compressedlines if not x.startswith("--")])
    origbytes = sum([len(x) for x in FILELINES])

    assert compressedbytes < origbytes

    compressedstr = "\n".join(compressedlines)
    assert opm.io.Parser().parse_string(compressedstr, OPMIO_PARSECONTEXT)
Ejemplo n.º 3
0
def test_main(tmpdir):
    """Test installed endpoint"""

    tmpdir.chdir()

    with open("testdeck.inc", "w") as testdeck:
        for line in FILELINES:
            testdeck.write(line + "\n")

    if os.path.exists("testdeck.inc.orig"):
        os.unlink("testdeck.inc.orig")

    sys.argv = ["eclcompress", "--keeporiginal", "testdeck.inc"]
    main()

    assert os.path.exists("testdeck.inc.orig")
    assert os.path.exists("testdeck.inc")
    compressedlines = open("testdeck.inc").readlines()
    compressedbytes = sum([len(x) for x in compressedlines if not x.startswith("--")])
    origbytes = sum([len(x) for x in FILELINES])

    assert compressedbytes < origbytes

    compressedstr = "\n".join(compressedlines)
    parsecontext = opm.io.ParseContext(
        [("PARSE_MISSING_DIMS_KEYWORD", opm.io.action.ignore)]
    )
    assert opm.io.Parser().parse_string(compressedstr, parsecontext)
Ejemplo n.º 4
0
def text_compress_argparse_3():
    """Command line options, explicit files vs. --files"""
    sys.argv = ["eclcompress", "perm.grdecl"]
    main()
    assert "File compressed with eclcompress" in open("perm.grdecl").read()
    assert "File compressed with eclcompress" not in open("poro.grdecl").read()
    assert "13*0" in open("perm.grdecl").read()
    assert "7*1" not in open("poro.grdecl").read()
Ejemplo n.º 5
0
def text_compress_argparse_1():
    """Test also the command line interface with --files"""
    sys.argv = ["eclcompress", "--files", "files"]
    main()
    assert "File compressed with eclcompress" in open("perm.grdecl").read()
    assert "File compressed with eclcompress" in open("poro.grdecl").read()
    assert "13*0" in open("perm.grdecl").read()
    assert "7*1" in open("poro.grdecl").read()
Ejemplo n.º 6
0
def text_compress_argparse_3(mocker):
    """Command line options, explicit files vs. --files"""
    mocker.patch("sys.argv", ["eclcompress", "perm.grdecl"])
    main()
    assert "File compressed with eclcompress" in Path("perm.grdecl").read_text(
        encoding="utf8"
    )
    assert "File compressed with eclcompress" not in Path("poro.grdecl").read_text(
        encoding="utf8"
    )
    assert "13*0" in Path("perm.grdecl").read_text(encoding="utf8")
    assert "7*1" not in Path("poro.grdecl").read_text(encoding="utf8")
Ejemplo n.º 7
0
def text_compress_argparse_1(mocker):
    """Test also the command line interface with --files"""
    mocker.patch("sys.argv", ["eclcompress", "--files", "files"])
    main()
    assert "File compressed with eclcompress" in Path("perm.grdecl").read_text(
        encoding="utf8"
    )
    assert "File compressed with eclcompress" in Path("poro.grdecl").read_text(
        encoding="utf8"
    )
    assert "13*0" in Path("perm.grdecl").read_text(encoding="utf8")
    assert "7*1" in Path("poro.grdecl").read_text(encoding="utf8")
Ejemplo n.º 8
0
def test_binary_example_file(tmpdir, mocker):
    """Test that a particular binary file is not touched by eclcompress

    (historical bug)
    """
    tmpdir.chdir()
    filename = "permxyz.grdecl"
    shutil.copy(TESTDATADIR / filename, filename)
    origfilehash = hashlib.sha256(open(filename, "rb").read()).hexdigest()
    mocker.patch("sys.argv", ["eclcompress", "--verbose", filename])
    main()
    afterfilehash = hashlib.sha256(open(filename, "rb").read()).hexdigest()
    assert origfilehash == afterfilehash
Ejemplo n.º 9
0
def test_main(tmp_path, mocker):
    """Test installed endpoint"""

    os.chdir(tmp_path)

    Path("testdeck.inc").write_text("\n".join(FILELINES), encoding="utf8")

    mocker.patch("sys.argv", ["eclcompress", "--keeporiginal", "testdeck.inc"])
    main()

    assert os.path.exists("testdeck.inc.orig")
    assert os.path.exists("testdeck.inc")
    compressedlines = Path("testdeck.inc").read_text(encoding="utf8").splitlines()
    compressedbytes = sum([len(x) for x in compressedlines if not x.startswith("--")])
    origbytes = sum([len(x) for x in FILELINES])

    assert compressedbytes < origbytes

    compressedstr = "\n".join(compressedlines)
    assert opm.io.Parser().parse_string(compressedstr, OPMIO_PARSECONTEXT)
Ejemplo n.º 10
0
def test_eclkw_regexp(tmpdir):
    """Test that custom regular expressions can be supplied to compress
    otherwise unknown (which implies no compression) keywords"""
    tmpdir.chdir()

    uncompressed_str = "G1\n0 0 0 0 0 0 0 0 0 0 0 0 0\n/"

    # Nothing is found by default here.
    assert not find_keyword_sets(uncompressed_str.split())

    # Only if we specify a regexp catching this odd keyword name:

    kw_sets = find_keyword_sets(uncompressed_str.split(), eclkw_regexp="G1")
    kwend_idx = len(uncompressed_str.split()) - 1
    assert kw_sets == [(0, kwend_idx)]
    assert compress_multiple_keywordsets(kw_sets, uncompressed_str.split()) == [
        "G1",
        "  13*0",
        "/",
    ]

    with open("g1.grdecl", "w") as f_handle:
        f_handle.write(uncompressed_str)

    # Alternative regexpes that should also work with this G1:
    kw_sets = find_keyword_sets(
        uncompressed_str.split(), eclkw_regexp="[A-Z]{1-8}$"
    ) == [(0, kwend_idx)]

    kw_sets = find_keyword_sets(
        uncompressed_str.split(), eclkw_regexp="[A-Z0-9]{2-8}$"
    ) == [(0, kwend_idx)]

    sys.argv = ["eclcompress", "g1.grdecl", "--eclkw_regexp", "G1"]
    main()
    compressed = open("g1.grdecl").read()
    assert "File compressed with eclcompress" in compressed
    assert "13*0" in compressed
Ejemplo n.º 11
0
def test_eclkw_regexp(tmp_path, mocker):
    """Test that custom regular expressions can be supplied to compress
    otherwise unknown (which implies no compression) keywords"""
    os.chdir(tmp_path)

    uncompressed_str = "G1\n0 0 0 0 0 0 0 0 0 0 0 0 0\n/"

    # Nothing is found by default here.
    assert not find_keyword_sets(uncompressed_str.split())

    # Only if we specify a regexp catching this odd keyword name:

    kw_sets = find_keyword_sets(uncompressed_str.split(), eclkw_regexp="G1")
    kwend_idx = len(uncompressed_str.split()) - 1
    assert kw_sets == [(0, kwend_idx)]
    assert compress_multiple_keywordsets(kw_sets, uncompressed_str.split()) == [
        "G1",
        "  13*0",
        "/",
    ]

    Path("g1.grdecl").write_text(uncompressed_str, encoding="utf8")

    # Alternative regexpes that should also work with this G1:
    kw_sets = find_keyword_sets(
        uncompressed_str.split(), eclkw_regexp="[A-Z]{1-8}$"
    ) == [(0, kwend_idx)]

    kw_sets = find_keyword_sets(
        uncompressed_str.split(), eclkw_regexp="[A-Z0-9]{2-8}$"
    ) == [(0, kwend_idx)]

    mocker.patch("sys.argv", ["eclcompress", "g1.grdecl", "--eclkw_regexp", "G1"])
    main()
    compressed = Path("g1.grdecl").read_text(encoding="utf8")
    assert "File compressed with eclcompress" in compressed
    assert "13*0" in compressed