You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by jo...@apache.org on 2013/08/20 19:58:03 UTC

svn commit: r1515903 - /incubator/climate/trunk/ocw/tests/test_dataset.py

Author: joyce
Date: Tue Aug 20 17:58:02 2013
New Revision: 1515903

URL: http://svn.apache.org/r1515903
Log:
CLIMATE-267 - Add tests for Dataset input validation

Modified:
    incubator/climate/trunk/ocw/tests/test_dataset.py

Modified: incubator/climate/trunk/ocw/tests/test_dataset.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw/tests/test_dataset.py?rev=1515903&r1=1515902&r2=1515903&view=diff
==============================================================================
--- incubator/climate/trunk/ocw/tests/test_dataset.py (original)
+++ incubator/climate/trunk/ocw/tests/test_dataset.py Tue Aug 20 17:58:02 2013
@@ -48,6 +48,42 @@ class TestDatasetAttributes(unittest.Tes
     def test_variable(self):
         self.assertEqual(self.test_dataset.variable, self.variable)
 
+class TestInvalidDatasetInit(unittest.TestCase):
+    def setUp(self):
+        self.lat = np.array([10, 12, 14, 16, 18])
+        self.lon = np.array([100, 102, 104, 106, 108])
+        self.time = np.array([dt.datetime(2000, x, 1) for x in range(1, 13)])
+        flat_array = np.array(range(300))
+        self.value = flat_array.reshape(12, 5, 5)
+
+    def test_bad_lat_shape(self):
+        self.lat = np.array([[1, 2], [3, 4]])
+        with self.assertRaises(ValueError):
+            Dataset(self.lat, self.lon, self.time, self.value, 'prec')
+
+    def test_bad_lon_shape(self):
+        self.lon = np.array([[1, 2], [3, 4]])
+        with self.assertRaises(ValueError):
+            Dataset(self.lat, self.lon, self.time, self.value, 'prec')
+
+    def test_bad_times_shape(self):
+        self.time = np.array([[1, 2], [3, 4]])
+        with self.assertRaises(ValueError):
+            Dataset(self.lat, self.lon, self.time, self.value, 'prec')
+
+    def test_bad_values_shape(self):
+        self.value = np.array([[1, 2], [2, 3], [3, 4], [4, 5]])
+        with self.assertRaises(ValueError):
+            Dataset(self.lat, self.lon, self.time, self.value, 'prec')
+
+    def test_values_shape_mismatch(self):
+        # If we change lats to this the shape of value will not match
+        # up with the length of the lats array.
+        self.lat = self.lat[:-2]
+        with self.assertRaises(ValueError):
+            Dataset(self.lat, self.lon, self.time, self.value, 'prec')
+
+
 
 class TestDatasetFunctions(unittest.TestCase):
     def setUp(self):