Repository: yt-project/yt

Issue:
TST: missing tests for SpectralCubeCoordinateHandler class
While working on #4179 I discovered that we don't have any tests exercising this geometry.
Even minimal testing would be very valuable.


Discussion:

Resolving patch:
diff --git a/yt/frontends/stream/data_structures.py b/yt/frontends/stream/data_structures.py
--- a/yt/frontends/stream/data_structures.py
+++ b/yt/frontends/stream/data_structures.py
@@ -23,6 +23,7 @@
 from yt.data_objects.static_output import Dataset, ParticleFile
 from yt.data_objects.unions import MeshUnion
 from yt.frontends.sph.data_structures import SPHParticleIndex
+from yt.funcs import setdefaultattr
 from yt.geometry.geometry_handler import Index, YTDataChunk
 from yt.geometry.grid_geometry_handler import GridIndex
 from yt.geometry.oct_container import OctreeContainer
@@ -340,6 +341,27 @@ def __init__(
         name = f"InMemoryParameterFile_{uuid.uuid4().hex}"
         from yt.data_objects.static_output import _cached_datasets
 
+        if geometry == "spectral_cube":
+            # mimick FITSDataset specific interface to allow testing with
+            # fake, in memory data
+            setdefaultattr(self, "lon_axis", 0)
+            setdefaultattr(self, "lat_axis", 1)
+            setdefaultattr(self, "spec_axis", 2)
+            setdefaultattr(self, "lon_name", "X")
+            setdefaultattr(self, "lat_name", "Y")
+            setdefaultattr(self, "spec_name", "z")
+            setdefaultattr(self, "spec_unit", "")
+            setdefaultattr(
+                self,
+                "pixel2spec",
+                lambda pixel_value: self.arr(pixel_value, self.spec_unit),
+            )
+            setdefaultattr(
+                self,
+                "spec2pixel",
+                lambda spec_value: self.arr(spec_value, "code_length"),
+            )
+
         _cached_datasets[name] = self
         Dataset.__init__(
             self,


Test patch:
diff --git a/tests/tests.yaml b/tests/tests.yaml
--- a/tests/tests.yaml
+++ b/tests/tests.yaml
@@ -227,6 +227,7 @@ other_tests:
      - "--ignore-files=test_set_zlim\\.py"
      - "--ignore-file=test_add_field\\.py"
      - "--ignore-file=test_glue\\.py"
+     - "--ignore-file=test_geometries\\.py"
      - "--exclude-test=yt.frontends.gdf.tests.test_outputs.TestGDF"
      - "--exclude-test=yt.frontends.adaptahop.tests.test_outputs"
      - "--exclude-test=yt.frontends.stream.tests.test_stream_particles.test_stream_non_cartesian_particles"
diff --git a/yt/geometry/coordinates/tests/test_axial_pixelization.py b/yt/geometry/coordinates/tests/test_axial_pixelization.py
--- a/yt/geometry/coordinates/tests/test_axial_pixelization.py
+++ b/yt/geometry/coordinates/tests/test_axial_pixelization.py
@@ -4,5 +4,9 @@
 
 def test_axial_pixelization():
     for geom in sorted(_geom_transforms):
+        if geom == "spectral_cube":
+            # skip this case as it was added much later and we don't want to keep
+            # adding yield-based tests during the nose->pytest migration
+            continue
         ds = fake_amr_ds(geometry=geom)
         yield AxialPixelizationTest(ds)
diff --git a/yt/geometry/tests/test_geometries.py b/yt/geometry/tests/test_geometries.py
new file mode 100644
--- /dev/null
+++ b/yt/geometry/tests/test_geometries.py
@@ -0,0 +1,31 @@
+import pytest
+
+import yt
+from yt.testing import fake_amr_ds
+
+
+@pytest.mark.parametrize(
+    "geometry",
+    [
+        "cartesian",
+        "polar",
+        "cylindrical",
+        "spherical",
+        "geographic",
+        "internal_geographic",
+        "spectral_cube",
+    ],
+)
+def test_testable_geometries(geometry):
+    # check that initializing a simple fake dataset works in any geometry
+    ds = fake_amr_ds(fields=[("gas", "density")], units=["g/cm**3"], geometry=geometry)
+    # make sure basic plotting works
+    for axis in range(3):
+        if "geographic" in geometry and axis == 2:
+            pytest.skip(
+                reason=(
+                    "cannot test this case with vanilla yt (requires cartopy) "
+                    "see https://github.com/yt-project/yt/issues/4182"
+                )
+            )
+        yt.SlicePlot(ds, axis, ("gas", "density"), buff_size=(8, 8))
diff --git a/yt/testing.py b/yt/testing.py
--- a/yt/testing.py
+++ b/yt/testing.py
@@ -299,6 +299,7 @@ def fake_random_ds(
     "polar": ((0.0, 0.0, 0.0), (1.0, 2.0 * np.pi, 1.0)),  # rtz
     "geographic": ((-90.0, -180.0, 0.0), (90.0, 180.0, 1000.0)),  # latlonalt
     "internal_geographic": ((-90.0, -180.0, 0.0), (90.0, 180.0, 1000.0)),  # latlondep
+    "spectral_cube": ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)),
 }