Repository: climate Updated Branches: refs/heads/master 5207ddaca -> 14e980fa6
Add unittest to test calc_time_series Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/14e980fa Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/14e980fa Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/14e980fa Branch: refs/heads/master Commit: 14e980fa63d809f02c39e8ab57fd3b943d1a5ca1 Parents: 6f49bd5 Author: Kim Whitehall <[email protected]> Authored: Mon Mar 23 10:15:40 2015 -0700 Committer: Kim Whitehall <[email protected]> Committed: Fri Apr 10 15:04:00 2015 -0700 ---------------------------------------------------------------------- ocw/tests/test_utils.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/14e980fa/ocw/tests/test_utils.py ---------------------------------------------------------------------- diff --git a/ocw/tests/test_utils.py b/ocw/tests/test_utils.py index a5c8db6..36cf42f 100644 --- a/ocw/tests/test_utils.py +++ b/ocw/tests/test_utils.py @@ -213,11 +213,29 @@ class TestCalcClimatologyMonthly(unittest.TestCase): def test_calc_climatology_monthly(self): expected_result = np.ones(300).reshape(12, 5, 5) - expected_times = np.array([datetime.datetime(1, 1, 1) + relativedelta(months = x) for x in range(12)]) + expected_times = np.array([datetime.datetime(1, 1, 1) + relativedelta(months = x) + for x in range(12)]) actual_result, actual_times = utils.calc_climatology_monthly(self.dataset) np.testing.assert_array_equal(actual_result, expected_result) np.testing.assert_array_equal(actual_times, expected_times) +class TestCalcTimeSeries(unittest.TestCase): + ''' Tests the 'calc_time_series' method from ocw.utils.py ''' + def setUp(self): + self.lats = np.array([10, 20, 30, 40, 50]) + self.lons = np.array([20, 30, 40, 50, 60]) + start_date = datetime.datetime(2000, 1, 1) + self.times = np.array([start_date + relativedelta(months=x) + for x in range(12)]) + self.values = np.ones(300).reshape(12, 5, 5) + self.variable = 'testdata' + self.dataset = Dataset(self.lats, self.lons, self.times, + self.values, self.variable) + + def test_calc_time_series(self): + expected_result = np.ones(12) + np.testing.assert_array_equal(utils.calc_time_series(self.dataset), expected_result) + if __name__ == '__main__': unittest.main()
