Repository: equinor/fmu-dataio

Issue:
Return `TriangulatedSurfaceDataProvider` from object data provider factory
It should a type check and return the correct type from the object data provider factory.

https://github.com/equinor/fmu-dataio/blob/beac99977bd954f24c2186efc39df5ef8c1458e2/src/fmu/dataio/providers/objectdata/_provider.py#L169-L181

Hints from issue comments:

Solution patch:
diff --git a/src/fmu/dataio/providers/objectdata/_provider.py b/src/fmu/dataio/providers/objectdata/_provider.py
index e47104b6d..7cd10bf18 100644
--- a/src/fmu/dataio/providers/objectdata/_provider.py
+++ b/src/fmu/dataio/providers/objectdata/_provider.py
@@ -98,6 +98,7 @@ import xtgeo
 from fmu.dataio._definitions import ExportFolder, FileExtension
 from fmu.dataio._logging import null_logger
 from fmu.dataio._models.fmu_results.enums import FileFormat, FMUClass, Layout
+from fmu.dataio._readers.tsurf import TSurfData
 from fmu.dataio.readers import FaultRoomSurface
 
 from ._base import (
@@ -105,6 +106,7 @@ from ._base import (
 )
 from ._faultroom import FaultRoomSurfaceProvider
 from ._tables import ArrowTableDataProvider, DataFrameDataProvider
+from ._triangulated_surface import TriangulatedSurfaceProvider
 from ._xtgeo import (
     CPGridDataProvider,
     CPGridPropertyDataProvider,
@@ -170,6 +172,10 @@ def objectdata_provider_factory(
         return FaultRoomSurfaceProvider(
             obj=obj, dataio=dataio, standard_result=standard_result
         )
+    if isinstance(obj, TSurfData):
+        return TriangulatedSurfaceProvider(
+            obj=obj, dataio=dataio, standard_result=standard_result
+        )
     if isinstance(obj, dict):
         return DictionaryDataProvider(
             obj=obj, dataio=dataio, standard_result=standard_result


Test patch:
diff --git a/tests/test_units/test_objectdataprovider_class.py b/tests/test_units/test_objectdataprovider_class.py
index b7d91b88a..d28083089 100644
--- a/tests/test_units/test_objectdataprovider_class.py
+++ b/tests/test_units/test_objectdataprovider_class.py
@@ -8,12 +8,18 @@ import pytest
 import yaml
 
 from fmu import dataio
-from fmu.dataio._models.fmu_results.specification import FaultRoomSurfaceSpecification
+from fmu.dataio._models.fmu_results.specification import (
+    FaultRoomSurfaceSpecification,
+    TriangulatedSurfaceSpecification,
+)
 from fmu.dataio.exceptions import ConfigurationError
 from fmu.dataio.providers.objectdata._faultroom import FaultRoomSurfaceProvider
 from fmu.dataio.providers.objectdata._provider import (
     objectdata_provider_factory,
 )
+from fmu.dataio.providers.objectdata._triangulated_surface import (
+    TriangulatedSurfaceProvider,
+)
 from fmu.dataio.providers.objectdata._xtgeo import RegularSurfaceDataProvider
 
 from ..conftest import remove_ert_env, set_ert_env_prehook
@@ -82,6 +88,43 @@ def test_objectdata_faultroom_fault_juxtaposition_get_stratigraphy_differ(
     assert frss.juxtaposition_hw == ["Valysar Fm.", "Therys Fm.", "Volon Fm."]
 
 
+def test_objectdata_triangulated_surface_validate_spec(tsurf, edataobj2):
+    """
+    Validate the specifications of the triangulated surface object represented
+    in the TSurf format.
+    TSurf is a file format used in for example the GOCAD software. RMS can export
+    triangulated surfaces in its structural model in the TSurf format.
+    """
+    objdata = objectdata_provider_factory(tsurf, edataobj2)
+    assert isinstance(objdata, TriangulatedSurfaceProvider)
+
+    assert objdata.classname.value == "triangulated_surface"
+    assert objdata.efolder == "maps"
+    assert objdata.extension == ".ts"
+    assert objdata.fmt == "tsurf"
+    assert objdata.layout == "triangulated_surface"
+
+    bbox = objdata.get_bbox()
+    assert bbox.xmin == 0.1
+    assert bbox.xmax == 3.1
+    assert bbox.ymin == 0.2
+    assert bbox.ymax == 3.2
+    assert bbox.zmin == 0.3
+    assert bbox.zmax == 3.3
+
+    tri_surf_spec = objdata.get_spec()
+    assert isinstance(tri_surf_spec, TriangulatedSurfaceSpecification)
+    assert tri_surf_spec.num_vertices == 4
+    assert tri_surf_spec.num_triangles == 2
+
+    encoding = "utf-8"
+    buffer = BytesIO()
+    objdata.export_to_file(buffer)
+    buffer.seek(0)
+    # Check the first 14 bytes of the buffer
+    assert buffer.read(14).decode(encoding=encoding) == "GOCAD TSurf 1\n"
+
+
 def test_objectdata_regularsurface_validate_extension(regsurf, edataobj1):
     """Test a valid extension for RegularSurface object."""