def test_glob_smry_keys(): """Test the globbing function for virtual realization""" empty_vreal = ensemble.VirtualRealization() with pytest.raises(ValueError): empty_vreal._glob_smry_keys("FOP*") if "__file__" in globals(): # Easen up copying test code into interactive sessions testdir = os.path.dirname(os.path.abspath(__file__)) else: testdir = os.path.abspath(".") realdir = os.path.join(testdir, "data/testensemble-reek001", "realization-0/iter-0") real = ensemble.ScratchRealization(realdir) real.load_smry(time_index="yearly", column_keys=["F*", "W*"]) vreal = real.to_virtual() assert len(vreal._glob_smry_keys("FOP*")) == 9 assert len(vreal._glob_smry_keys("FOP?")) == 3 assert len(vreal._glob_smry_keys(["FOP*"])) == 9 assert len(vreal._glob_smry_keys("WOPT:*")) == 8 assert all([x.startswith("WOPT:") for x in vreal._glob_smry_keys("WOPT:*")]) assert not vreal._glob_smry_keys("FOOBAR")
def test_get_smry_dates(): """Test date grid functionality from a virtual realization. Already internalized summary data is needed for this""" # First test with no data: empty_vreal = ensemble.VirtualRealization() with pytest.raises(ValueError): empty_vreal.get_smry_dates() if "__file__" in globals(): # Easen up copying test code into interactive sessions testdir = os.path.dirname(os.path.abspath(__file__)) else: testdir = os.path.abspath(".") realdir = os.path.join(testdir, "data/testensemble-reek001", "realization-0/iter-0") real = ensemble.ScratchRealization(realdir) real.load_smry(time_index="yearly", column_keys=["F*", "W*"]) vreal = real.to_virtual() assert len(vreal.get_smry_dates(freq="monthly")) == 49 assert len(vreal.get_smry_dates(freq="daily")) == 1462 assert len(vreal.get_smry_dates(freq="yearly")) == 5 with pytest.raises(ValueError): assert vreal.get_smry_dates(freq="foobar")
def test_virtual_fromdisk(tmp="TMP"): """Test retrieval of a virtualrealization that has been dumped to disk""" if "__file__" in globals(): # Easen up copying test code into interactive sessions testdir = os.path.dirname(os.path.abspath(__file__)) else: testdir = os.path.abspath(".") # First make a ScratchRealization to virtualize and dump: realdir = os.path.join(testdir, "data/testensemble-reek001", "realization-0/iter-0") real = ensemble.ScratchRealization(realdir) # Internalize some data that we can test for afterwards real.load_smry(time_index="yearly", column_keys=["F*"]) real.load_scalar("npv.txt") if not os.path.exists(tmp): os.mkdir(tmp) # Virtualize and dump to disk: real.to_virtual().to_disk(os.path.join(tmp, "virtreal2"), delete=True) # Reload the virtualized realization back from disk: vreal = ensemble.VirtualRealization("foo") vreal.load_disk(os.path.join(tmp, "virtreal2")) for key in vreal.keys(): if isinstance(real.get_df(key), (pd.DataFrame, dict)): assert len(real.get_df(key)) == len(vreal.get_df(key)) else: # Scalars: assert real.get_df(key) == vreal.get_df(key) assert real.get_df("parameters")["FWL"] == vreal.get_df( "parameters")["FWL"] assert (real.get_df("unsmry--yearly").iloc[-1]["FGIP"] == vreal.get_df( "unsmry--yearly").iloc[-1]["FGIP"]) assert real.get_df("npv.txt") == 3444
def test_get_smry_cumulative(): """Test the cumulative boolean function""" vreal = ensemble.VirtualRealization() assert isinstance(vreal._smry_cumulative([]), list) with pytest.raises(TypeError): vreal._smry_cumulative({}) with pytest.raises(TypeError): vreal._smry_cumulative() assert vreal._smry_cumulative(["FOPT"])[0] assert not vreal._smry_cumulative(["FOPR"])[0] assert not vreal._smry_cumulative(["FWCT"])[0] assert vreal._smry_cumulative(["WOPT:A-1"])[0] assert not vreal._smry_cumulative(["WOPR:A-1T"])[0]