Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions tests/test_date_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
import collections
import unittest

from pytest import mark
from netCDF4 import num2date
Expand All @@ -8,7 +9,12 @@
resolution_standard_name, \
jday_360_to_remapped_month_day, \
to_datetime, \
truncate_to_resolution
truncate_to_resolution, \
time_to_seconds, \
seconds_to_time

from nchelpers.exceptions import \
CFValueError


@mark.parametrize('arg, result', [
Expand Down Expand Up @@ -95,4 +101,18 @@ def test_to_datetime_360(jday_360, month, day):
(datetime(2012, 5, 1), "seasonal", datetime(2012, 3, 1))
])
def test_truncate_to_resolution(date, resolution, expected):
assert(truncate_to_resolution(date, resolution)) == expected
assert(truncate_to_resolution(date, resolution)) == expected

class CFValueErrorTestCases(unittest.TestCase):
def test_time_to_seconds(self):
with self.assertRaises(CFValueError):
time_to_seconds(604800, 'weeks')

def test_seconds_to_time(self):
with self.assertRaises(CFValueError):
seconds_to_time(604800, 'weeks')

class ValueErrorTestCases(unittest.TestCase):
def test_truncate_to_resolution(self):
with self.assertRaises(ValueError):
truncate_to_resolution('unimportant_date', {})