def test_get_filestem( regsurf, edataobj1, name, tagname, parentname, time0, time1, expected, ): """Testing the private _get_filestem method.""" objdata = _ObjectDataProvider(regsurf, edataobj1) objdata.name = name objdata.time0 = time0 objdata.time1 = time1 edataobj1.tagname = tagname edataobj1.parent = parentname edataobj1.name = "" fdata = _FileDataProvider( edataobj1, objdata, ) stem = fdata._get_filestem() assert stem == expected
def test_get_filestem_shall_fail( regsurf, edataobj1, name, tagname, parentname, time0, time1, message, ): """Testing the private _get_filestem method when it shall fail.""" objdata = _ObjectDataProvider(regsurf, edataobj1) objdata.name = name objdata.time0 = time0 objdata.time1 = time1 edataobj1.tagname = tagname edataobj1.parent = parentname edataobj1.name = "" fdata = _FileDataProvider(edataobj1, objdata) with pytest.raises(ValueError) as msg: _ = fdata._get_filestem() assert message in str(msg)
def test_filedata_provider(regsurf, edataobj1, tmp_path): """Testing the derive_filedata function.""" os.chdir(tmp_path) cfg = edataobj1 cfg.createfolder = True cfg._rootpath = Path(".") cfg.name = "" objdata = _ObjectDataProvider(regsurf, edataobj1) objdata.name = "name" objdata.efolder = "efolder" objdata.extension = ".ext" objdata.time0 = "t1" objdata.time1 = "t2" fdata = _FileDataProvider(cfg, objdata) fdata.derive_filedata() print(fdata.relative_path) assert fdata.relative_path == "share/results/efolder/parent--name--tag--t1_t2.ext" absdata = str(tmp_path / "share/results/efolder/parent--name--tag--t1_t2.ext") assert fdata.absolute_path == absdata
def test_objectdata_regularsurface_validate_extension_shall_fail(regsurf, edataobj1): """Test an invalid extension for RegularSurface object.""" with pytest.raises(ConfigurationError): _ = _ObjectDataProvider(regsurf, edataobj1)._validate_get_ext( "some_invalid", "RegularSurface", _ValidFormats().surface )
def test_objectdata_regularsurface_derive_objectdata(regsurf, edataobj1): """Derive other properties.""" res = _ObjectDataProvider(regsurf, edataobj1)._derive_objectdata() assert res["subtype"] == "RegularSurface" assert res["classname"] == "surface" assert res["extension"] == ".gri"
def test_objectdata_regularsurface_validate_extension(regsurf, edataobj1): """Test a valid extension for RegularSurface object.""" ext = _ObjectDataProvider(regsurf, edataobj1)._validate_get_ext( "irap_binary", "RegularSurface", _ValidFormats().surface ) assert ext == ".gri"
def test_objectdata_regularsurface_derive_metadata(regsurf, edataobj1): """Derive all metadata for the 'data' block in fmu-dataio.""" myobj = _ObjectDataProvider(regsurf, edataobj1) myobj.derive_metadata() res = myobj.metadata assert res["content"] == "depth" assert res["alias"]
def test_objectdata_regularsurface_spec_bbox(regsurf, edataobj1): """Derive specs and bbox for RegularSurface object.""" specs, bbox = _ObjectDataProvider( regsurf, edataobj1 )._derive_spec_bbox_regularsurface() assert specs["ncol"] == regsurf.ncol assert bbox["xmin"] == 0.0 assert bbox["zmin"] == 1234.0
def test_objectdata_regularsurface_derive_name_stratigraphy_differ(regsurf, edataobj2): """Get name and some stratigaphic keys for a valid RegularSurface object .""" # mimic the stripped parts of configuations for testing here objdata = _ObjectDataProvider(regsurf, edataobj2) res = objdata._derive_name_stratigraphy() assert res["name"] == "VOLANTIS GP. Top" assert "TopVolantis" in res["alias"] assert res["stratigraphic"] is True
def _populate_meta_objectdata(self): """Analyze the actual object together with input settings. This will provide input to the ``data`` block of the metas but has also valuable settings which are needed when providing filedata etc. Hence this must be ran early or first. """ self.objdata = _ObjectDataProvider(self.obj, self.dataio) self.objdata.derive_metadata() self.meta_objectdata = self.objdata.metadata
def test_get_paths_not_exists_so_create(regsurf, edataobj1, tmp_path): """Testing the private _get_path method, creating the path.""" os.chdir(tmp_path) objdata = _ObjectDataProvider(regsurf, edataobj1) objdata.name = "some" objdata.efolder = "efolder" cfg = edataobj1 cfg.createfolder = True cfg._rootpath = Path(".") fdata = _FileDataProvider(cfg, objdata) path = fdata._get_path() assert str(path) == "share/results/efolder"
def test_get_paths_path_exists_already(regsurf, edataobj1, tmp_path): """Testing the private _get_path method.""" os.chdir(tmp_path) newpath = tmp_path / "share" / "results" / "efolder" newpath.mkdir(parents=True, exist_ok=True) edataobj1.name = "some" objdata = _ObjectDataProvider(regsurf, edataobj1) objdata.name = "some" objdata.efolder = "efolder" fdata = _FileDataProvider(edataobj1, objdata) path = fdata._get_path() assert str(path) == "share/results/efolder"