Skip to content

Commit

Permalink
CLN: Remove unused utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mferrera committed Apr 19, 2024
1 parent 988e798 commit a88748a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 137 deletions.
62 changes: 0 additions & 62 deletions src/fmu/dataio/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from typing import Any, Final

import numpy as np
import xtgeo

from fmu.config import utilities as ut

Expand Down Expand Up @@ -78,29 +77,6 @@ def md5sum(fname: Path) -> str:
return hash_md5.hexdigest()


def create_symlink(source: str, target: str) -> None:
"""Create a symlinked file with some checks."""

thesource = Path(source)
if not thesource.exists():
raise OSError(f"Cannot symlink: Source file {thesource} does not exist.")

thetarget = Path(target)

if thetarget.exists() and not thetarget.is_symlink():
raise OSError(f"Target file {thetarget} exists already as a normal file.")

os.symlink(source, target)

if not (thetarget.exists() and thetarget.is_symlink()):
raise OSError(f"Target file {thesource} does not exist or is not a symlink.")


def size(fname: str) -> int:
"""Size of file, in bytes"""
return Path(fname).stat().st_size


def uuid_from_string(string: str) -> uuid.UUID:
"""Produce valid and repeteable UUID4 as a hash of given string"""
return uuid.UUID(hashlib.md5(string.encode("utf-8")).hexdigest())
Expand Down Expand Up @@ -148,39 +124,6 @@ def check_if_number(value: str | None) -> int | float | str | None:
return value


def get_object_name(obj: Path) -> str | None:
"""Get the name of the object.
If not possible, return None.
If result is 'unknown', return None (XTgeo defaults)
If object is a polygon, and object name is 'poly', return None (XTgeo defaults)
If object is a grid, and object name is 'noname', return None (XTgeo defaults)
"""

logger.debug("Getting name from the data object itself")

try:
name = obj.name
except AttributeError:
logger.info("display.name could not be set")
return None

if isinstance(obj, xtgeo.RegularSurface) and name == "unknown":
logger.debug("Got 'unknown' as name from a surface object, returning None")
return None

if isinstance(obj, xtgeo.Polygons) and name == "poly":
logger.debug("Got 'poly' as name from a polygons object, returning None")
return None

if isinstance(obj, xtgeo.Grid) and name == "noname":
logger.debug("Got 'noname' as name from grids object, returning None")
return None

return name


def prettyprint_dict(inp: dict) -> str:
"""Prettyprint a dict into as string variable (for python logging e.g)"""
return str(json.dumps(inp, indent=2, default=str, ensure_ascii=False))
Expand All @@ -206,11 +149,6 @@ def some_config_from_env(envvar: str = "FMU_GLOBAL_CONFIG") -> dict | None:
) from e


def read_named_envvar(envvar: str) -> str | None:
"""Read a specific (named) environment variable."""
return os.environ.get(envvar, None)


def filter_validate_metadata(metadata_in: dict) -> dict:
"""Validate metadatadict at topmost_level and strip away any alien keys."""

Expand Down
75 changes: 0 additions & 75 deletions tests/test_units/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
"""Test the utils module"""

import os
from tempfile import NamedTemporaryFile

import numpy as np
import pytest
from fmu.dataio import _utils as utils
from xtgeo import Grid, Polygons, RegularSurface

from ..utils import inside_rms

Expand All @@ -33,53 +28,6 @@ def test_check_if_number(value, result):
assert utils.check_if_number(value) == result


def test_get_object_name():
assert utils.get_object_name(object()) is None

assert utils.get_object_name(RegularSurface(0, 0, 0, 0)) is None
assert utils.get_object_name(RegularSurface(0, 0, 0, 0, name="unknown")) is None
assert (
utils.get_object_name(RegularSurface(0, 0, 0, 0, name="Not ukn")) == "Not ukn"
)

assert utils.get_object_name(Polygons()) is None
assert utils.get_object_name(Polygons(name="poly")) is None
assert utils.get_object_name(Polygons(name="Not poly")) == "Not poly"

assert (
utils.get_object_name(
Grid(
np.random.randn(2, 2, 6).astype(np.float64),
np.random.randn(2, 2, 2, 4).astype(np.float32),
np.random.randn(1, 1, 1).astype(np.int32),
)
)
is None
)
assert (
utils.get_object_name(
Grid(
np.random.randn(2, 2, 6).astype(np.float64),
np.random.randn(2, 2, 2, 4).astype(np.float32),
np.random.randn(1, 1, 1).astype(np.int32),
name="noname",
)
)
is None
)
assert (
utils.get_object_name(
Grid(
np.random.randn(2, 2, 6).astype(np.float64),
np.random.randn(2, 2, 2, 4).astype(np.float32),
np.random.randn(1, 1, 1).astype(np.int32),
name="Not noname",
)
)
== "Not noname"
)


@inside_rms
def test_detect_inside_rms_decorator():
assert utils.detect_inside_rms()
Expand All @@ -89,22 +37,6 @@ def test_detect_not_inside_rms():
assert not utils.detect_inside_rms()


def test_create_symlink():
with pytest.raises(OSError):
utils.create_symlink(
"hopefullythispathwillneverexist",
"norwillthispath",
)

with NamedTemporaryFile() as source, NamedTemporaryFile() as target, pytest.raises(
OSError
):
utils.create_symlink(
source.name,
target.name,
)


def test_generate_description():
assert utils.generate_description("") is None
assert utils.generate_description([]) is None
Expand All @@ -118,10 +50,3 @@ def test_generate_description():

with pytest.raises(ValueError):
utils.generate_description(object())


def test_read_named_envvar():
assert utils.read_named_envvar("DONTEXIST") is None

os.environ["MYTESTENV"] = "mytestvalue"
assert utils.read_named_envvar("MYTESTENV") == "mytestvalue"

0 comments on commit a88748a

Please sign in to comment.