Skip to content

Commit

Permalink
Add tidy func to clean up ecl2dfs mess when rft is exctracted
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sol committed Aug 30, 2023
1 parent 6d8bae1 commit 86705da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/fmu/sumo/utilities/scripts/sim2sumo.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Sim2Sumo(ErtScript):
This is used for the ERT workflow context."""

# pylint: disable=too-few-public-methods
def run(self, *args):
def run(self):
# pylint: disable=no-self-use
"""Parse with a simplified command line parser, for ERT only,
call sumo_upload_main()"""
Expand Down
20 changes: 19 additions & 1 deletion src/fmu/sumo/utilities/sim2sumo.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,27 @@ def get_dataframe(
"Trace: %s, \nNo results produced ",
trace,
)
if submod == "rft":
tidy()
return frame


def tidy():
"""Utility function to tidy up mess from ecl2df"""
# Ecl2df creates three files for rft data, see unwanted list below
logger = logging.getLogger(__file__ + ".tidy")
unwanteds = ["seg.csv", "con.csv", "icd.csv"]
cwd = Path().cwd()
for unwanted in unwanteds:
unwanted_posix = cwd / unwanted
if unwanted_posix.is_file():
logger.info(
"Deleting unwanted file from rft export %s",
str(unwanted_posix),
)
unwanted_posix.unlink()


def export_csv(
datafile_path: str,
submod: str,
Expand Down Expand Up @@ -362,7 +380,7 @@ def give_help(submod, only_general=False):
general_info = """
This utility uses the library ecl2csv, but uploads directly to sumo. Required options are:
A config file in yaml format, where you specifiy the variables to extract. What is required
is a keyword in the config saying sim2df. under there you have three optional arguments:
is a keyword in the config called "sim2simo". under there you have three optional arguments:
* datafile: this can be a string, a list, or it can be absent altogether
* datatypes: this needs to be a list, or non existent
* options: The options are listed below in the original documentation from ecl2csv. The eclfiles
Expand Down
31 changes: 3 additions & 28 deletions tests/test_utility_sim2sumo.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,39 +210,14 @@ def test_export_w_config(tmp_path, config_path):
sim2sumo.export_with_config(config_path)


# @pytest.mark.parametrize(
# "input_args",
# (
# ("--config_path", "global_vars", "--env", "dev"),
# *[("help", sub) for sub in sim2sumo.SUBMODULES],
# ),
# )
# def test_parse_args(mocker, input_args):
# """Test parse args

# Args:
# mocker (pytest.fixture): to mock command line like
# submod (str): name of submodule
# """
# commands = list(input_args)
# assert isinstance(commands, list)
# assert len(commands) == 2
# assert "help" in commands

# print(commands)
# mocker.patch("sys.argv", commands)
# print(sys.argv)
# # sim2sumo.parse_args()


def test_upload(token):
"""Test the upload function"""
sumo_env = "dev"
sumo = SumoClient(sumo_env, token)
sumocon = SumoConnection(sumo_env, token)
case_metadata_path = REEK_ROOT / "share/metadata/fmu_case.yml"
LOGGER.info("This is the case metadata %s", case_metadata_path)

LOGGER.info("Using token %s", token)
case = CaseOnDisk(
case_metadata_path=case_metadata_path,
sumo_connection=sumocon,
Expand All @@ -261,10 +236,10 @@ def test_upload(token):
results = sumo.get(
"/search", query=f"fmu.case.uuid:{case_uuid} AND class:table", size=0
)
print(results["hits"])
LOGGER.debug(results["hits"])
correct = 2
returned = results["hits"]["total"]["value"]
print("This is returned ", returned)
LOGGER.debug("This is returned ", returned)
assert (
returned == correct
), f"Tried to upload {correct}, but only managed {returned}"
Expand Down

0 comments on commit 86705da

Please sign in to comment.