Repository: ioos/compliance-checker
Pull request #875 (2021-07-29 20:05:07)

Variable features case insensitive

benjwadams: Addresses case-sensitivity issues mentioned in #858 by @mhidas.
benjwadams: @mhidas, please review and see if this works for you at this point

Patch:
diff --git a/compliance_checker/cf/cf.py b/compliance_checker/cf/cf.py
index 99cc71d..065c5fa 100644
--- a/compliance_checker/cf/cf.py
+++ b/compliance_checker/cf/cf.py
@@ -4423,18 +4423,19 @@ class CF1_6Check(CFNCCheck):
         """
         feature_types_found = defaultdict(list)
         ret_val = []
-        feature_list = [
+        feature_list = {
             "point",
-            "timeSeries",
+            "timeseries",
             "trajectory",
             "profile",
-            "timeSeriesProfile",
-            "trajectoryProfile",
-        ]
+            "timeseriesprofile",
+            "trajectoryprofile",
+        }
         # Don't bother checking if it's not a legal featureType
         # if the featureType attribute doesn't exist
         feature_type = getattr(ds, "featureType", None)
-        if feature_type not in feature_list:
+        if (feature_type is not None and
+            feature_type.lower() not in feature_list):
             return []
 
         # If a data set is detected as a valid ragged array representation,
@@ -4443,7 +4444,7 @@ class CF1_6Check(CFNCCheck):
         if cfutil.is_dataset_valid_ragged_array_repr_featureType(ds, feature_type):
             _feature = "ragged-array"
         else:
-            _feature = feature_type
+            _feature = feature_type.lower()
 
         for name in self._find_geophysical_vars(ds):
             variable_feature = cfutil.guess_feature_type(ds, name)
@@ -4451,9 +4452,10 @@ class CF1_6Check(CFNCCheck):
             if variable_feature is None:
                 continue
             feature_types_found[variable_feature].append(name)
-            matching_feature = TestCtx(BaseCheck.MEDIUM, self.section_titles["9.1"])
+            matching_feature = TestCtx(BaseCheck.MEDIUM,
+                                       self.section_titles["9.1"])
             matching_feature.assert_true(
-                variable_feature == _feature,
+                variable_feature.lower() == _feature,
                 "{} is not a {}, it is detected as a {}"
                 "".format(name, _feature, variable_feature),
             )


Test patch:
diff --git a/compliance_checker/tests/test_cf.py b/compliance_checker/tests/test_cf.py
index 778df91..298cda6 100644
--- a/compliance_checker/tests/test_cf.py
+++ b/compliance_checker/tests/test_cf.py
@@ -1655,6 +1655,18 @@ class TestCF1_7(BaseTestCase):
         message = u"Cell measure variable box_area referred to by PS is not present in dataset variables"
         assert message in messages
 
+    def test_variable_features(self):
+        with MockTimeSeries() as dataset:
+            # I hope to never see an attribute value like this, but since
+            # it's case insensitive, it still should work
+            dataset.featureType = "tImEsERiEs"
+            # dimensionless variable for cf_role
+            station = dataset.createVariable("station", "i", ())
+            station.cf_role = "timeseries_id"
+            results = self.cf.check_variable_features(dataset)
+            score, out_of, messages = get_results(results)
+            assert score == out_of and score > 0
+
     def test_process_vdatum(self):
         # first, we set up a mock SQLite database
         conn_str = ":memory:"