Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_main(tmpdir):
"""Test command line interface"""
tmpcsvfile = str(tmpdir.join("pvt.csv"))
sys.argv = ["ecl2csv", "pvt", "-v", DATAFILE, "-o", tmpcsvfile]
ecl2csv.main()
assert os.path.exists(tmpcsvfile)
disk_df = pd.read_csv(tmpcsvfile)
assert "PVTNUM" in disk_df
assert "KEYWORD" in disk_df
assert not disk_df.empty
# Write back to include file:
incfile = str(tmpdir.join("pvt.inc"))
sys.argv = ["csv2ecl", "pvt", "-v", str(tmpcsvfile), "-o", incfile]
csv2ecl.main()
# Reparse the include file on disk back to dataframe
# and check dataframe equality
assert os.path.exists(incfile)
disk_inc_df = pvt.df(open(incfile).read())
assert "FIPNUM" in disk_df
assert "EQLNUM" not in disk_df
assert len(disk_df) == 7675
# Group pr. FIPNUM:
sys.argv = [
"ecl2csv",
"pillars",
DATAFILE,
"--region",
"FIPNUM",
"--group",
"-o",
str(tmpcsvfile),
]
ecl2csv.main()
assert os.path.exists(str(tmpcsvfile))
disk_df = pd.read_csv(str(tmpcsvfile))
assert "PILLAR" not in disk_df # because of grouping
assert "FIPNUM" in disk_df # grouped by this.
assert len(disk_df) == 6
# Test dates:
sys.argv = [
"ecl2csv",
"pillars",
DATAFILE,
"--region",
"",
"--group",
"--rstdates",
"first",
def test_prettyprint():
"""Test pretty printing via command line interface"""
sys.argv = ["ecl2csv", "gruptree", DATAFILE, "--prettyprint"]
ecl2csv.main()
def test_main_subparser():
"""Test command line interface"""
tmpcsvfile = ".TMP-equil.csv"
sys.argv = ["ecl2csv", "equil", DATAFILE, "-o", tmpcsvfile]
ecl2csv.main()
assert os.path.exists(tmpcsvfile)
disk_df = pd.read_csv(tmpcsvfile)
assert not disk_df.empty
os.remove(tmpcsvfile)
assert os.path.exists(str(tmpcsvfile))
disk_df = pd.read_csv(str(tmpcsvfile))
assert not disk_df.empty
tmpcsvfile = tmpdir.join(".TMP-rft2.csv")
# Test with RFT file as argument:
sys.argv = [
"ecl2cvsv",
"rft",
"-v",
DATAFILE.replace(".DATA", ".RFT"),
"-o",
str(tmpcsvfile),
]
ecl2csv.main()
assert os.path.exists(str(tmpcsvfile))
disk_df = pd.read_csv(str(tmpcsvfile))
assert not disk_df.empty
def test_main_subparsers(tmpdir):
"""Test command line interface"""
tmpcsvfile = tmpdir.join(".TMP-satfunc.csv")
sys.argv = ["ecl2csv", "satfunc", DATAFILE, "-o", str(tmpcsvfile)]
ecl2csv.main()
assert os.path.exists(str(tmpcsvfile))
disk_df = pd.read_csv(str(tmpcsvfile))
assert not disk_df.empty
tmpcsvfile2 = tmpdir.join(".TMP-satfunc-swof.csv")
print(tmpcsvfile2)
sys.argv = [
"ecl2csv",
"satfunc",
DATAFILE,
"--keywords",
"SWOF",
"--output",
str(tmpcsvfile2),
]