Skip to content

Commit

Permalink
Fix suffix check (#90)
Browse files Browse the repository at this point in the history
* Use Path.with_suffix() instead of custom function

* Update SMDA testdata uuids to uuid4

* Revert: smda uuid changes
  • Loading branch information
equinor-ruaj authored Sep 13, 2024
1 parent 8756943 commit e000f1f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 35 deletions.
22 changes: 0 additions & 22 deletions src/fmu/sumo/sim2sumo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,25 +567,3 @@ def give_name(datafile_path: str) -> str:
base_name = base_name[:-1]
logger.info("Returning name %s", base_name)
return base_name


def fix_suffix(datafile_path: str, suffix=".DATA"):
"""Check if suffix is .DATA, if not change to
Args:
datafile_path (PosixPath): path to check
suffix (str): desired suffix
Returns:
str: the corrected path
"""
logger = logging.getLogger(__file__ + ".fix_suffix")
string_datafile_path = str(datafile_path)
assert "." in suffix, f"suffix: needs to start with . (is {suffix})"
if "." not in string_datafile_path:
string_datafile_path += suffix
if not string_datafile_path.endswith(suffix):
corrected_path = re.sub(r"\..*", suffix, string_datafile_path)
logger.debug("Changing %s to %s", string_datafile_path, corrected_path)
datafile_path = corrected_path
return datafile_path
9 changes: 5 additions & 4 deletions src/fmu/sumo/sim2sumo/grid3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
3. Uploads to Sumo
"""
import logging
from pathlib import Path
import re
from datetime import datetime

Expand All @@ -21,7 +22,6 @@
generate_meta,
convert_to_bytestring,
convert_2_sumo_file,
fix_suffix,
)


Expand Down Expand Up @@ -355,9 +355,10 @@ def upload_simulation_run(datafile, config, dispatcher):
datafile (str): path to datafile
"""
logger = logging.getLogger(__name__ + ".upload_simulation_run")
init_path = fix_suffix(datafile, ".INIT")
restart_path = fix_suffix(datafile, ".UNRST")
grid_path = fix_suffix(datafile, ".EGRID")
datafile_path = Path(datafile)
init_path = datafile_path.with_suffix(".INIT")
restart_path = datafile_path.with_suffix(".UNRST")
grid_path = datafile_path.with_suffix(".EGRID")
egrid = Grid(grid_path)
xtgeoegrid = grid_from_file(grid_path)
# grid_exp_path = export_object(
Expand Down
10 changes: 1 addition & 9 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
nodisk_upload,
Dispatcher,
find_datefield,
find_datafile_paths,
find_datafiles_no_seedpoint,
filter_options,
)
Expand All @@ -31,7 +30,7 @@
convert_to_arrow,
SUBMODULES,
)
from fmu.sumo.sim2sumo.common import fix_suffix, get_case_uuid
from fmu.sumo.sim2sumo.common import get_case_uuid
from fmu.sumo.uploader import SumoConnection

REEK_ROOT = Path(__file__).parent / "data/reek"
Expand Down Expand Up @@ -183,13 +182,6 @@ def test_find_datefield(datestring):
print(results)


def test_fix_suffix():

test_path = "simulator.banana"
corrected_path = fix_suffix(test_path)
assert corrected_path.endswith(".DATA"), f"Didn't correct {corrected_path}"


def test_get_case_uuid(case_uuid, scratch_files, monkeypatch):
real0 = scratch_files[0]

Expand Down

0 comments on commit e000f1f

Please sign in to comment.