From 88f2b6dce61dc92c89ae817d8824b492626d3154 Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Tue, 21 Dec 2021 13:49:22 +0100 Subject: [PATCH] BUG: handle not found file in surface_from_file surface_from_file would throw a segfault when file is missing, fixed with a check on the python side. --- src/xtgeo/surface/regular_surface.py | 1 + tests/test_surface/test_regular_surface.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/xtgeo/surface/regular_surface.py b/src/xtgeo/surface/regular_surface.py index 74d619be4..964cc8eff 100644 --- a/src/xtgeo/surface/regular_surface.py +++ b/src/xtgeo/surface/regular_surface.py @@ -1082,6 +1082,7 @@ def _read_file( """ mfile = xtgeosys._XTGeoFile(mfile) + mfile.check_file(raiseerror=ValueError) if fformat is None or fformat == "guess": fformat = mfile.detect_fformat() else: diff --git a/tests/test_surface/test_regular_surface.py b/tests/test_surface/test_regular_surface.py index 55b6558ce..e5a4e76be 100644 --- a/tests/test_surface/test_regular_surface.py +++ b/tests/test_surface/test_regular_surface.py @@ -39,6 +39,11 @@ FENCE1 = TPATH / "polygons/reek/1/fence.pol" +def test_surface_from_file_missing(tmp_path): + with pytest.raises(ValueError, match="missing"): + xtgeo.surface_from_file(tmp_path / "nosuchfile", fformat="irap_binary") + + @pytest.mark.filterwarnings("ignore:Default values*") def test_values(default_surface): """Test behaviour of values attribute."""