Repository: climate
Updated Branches:
  refs/heads/master aaa3bc5c4 -> 71c8a502e


Add new tests for the dataset module


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

Branch: refs/heads/master
Commit: 71c8a502e11849c347f3ff8536949810135b2425
Parents: 5ecaa8e
Author: Ibrahim <jarifibra...@gmail.com>
Authored: Sun Jun 5 21:22:52 2016 +0530
Committer: Ibrahim <jarifibra...@gmail.com>
Committed: Tue Jun 14 00:51:58 2016 +0530

----------------------------------------------------------------------
 ocw/tests/test_dataset.py | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/71c8a502/ocw/tests/test_dataset.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_dataset.py b/ocw/tests/test_dataset.py
index d30fbcc..dcf6490 100644
--- a/ocw/tests/test_dataset.py
+++ b/ocw/tests/test_dataset.py
@@ -91,6 +91,9 @@ class TestInvalidDatasetInit(unittest.TestCase):
         self.value = np.array([1, 2, 3, 4, 5])
         with self.assertRaises(ValueError):
             Dataset(self.lat, self.lon, self.time, self.value, 'prec')
+        self.value = self.value.reshape(1, 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
@@ -142,6 +145,26 @@ class TestDatasetFunctions(unittest.TestCase):
     def test_spatial_resolution(self):
         self.assertEqual(self.test_dataset.spatial_resolution(), (2, 2))
 
+    def test_spatial_resolution_2_dim_lat_lon(self):
+        self.lat = np.array([10, 12, 14, 16, 18, 20])
+        self.lon = np.array([100, 102, 104, 106, 108, 110])
+        self.lat = self.lat.reshape(3, 2)
+        self.lon = self.lon.reshape(3, 2)
+        flat_array = np.array(range(72))
+        self.value = flat_array.reshape(12, 3, 2)
+        self.test_dataset = Dataset(self.lat, self.lon, self.time,
+                                    self.value, self.variable)
+        self.assertEqual(self.test_dataset.spatial_resolution(), (6, 6))
+
+    def test_temporal_resolution_hourly(self):
+        self.time = np.array([dt.datetime(2000, 1, 1),
+                              dt.datetime(2000, 1, 1)])
+        flat_array = np.array(range(50))
+        self.value = flat_array.reshape(2, 5, 5)
+        self.test_dataset = Dataset(self.lat, self.lon, self.time,
+                                    self.value, self.variable)
+        self.assertEqual(self.test_dataset.temporal_resolution(), 'minutely')
+
     def test_temporal_resolution_monthly(self):
         self.assertEqual(self.test_dataset.temporal_resolution(), 'monthly')
 
@@ -197,6 +220,22 @@ class TestBounds(unittest.TestCase):
                              dt.datetime(2002, 1, 1))  # End time
         self.another_bounds = Bounds(-80, 80,                # Lats
                                      -160, 160)
+
+    def test_setter_methods(self):
+        self.bounds.lat_min = -10
+        self.bounds.lat_max = 10
+        self.bounds.lon_min = -120
+        self.bounds.lon_max = 120
+        self.bounds.start = dt.datetime(2000, 1, 2)
+        self.bounds.end = dt.datetime(2002, 1, 4)
+
+        self.assertEqual(self.bounds.lat_min, -10)
+        self.assertEqual(self.bounds.lat_max, 10)
+        self.assertEqual(self.bounds.lon_min, -120)
+        self.assertEqual(self.bounds.lon_max, 120)
+        self.assertEqual(self.bounds.start, dt.datetime(2000, 1, 2))
+        self.assertEqual(self.bounds.end, dt.datetime(2002, 1, 4))
+
     # Latitude tests
     def test_inverted_min_max_lat(self):
         with self.assertRaises(ValueError):

Reply via email to