climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject [3/8] climate git commit: CLIMATE-639 - Add subregion support to configuration parsing
Date Mon, 01 Jun 2015 18:02:36 GMT
CLIMATE-639 - Add subregion support to configuration parsing

- Add subregion support to config parsing.
- Add tests for parsing bad subregion information.


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/2357078a
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/2357078a
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/2357078a

Branch: refs/heads/master
Commit: 2357078afc91f1abcb8b5887cf3905f95628a261
Parents: 6ab02d8
Author: Michael Joyce <joyce@apache.org>
Authored: Thu May 28 11:01:19 2015 -0700
Committer: Michael Joyce <joyce@apache.org>
Committed: Thu May 28 11:01:19 2015 -0700

----------------------------------------------------------------------
 ocw-config-runner/configuration_parsing.py     | 24 +++++++++++++
 ocw-config-runner/tests/test_config_parsing.py | 38 +++++++++++++++++++++
 2 files changed, 62 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/2357078a/ocw-config-runner/configuration_parsing.py
----------------------------------------------------------------------
diff --git a/ocw-config-runner/configuration_parsing.py b/ocw-config-runner/configuration_parsing.py
index 477488e..be8bd00 100644
--- a/ocw-config-runner/configuration_parsing.py
+++ b/ocw-config-runner/configuration_parsing.py
@@ -117,6 +117,11 @@ def _config_is_well_formed(config_data):
             if not _valid_plot_config_data(plot):
                 is_well_formed = False
 
+    if 'subregions' in config_data:
+        for subregion in config_data['subregions']:
+            if not _valid_subregion_config_data(subregion):
+                is_well_formed = False
+
     return is_well_formed
 
 def _contains_unary_metrics(config_metric_data):
@@ -233,3 +238,22 @@ def _valid_plot_config_data(plot_config_data):
 
     return True
 
+def _valid_subregion_config_data(subregion_config_data):
+    """"""
+    if type(subregion_config_data) != type([]):
+        logger.error(
+            'Subregions should be passed as a list of lists where '
+            'each sub-list contains a bounding box of the form: '
+            '[lat_min, lat_max, lon_min, lon_max].'
+        )
+        return False
+
+    if len(subregion_config_data) != 4:
+        logger.error(
+            'Subregions should be passed as a list of lists where '
+            'each sub-list contains a bounding box of the form: '
+            '[lat_min, lat_max, lon_min, lon_max].'
+        )
+        return False
+
+    return True

http://git-wip-us.apache.org/repos/asf/climate/blob/2357078a/ocw-config-runner/tests/test_config_parsing.py
----------------------------------------------------------------------
diff --git a/ocw-config-runner/tests/test_config_parsing.py b/ocw-config-runner/tests/test_config_parsing.py
index 9df9980..88a08f7 100644
--- a/ocw-config-runner/tests/test_config_parsing.py
+++ b/ocw-config-runner/tests/test_config_parsing.py
@@ -290,6 +290,36 @@ class TestConfigIsWellFormed(unittest.TestCase):
         """
         bad_plot = yaml.load(bad_plot_config)
 
+        bad_subregion_config_type = """
+            datasets:
+                reference:
+                    data_source: dap
+                    url: afakeurl.com
+                    variable: pr
+
+            metrics:
+                - Bias
+
+            subregions:
+                - this is a string instead of a list
+        """
+        self.bad_subregion_type = yaml.load(bad_subregion_config_type)
+
+        bad_subregion_config_length = """
+            datasets:
+                reference:
+                    data_source: dap
+                    url: afakeurl.com
+                    variable: pr
+
+            metrics:
+                - Bias
+
+            subregions:
+                - [1, 2, 3, 4, 5]
+        """
+        self.bad_subregion_length = yaml.load(bad_subregion_config_length)
+
     def test_malformed_reference_config(self):
         ret = parser._config_is_well_formed(self.malformed_reference_conf)
         self.assertFalse(ret)
@@ -320,6 +350,14 @@ class TestConfigIsWellFormed(unittest.TestCase):
     def test_bad_plot_config(self):
         ret = parser._config_is_well_formed(self.missing_metric_name)
         self.assertFalse(ret)
+    
+    def test_bad_subregion_type(self):
+        ret = parser._config_is_well_formed(self.bad_subregion_type)
+        self.assertFalse(ret)
+
+    def test_bad_subregion_length(self):
+        ret = parser._config_is_well_formed(self.bad_subregion_length)
+        self.assertFalse(ret)
 
 
 class MetricFetchTest(unittest.TestCase):


Mime
View raw message