Exemplo n.º 1
0
def test_subdirectory(tmpdir, mocker):
    """Check that we can thin an UNRST file two directory levels down"""
    tmpdir.chdir()

    subdir = Path("eclipse/model")
    subdir.mkdir(parents=True)

    shutil.copyfile(ECLDIR / UNRST_FNAME, subdir / UNRST_FNAME)
    orig_rstindices = restartthinner.get_restart_indices(subdir / UNRST_FNAME)

    mocker.patch(
        "sys.argv",
        ["restartthinner", "-n", "3",
         str(subdir / UNRST_FNAME), "--keep"])
    print(os.getcwd())
    restartthinner.main()
    print(os.getcwd())

    assert (subdir / UNRST_FNAME).exists()
    assert (subdir / (UNRST_FNAME + ".orig")).exists()  # The backed up file

    new_rstindices = restartthinner.get_restart_indices(subdir / UNRST_FNAME)
    assert len(new_rstindices) == 3
    assert new_rstindices[0] == orig_rstindices[0]
    assert new_rstindices[-1] == orig_rstindices[-1]
    assert (len(
        restartthinner.get_restart_indices(subdir /
                                           (UNRST_FNAME + ".orig"))) == 4)
Exemplo n.º 2
0
def test_main(tmpdir):
    """Basic testing of the command line application"""

    ecldir = os.path.join(os.path.dirname(__file__), "data/reek/eclipse/model")

    unrst_fname = "2_R001_REEK-0.UNRST"

    shutil.copyfile(ecldir + "/" + unrst_fname, str(tmpdir.join(unrst_fname)))

    tmpdir.chdir()

    orig_rstindices = restartthinner.get_restart_indices(unrst_fname)
    assert len(orig_rstindices) == 4

    sys.argv = ["restartthinner", "-d", "-n", "2", unrst_fname]
    restartthinner.main()

    # Check that dry run did not do anything
    assert os.path.exists(unrst_fname)
    assert len(orig_rstindices) == len(restartthinner.get_restart_indices(unrst_fname))

    # Now go down to two points, this should give us the first and last.
    sys.argv = ["restartthinner", "-n", "2", unrst_fname, "--keep"]
    restartthinner.main()

    assert os.path.exists(unrst_fname)
    assert os.path.exists(unrst_fname + ".orig")  # The backed up file

    new_rstindices = restartthinner.get_restart_indices(unrst_fname)
    assert len(new_rstindices) == 2
    assert new_rstindices[0] == orig_rstindices[0]
    assert new_rstindices[-1] == orig_rstindices[-1]
    assert len(restartthinner.get_restart_indices(unrst_fname + ".orig")) == 4
Exemplo n.º 3
0
def test_dryrun(tmp_path, mocker):
    """Test dry-run"""
    shutil.copyfile(ECLDIR / UNRST_FNAME, tmp_path / UNRST_FNAME)

    os.chdir(tmp_path)

    orig_rstindices = restartthinner.get_restart_indices(UNRST_FNAME)
    assert len(orig_rstindices) == 4

    mocker.patch("sys.argv", ["restartthinner", "-d", "-n", "2", UNRST_FNAME])
    restartthinner.main()

    # Check that dry run did not do anything
    assert Path(UNRST_FNAME).exists()
    assert len(orig_rstindices) == len(restartthinner.get_restart_indices(UNRST_FNAME))
Exemplo n.º 4
0
def test_first_and_last(tmpdir, mocker):
    """Ask for two restart points, this should give us the first and last."""
    shutil.copyfile(ECLDIR / UNRST_FNAME, tmpdir.join(UNRST_FNAME))

    orig_rstindices = restartthinner.get_restart_indices(UNRST_FNAME)

    tmpdir.chdir()
    mocker.patch("sys.argv",
                 ["restartthinner", "-n", "2", UNRST_FNAME, "--keep"])
    restartthinner.main()

    assert Path(UNRST_FNAME).exists()
    assert Path(UNRST_FNAME + ".orig").exists()  # The backed up file

    new_rstindices = restartthinner.get_restart_indices(UNRST_FNAME)
    assert len(new_rstindices) == 2
    assert new_rstindices[0] == orig_rstindices[0]
    assert new_rstindices[-1] == orig_rstindices[-1]
    assert len(restartthinner.get_restart_indices(UNRST_FNAME + ".orig")) == 4