From 71b2ff112a7ffa3e3d5dfce7563308935de61805 Mon Sep 17 00:00:00 2001 From: Zach Hornung Date: Thu, 15 Jul 2021 16:46:39 -0700 Subject: [PATCH] first open source contribution, added three tests to test_data_utils.py --- CONTRIBUTORS.rst | 3 +++ tests/test_date_utils.py | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 6d1b8d3..f1a1c0d 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -3,6 +3,9 @@ In alphabetical order: * David Bronaugh * Rod Glover * James Hiebert +* Zach Hornung +* Skyler Johnson * Nikola Rados * Basil Veerman * Lee Zeman + diff --git a/tests/test_date_utils.py b/tests/test_date_utils.py index 1acdb5a..df73bb1 100644 --- a/tests/test_date_utils.py +++ b/tests/test_date_utils.py @@ -1,5 +1,7 @@ from datetime import datetime import collections +from nchelpers.exceptions import CFValueError +import pytest from pytest import mark from netCDF4 import num2date @@ -8,7 +10,8 @@ resolution_standard_name, \ jday_360_to_remapped_month_day, \ to_datetime, \ - truncate_to_resolution + truncate_to_resolution, \ + time_scale @mark.parametrize('arg, result', [ @@ -95,4 +98,20 @@ 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 \ No newline at end of file + assert(truncate_to_resolution(date, resolution)) == expected + +def test_time_scale_error_messages(): + with pytest.raises(AttributeError): + time_scale('baby goats') + +def test_time_scale_error2(): + class BabyGoats: + def __init__(self): + self.units = 'baby goats' + with pytest.raises(CFValueError): + time_scale(BabyGoats()) + +def test_hours_conversion_for_resolution_standard_name(): + seconds = 3600 + assert resolution_standard_name(seconds) == '1-hourly' +