From d89ceb6b452462a0704fca4030e9c506001bf42f Mon Sep 17 00:00:00 2001
From: "oriol.tinto" <oriol.tinto@lmu.de>
Date: Thu, 16 Nov 2023 15:08:20 +0100
Subject: [PATCH] Add tests for constant arrays and variables without lat_lon

---
 tests/test_analyzer.py | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/tests/test_analyzer.py b/tests/test_analyzer.py
index 184f417..05162dc 100644
--- a/tests/test_analyzer.py
+++ b/tests/test_analyzer.py
@@ -15,6 +15,32 @@ class TestAnalyzer(TestClass):
             input_path = input_tempdir / ds
             analyze_files(file_paths=[input_path])
 
+    def test_analyzer_constant_array(self):
+        import enstools.compression.xr_accessor  # noqa
+        import numpy as np
+        import xarray as xr
+
+        shape = (100, 100, 100)
+        data = np.zeros(shape)
+        data_array = xr.DataArray(data)
+        # Expect a warning about constant values
+        with pytest.warns(UserWarning, match="All values in the variable .* are constant."):
+            specs, metrics = data_array.compression.analyze()
+
+        data_array.compression(specs)
+
+    def test_analyzer_without_lat_lon(self):
+        import enstools.compression.xr_accessor  # noqa
+        import numpy as np
+        import xarray as xr
+
+        shape = (100, 100, 100)
+        data = np.random.random(size=shape)
+        data_array = xr.DataArray(data)
+        specs, metrics = data_array.compression.analyze()
+        data_array.compression(specs)
+
+
     def test_zfp_analyzer(self):
         from enstools.compression.api import analyze_files
         input_tempdir = self.input_directory_path
@@ -60,8 +86,9 @@ class TestAnalyzer(TestClass):
 
             for var in metrics:
                 if abs(metrics[var][cr_label] - thresholds[cr_label]) > TOLERANCE:
-                    raise AssertionError(f"Case:{input_path.name}.The resulting compression ratio of {metrics[var][cr_label]:.2f}"
-                                         f"x is not close enough to the target of {thresholds[cr_label]:.2f}")
+                    raise AssertionError(
+                        f"Case:{input_path.name}.The resulting compression ratio of {metrics[var][cr_label]:.2f}"
+                        f"x is not close enough to the target of {thresholds[cr_label]:.2f}")
 
     def test_sz_analyzer(self):
         from enstools.compression.api import analyze_files
@@ -85,6 +112,7 @@ class TestAnalyzer(TestClass):
                           compressor="zfp",
                           mode="rate",
                           )
+
     def test_rmse(self):
         from enstools.compression.api import analyze_files
         input_tempdir = self.input_directory_path
-- 
GitLab