climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From boust...@apache.org
Subject svn commit: r1515484 - /incubator/climate/branches/RefactorInput/ocw/tests/test_rcmed.py
Date Mon, 19 Aug 2013 16:07:33 GMT
Author: boustani
Date: Mon Aug 19 16:07:33 2013
New Revision: 1515484

URL: http://svn.apache.org/r1515484
Log:
test_rcmed.py now can test values, lats, lons, times and get_parameters_metadata() function.

Modified:
    incubator/climate/branches/RefactorInput/ocw/tests/test_rcmed.py

Modified: incubator/climate/branches/RefactorInput/ocw/tests/test_rcmed.py
URL: http://svn.apache.org/viewvc/incubator/climate/branches/RefactorInput/ocw/tests/test_rcmed.py?rev=1515484&r1=1515483&r2=1515484&view=diff
==============================================================================
--- incubator/climate/branches/RefactorInput/ocw/tests/test_rcmed.py (original)
+++ incubator/climate/branches/RefactorInput/ocw/tests/test_rcmed.py Mon Aug 19 16:07:33 2013
@@ -18,6 +18,7 @@
 import unittest
 import datetime
 import numpy
+import pickle
 import data_source.rcmed as rcmed
 
 
@@ -33,46 +34,54 @@ class test_rcmed(unittest.TestCase):
         self.max_lon = 15
         self.start_time = datetime.datetime(2002, 8, 1)
         self.end_time = datetime.datetime(2002, 10, 1)
+        #start and end time for URL to query database is the beginning and end of start_time
and end_time
+        self.start_time_for_url = "20020801T0000Z"
+        self.end_time_for_url = "20021031T0000Z"
         self.url = "http://rcmes.jpl.nasa.gov/query-api/query.php?"
         self.lats=numpy.arange(50.5, 70, 1)
         self.lons=numpy.arange(1.5, 15, 1)
-        self.times=[datetime.datetime(2002,8,31) + datetime.timedelta(days=x) for x in range(0,
62)]
+        #In this parameter, two days of 10/20 and 10/21 have been missed.
+        self.times=[datetime.datetime(2002, 8, 31) + datetime.timedelta(days=x) for x in
range(0, 62)]
         self.times.remove(datetime.datetime(2002, 10, 20))
         self.times.remove(datetime.datetime(2002, 10, 21))
-        #self.values
+        self.values = pickle.load( open( "parameters_values.p", "rb" ) )
+        self.param_metadata_output = pickle.load( open( "parameters_metadata_output.p", "rb"
) ) 
 
 
     def return_text(self, url):
-        ##TODO: Replace the hard coded start and end time with variables.
         if url == self.url + "datasetId={0}&parameterId={1}&latMin={2}&latMax={3}&lonMin={4}&lonMax={5}&timeStart=20020801T0000Z&timeEnd=20021031T0000Z"\
-                .format(self.dataset_id, self.parameter_id, self.min_lat, self.max_lat, self.min_lon,
self.max_lon):
+                .format(self.dataset_id, self.parameter_id, self.min_lat, self.max_lat, self.min_lon,
self.max_lon, self.start_time_for_url, self.end_time_for_url):
             return open("parameter_dataset_text.txt")
         elif url == self.url + "&param_info=yes":
             return open("parameters_metadata_text.txt")
         else:
-            raise Exceptption ("The URL is not acceptable.")
+            raise Exception ("The URL is not acceptable.")
 
 
-    def test_get_parameters_metadata(self):
+    def test_function_get_parameters_metadata(self):
         rcmed.urllib2.urlopen = self.return_text
-        ##TODO: converting to string may not be very accurate, better approach is necessary
-        self.assertEqual(str(rcmed.get_parameters_metadata()), open('get_parameters_metadata_output.txt','r').read())
+        self.assertEqual(rcmed.get_parameters_metadata(), self.param_metadata_output)
 
 
-    def test_parameter_dataset_latitudes(self):
+    def test_function_parameter_dataset_lats(self):
         rcmed.urllib2.urlopen = self.return_text
         self.assertTrue(numpy.allclose(rcmed.parameter_dataset(self.dataset_id, self.parameter_id,
self.min_lat, self.max_lat, self.min_lon, self.max_lon, self.start_time, self.end_time).lats,
self.lats))
 
 
-    def test_parameter_dataset_longitudes(self):
+    def test_function_parameter_dataset_lons(self):
         rcmed.urllib2.urlopen = self.return_text
         self.assertTrue(numpy.allclose(rcmed.parameter_dataset(self.dataset_id, self.parameter_id,
self.min_lat, self.max_lat, self.min_lon, self.max_lon, self.start_time, self.end_time).lons,
self.lons))
 
 
-    def test_parameter_dataset_times(self):
+    def test_function_parameter_dataset_times(self):
         rcmed.urllib2.urlopen = self.return_text
         self.assertEqual(rcmed.parameter_dataset(self.dataset_id, self.parameter_id, self.min_lat,
self.max_lat, self.min_lon, self.max_lon, self.start_time, self.end_time).times, self.times)
 
 
+    def test_function_parameter_dataset_values(self):
+        rcmed.urllib2.urlopen = self.return_text
+        self.assertTrue(numpy.allclose(rcmed.parameter_dataset(self.dataset_id, self.parameter_id,
self.min_lat, self.max_lat, self.min_lon, self.max_lon, self.start_time, self.end_time).values,
self.values))
+
+
 if __name__ == '__main__':
     unittest.main()
\ No newline at end of file



Mime
View raw message