Beispiel #1
0
def check_applicability(eclfiles: ecl2df.EclFiles) -> None:
    """Check that the input is relevant for usage with check_swatinit. This
    function may raise exceptions, SystemExit or only give warnings"""

    deck = eclfiles.get_ecldeck()

    init = eclfiles.get_initfile()
    if (
        "SWATINIT" not in [initheader[0] for initheader in init.headers]
        and "SWATINIT" not in deck
    ):
        logger.warning(
            "INIT-file/deck does not have SWATINIT, this tool has limited use."
        )

    if "RPTRST" not in deck:
        logger.warning(
            "RPTRST not found in DATA-file, UNRST file is expected to be missing"
        )

    try:
        eclfiles.get_rstfile()
    except FileNotFoundError as exception:
        if "UNIFOUT" not in deck:
            sys.exit(
                "Only unified RESTARTs are supported. Add UNIFOUT to your DATA file."
            )
        logger.error(str(exception))
        sys.exit(
            "No UNRST file found. This is required to get the initial water saturation"
        )
Beispiel #2
0
def test_filedescriptors():
    """Test that filedescriptors are properly closed"""

    fd_dir = Path("/proc/") / str(os.getpid()) / "fd"
    if not fd_dir.exists():
        print("Counting file descriptors on non-Linux not supported")
        return

    pre_fd_count = len(list(fd_dir.glob("*")))

    eclfiles = EclFiles(EIGHTCELLS)
    # No opened files yet:
    assert len(list(fd_dir.glob("*"))) == pre_fd_count

    eclfiles.close()
    # No change, no files to close:
    assert len(list(fd_dir.glob("*"))) == pre_fd_count

    eclfiles.get_egrid()
    # This should not leave any file descriptor open
    assert len(list(fd_dir.glob("*"))) == pre_fd_count

    eclfiles.get_initfile()
    assert len(list(fd_dir.glob("*"))) == pre_fd_count
    assert eclfiles._initfile is not None
    eclfiles.close()
    assert len(list(fd_dir.glob("*"))) == pre_fd_count
    assert eclfiles._initfile is None

    eclfiles.get_rstfile()
    # Automatically closed by libecl
    assert len(list(fd_dir.glob("*"))) == pre_fd_count
    assert eclfiles._rstfile is not None
    eclfiles.close()
    assert len(list(fd_dir.glob("*"))) == pre_fd_count
    assert eclfiles._rstfile is None

    eclfiles.get_eclsum()
    assert len(list(fd_dir.glob("*"))) == pre_fd_count + 1
    eclfiles.close()
    assert len(list(fd_dir.glob("*"))) == pre_fd_count

    eclfiles.get_egridfile()
    assert len(list(fd_dir.glob("*"))) == pre_fd_count
    assert eclfiles._egridfile is not None
    eclfiles.close()
    assert len(list(fd_dir.glob("*"))) == pre_fd_count
    assert eclfiles._egridfile is None

    eclfiles.get_rftfile()
    assert len(list(fd_dir.glob("*"))) == pre_fd_count
    assert eclfiles._rftfile is not None
    eclfiles.close()
    assert len(list(fd_dir.glob("*"))) == pre_fd_count
    assert eclfiles._rftfile is None

    eclfiles.get_ecldeck()
    # This should not leave any file descriptor open
    assert len(list(fd_dir.glob("*"))) == pre_fd_count