Esempio n. 1
0
def test_read_long_keyword():
    very_long_keyword = "a" * 200
    file_data = f"{very_long_keyword} Eclipse comment\n" "1 2 3 4 /"
    with patch("builtins.open", mock_open(read_data=file_data)) as mock_file:
        with open_grdecl(mock_file, keywords=[very_long_keyword]) as kw:
            assert list(kw) == [
                (very_long_keyword, ["1", "2", "3", "4"]),
            ]
Esempio n. 2
0
def test_gridunit(inp_str, expected_unit, expected_relative):
    with patch("builtins.open", mock_open(read_data=inp_str)) as mock_file:
        with open_grdecl(mock_file, keywords=["GRIDUNIT"]) as kw:
            keyword, values = next(kw)
            assert keyword == "GRIDUNIT"
            gridunit = ggrid.GridUnit.from_grdecl(values)

            assert gridunit.unit == expected_unit
            assert gridunit.grid_relative == expected_relative
Esempio n. 3
0
def test_read_extra_keyword_characters():
    file_data = ("LONGPROP Eclipse comment\n"
                 "1 2 3 4 / More Eclipse comment\nOTHERPROP\n 5 6 7 8 /\n")
    with patch("builtins.open", mock_open(read_data=file_data)) as mock_file:
        with open_grdecl(mock_file, keywords=["LONGPROP", "OTHERPROP"]) as kw:
            assert list(kw) == [
                ("LONGPROP", ["1", "2", "3", "4"]),
                ("OTHERPROP", ["5", "6", "7", "8"]),
            ]
Esempio n. 4
0
def test_mapaxes(inp_str, values):
    with patch("builtins.open", mock_open(read_data=inp_str)) as mock_file:
        with open_grdecl(mock_file, keywords=["MAPAXES"]) as kw:
            keyword, values = next(kw)
            assert keyword == "MAPAXES"
            mapaxes = ggrid.MapAxes.from_grdecl(values)
            assert list(mapaxes.origin) == [float(v) for v in values[2:4]]
            assert list(mapaxes.y_line) == [float(v) for v in values[0:2]]
            assert list(mapaxes.x_line) == [float(v) for v in values[4:6]]

            assert mapaxes.to_grdecl() == [float(v) for v in values]
Esempio n. 5
0
def test_specgrid():
    inp_str = "SPECGRID\n 64 118 263 1 F /"
    with patch("builtins.open", mock_open(read_data=inp_str)) as mock_file:
        with open_grdecl(mock_file, keywords=["SPECGRID"]) as kw:
            keyword, values = next(kw)
            assert keyword == "SPECGRID"
            specgrid = ggrid.SpecGrid.from_grdecl(values)
            assert specgrid.ndivix == 64
            assert specgrid.ndiviy == 118
            assert specgrid.ndiviz == 263
            assert specgrid.numres == 1
            assert specgrid.coordinate_type == ggrid.CoordinateType.CARTESIAN

            assert [str(v) for v in specgrid.to_grdecl()] == values
Esempio n. 6
0
def test_gdorient():
    inp_str = "GDORIENT\n INC INC INC DOWN LEFT /"
    with patch("builtins.open", mock_open(read_data=inp_str)) as mock_file:
        with open_grdecl(mock_file, keywords=["GDORIENT"]) as kw:
            keyword, values = next(kw)
            assert keyword == "GDORIENT"
            gdorient = ggrid.GdOrient.from_grdecl(values)

            assert gdorient.i_order == ggrid.Order.INCREASING
            assert gdorient.k_order == ggrid.Order.INCREASING
            assert gdorient.k_order == ggrid.Order.INCREASING
            assert gdorient.z_direction == ggrid.Orientation.DOWN
            assert gdorient.handedness == ggrid.Handedness.LEFT

            assert gdorient.to_grdecl() == values
Esempio n. 7
0
def test_read_prop_raises_error_when_no_forwardslash(undelimited_file_data):
    with patch("builtins.open",
               mock_open(read_data=undelimited_file_data)) as mock_file:
        with open_grdecl(mock_file, keywords=["PROP"]) as kw:
            with pytest.raises(ValueError):
                list(kw)
Esempio n. 8
0
def test_read_string():
    inp_str = "PROP\n 'FOO BAR' FOO /\n"
    with patch("builtins.open", mock_open(read_data=inp_str)) as mock_file:
        with open_grdecl(mock_file, keywords=["PROP"]) as kw:
            assert list(kw) == [("PROP", ["FOO BAR", "FOO"])]
Esempio n. 9
0
def test_read_repeated_string_literal():
    inp_str = "PROP\n 3*'INP   ' /\n"
    with patch("builtins.open", mock_open(read_data=inp_str)) as mock_file:
        with open_grdecl(mock_file, keywords=["PROP"]) as kw:
            assert list(kw) == [("PROP", ["INP   "] * 3)]
Esempio n. 10
0
def test_read_repeated_property(repeats, value):
    inp_str = f"PROP\n {repeats}*{value} /\n"
    with patch("builtins.open", mock_open(read_data=inp_str)) as mock_file:
        with open_grdecl(mock_file, keywords=["PROP"]) as kw:
            assert list(kw) == [("PROP", [str(value)] * repeats)]
Esempio n. 11
0
def test_read_simple_property(file_data):
    with patch("builtins.open", mock_open(read_data=file_data)) as mock_file:
        with open_grdecl(mock_file, keywords=["PROP"]) as kw:
            assert list(kw) == [("PROP", ["1", "2", "3", "4"])]