def test_main(tmpdir): """Test invocation from command line""" tmpdir.chdir() datafilepath = os.path.join(ECLDIR, ECLCASE) sys.argv = ["pack_sim", datafilepath, "."] pack_sim.main() assert os.path.exists(ECLCASE) assert os.path.exists("include")
def test_main(tmp_path, mocker): """Test invocation from command line""" os.chdir(tmp_path) datafilepath = ECLDIR / ECLCASE mocker.patch("sys.argv", ["pack_sim", str(datafilepath), "."]) pack_sim.main() assert Path(ECLCASE).exists() assert Path("include/reek.grid").exists() assert Path("include/reek.perm").exists() assert Path("include/reek.pvt").exists() assert Path("include/swof.inc").exists()
def test_strip_comments(tmp_path, mocker): """Test that we can strip comments""" os.chdir(tmp_path) datafilepath = ECLDIR / ECLCASE size_with_comments = os.stat(datafilepath).st_size mocker.patch("sys.argv", ["pack_sim", "-c", str(ECLDIR / ECLCASE), "."]) pack_sim.main() size_no_comments = os.stat(ECLCASE).st_size assert size_no_comments < size_with_comments assert "--" not in Path(ECLCASE).read_text(encoding="utf8") for includefile in os.listdir("include"): assert "--" not in (Path("include") / includefile).read_text()
def test_main_fmu(tmpdir, mocker): tmpdir.chdir() datafilepath = ECLDIR / ECLCASE mocker.patch("sys.argv", ["pack_sim", str(datafilepath), ".", "--fmu"]) pack_sim.main() # Test a subset of the files that should be there, paths # here are different from the test above without the "--fmu" option: assert (Path("model") / Path(ECLCASE)).exists() assert Path("include/edit").exists() assert Path("include/grid/reek.grid").exists() assert Path("include/props/reek.pvt").exists()
def test_strip_comments(tmpdir): """Test that we can strip comments""" tmpdir.chdir() datafilepath = os.path.join(ECLDIR, ECLCASE) size_with_comments = os.stat(datafilepath).st_size sys.argv = ["pack_sim", "-c", os.path.join(ECLDIR, ECLCASE), "."] pack_sim.main() size_no_comments = os.stat(ECLCASE).st_size assert size_no_comments < size_with_comments assert "--" not in "".join(open(ECLCASE).readlines()) for includefile in os.listdir("include"): assert "--" not in "".join( open(os.path.join("include", includefile)).readlines())
def test_main_fmu(tmp_path, mocker): """Test the --fmu option on the command line, yielding a different directory layout""" os.chdir(tmp_path) datafilepath = ECLDIR / ECLCASE mocker.patch("sys.argv", ["pack_sim", str(datafilepath), ".", "--fmu"]) pack_sim.main() # Test a subset of the files that should be there, paths # here are different from the test above without the "--fmu" option: assert (Path("model") / Path(ECLCASE)).exists() assert Path("include/edit").exists() assert Path("include/grid/reek.grid").exists() assert Path("include/props/reek.pvt").exists()
def test_restart_warning(injected, expectedwarning, tmp_path, mocker, capsys): """Test that warnings are emitted on various contents in the DATA file""" os.chdir(tmp_path) shutil.copytree(ECLDIR.parent / "include", "include", copy_function=os.symlink) shutil.copytree(ECLDIR.parent / "model", "model", copy_function=os.symlink) os.remove("model/" + ECLCASE) shutil.copy(ECLDIR.parent / "model" / ECLCASE, "model/" + ECLCASE) datafile = Path("model") / ECLCASE mocker.patch("sys.argv", ["pack_sim", str(datafile), "."]) modifieddata = "\n".join( datafile.read_text(encoding="utf8").splitlines() + [injected]) datafile.write_text(modifieddata, encoding="utf8") pack_sim.main() captured = capsys.readouterr() assert expectedwarning in captured.out
def test_repeated_run(tmp_path, mocker): """Test what happens on repeated incovations""" os.chdir(tmp_path) datafilepath = ECLDIR / ECLCASE mocker.patch("sys.argv", ["pack_sim", str(datafilepath), ".", "--fmu"]) pack_sim.main() with pytest.raises(ValueError, match="will not overwrite"): pack_sim.main() os.remove("model/" + ECLCASE) # Here it will reuse the packed include files: pack_sim.main() # But error if a file is not writable: os.remove("model/" + ECLCASE) os.chmod("include/grid/reek.perm", 0) with pytest.raises(IOError): pack_sim.main()