def test_long_vfp_lines(tmpdir, caplog): tmpdir.chdir() Path("vfp.inc").write_text( """VFPPROD 1 100 'GAS' 'WGR' 'GOR' 'THP' ' ' 'METRIC' 'BHP' / 100000 300000 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 / 30 50 / 0 / 5000 / 0 / -- This two-line record might get emitted as one long line by opm-common -- This will error in Eclipse 1 1 1 1 35.4324212 37.234245 39.2343242 40.4324234 43.23523546 45.54676535 47.3242356 49.345345 50.2342343 52.4353456 54.24342344 56.32424324 / 2 1 1 1 55.4324212 57.234245 59.2343242 60.4324234 63.23523546 65.54676535 67.3242356 69.345345 70.2342343 72.4353456 74.24342344 76.32424324 /""", encoding="utf-8", ) Path("conf.yml").write_text("files:\n - vfp.inc\noutput: sch.inc", encoding="utf-8") sys.argv = ["sunsch", "conf.yml"] sunsch.main() schinc = Path("sch.inc").read_text() assert max([len(line) for line in schinc.split("\n")]) <= 129 assert "Line 7 had length 146, wrapped" in caplog.text
def test_long_vfp_lines(tmp_path, caplog, mocker): """Make sure that lines can't get too long for Eclipse""" os.chdir(tmp_path) Path("vfp.inc").write_text( """VFPPROD 1 100 'GAS' 'WGR' 'GOR' 'THP' ' ' 'METRIC' 'BHP' / 100000 300000 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 / 30 50 / 0 / 5000 / 0 / -- This two-line record might get emitted as one long line by opm-common -- This will error in Eclipse 1 1 1 1 35.4324212 37.234245 39.2343242 40.4324234 43.23523546 45.54676535 47.3242356 49.345345 50.2342343 52.4353456 54.24342344 56.32424324 / 2 1 1 1 55.4324212 57.234245 59.2343242 60.4324234 63.23523546 65.54676535 67.3242356 69.345345 70.2342343 72.4353456 74.24342344 76.32424324 /""", encoding="utf-8", ) Path("conf.yml").write_text("files:\n - vfp.inc\noutput: sch.inc", encoding="utf-8") mocker.patch("sys.argv", ["sunsch", "conf.yml"]) sunsch.main() schinc = Path("sch.inc").read_text(encoding="utf8") assert max([len(line) for line in schinc.split("\n")]) <= 129
def test_cmdline_output(testdata, mocker): """Test that command line options can override configuration file""" mocker.patch( "sys.argv", ["sunsch", "--output", "subdir/schedule.inc", "config_v2.yml"]) with pytest.warns(FutureWarning, match="Implicit mkdir"): sunsch.main() assert Path("subdir/schedule.inc").exists()
def test_cmdline_dategrid(testdata, mocker): """Test that dategrid can be overridden on command line""" mocker.patch("sys.argv", ["sunsch", "--dategrid", "daily", "config_v2.yml"]) sunsch.main() assert "6 'JAN' 2017" in Path("schedule.inc").read_text(encoding="utf8") assert "7 'JAN' 2017" in Path("schedule.inc").read_text(encoding="utf8") assert "8 'JAN' 2017" in Path("schedule.inc").read_text(encoding="utf8") assert "9 'JAN' 2017" in Path("schedule.inc").read_text(encoding="utf8")
def test_main_configv1(testdata, caplog, mocker): """Test command line sunsch, loading a yaml file. This is run on a v1 config file, which will be autoconverted to v2. This format is to be deprecated, and should be removed in the future """ mocker.patch("sys.argv", ["sunsch", "config_v1.yml"]) with pytest.raises(SystemExit): sunsch.main()
def test_main_configv1(tmpdir, caplog): """Test command line sunsch, loading a yaml file. This is run on a v1 config file, which will be autoconverted to v2. This format is to be deprecated, and should be removed in the future """ tmpdir.chdir() shutil.copytree(DATADIR, "testdata_sunsch") tmpdir.join("testdata_sunsch").chdir() outfile = "schedule.sch" # also in config_v1.yml if os.path.exists(outfile): os.unlink(outfile) sys.argv = ["sunsch", "config_v1.yml"] sunsch.main() assert "DEPRECATED" in caplog.text assert os.path.exists(outfile) schlines = open(outfile).readlines() assert len(schlines) > 70 # Check footemplate.sch was included: assert any(["A-90" in x for x in schlines]) # Sample check for mergeme.sch: assert any(["WRFTPLT" in x for x in schlines]) # Check for foo1.sch, A-1 should occur twice assert sum(["A-1" in x for x in schlines]) == 2 # Check for substitutetest: assert any(["400000" in x for x in schlines]) # Check for randomid: assert any(["A-4" in x for x in schlines]) # Test that we can have statements in the init file # before the first DATES that are kept: sch_conf = yaml.safe_load(open("config_v1.yml")) print(sch_conf) sch_conf["init"] = "initwithdates.sch" sunsch.process_sch_config(sch_conf) # BAR-FOO is a magic string that occurs before any DATES in initwithdates.sch assert "BAR-FOO" in "".join(open(outfile).readlines())
def test_main_configv1(tmpdir, caplog): """Test command line sunsch, loading a yaml file. This is run on a v1 config file, which will be autoconverted to v2. This format is to be deprecated, and should be removed in the future """ tmpdir.chdir() shutil.copytree(DATADIR, "testdata_sunsch") tmpdir.join("testdata_sunsch").chdir() sys.argv = ["sunsch", "config_v1.yml"] with pytest.raises(SystemExit): sunsch.main()
def test_cmdline_refdate(testdata, mocker): """Test that --refdate on command line overrides config""" # Baseline run, proving refdate follows refdate in config yaml: mocker.patch("sys.argv", ["sunsch", "config_v2.yml"]) sunsch.main() # 40 days after refdate, which is 2018-01-01 in yaml: assert "10 'FEB' 2018" in Path("schedule.inc").read_text() mocker.patch("sys.argv", ["sunsch", "--refdate", "2019-01-01", "config_v2.yml"]) sunsch.main() # It should not be 40 days after startdate, assert "10 'FEB' 2018" not in Path("schedule.inc").read_text() # but 40 days after command line refdate: assert "10 'FEB' 2019" in Path("schedule.inc").read_text()
def test_main(testdata, caplog, mocker): """Test command line sunsch, loading a yaml file""" outfile = "schedule.inc" # also in config_v2.yml mocker.patch("sys.argv", ["sunsch", "config_v2.yml"]) sunsch.main() assert "DEPRECATED" not in caplog.text assert Path(outfile).exists() schlines = Path(outfile).read_text(encoding="utf8").splitlines() assert len(schlines) > 70 # Check footemplate.sch was included: assert any("A-90" in x for x in schlines) # Sample check for mergeme.sch: assert any("WRFTPLT" in x for x in schlines) # Check for foo1.sch, A-1 should occur twice assert sum("A-1" in x for x in schlines) == 2 # Check for substitutetest: assert any("400000" in x for x in schlines) # Check for randomid: assert any("A-4" in x for x in schlines) # Test that we can have statements in the init file # before the first DATES that are kept: sch_conf = yaml.safe_load(Path("config_v2.yml").read_text(encoding="utf8")) print(sch_conf) sch_conf["init"] = "initwithdates.sch" sunsch.process_sch_config(sch_conf) # BAR-FOO is a magic string that occurs before any DATES in initwithdates.sch assert "BAR-FOO" in "".join( Path(outfile).read_text(encoding="utf8").splitlines())
def test_cmdline_startdate(testdata, mocker): """Test that --startdate on command line overrides config""" mocker.patch("sys.argv", ["sunsch", "--startdate", "2020-01-01", "config_v2.yml"]) sunsch.main() assert "2018" not in Path("schedule.inc").read_text(encoding="utf8")