Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: Adding unitests for datetime_utils.py module. #1072

Merged
merged 1 commit into from
Mar 14, 2022
Merged
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
66 changes: 66 additions & 0 deletions pyart/util/tests/test_datetime_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
""" Unit tests for Py-ART's util/datetime_utils.py module. """

import cftime
import netCDF4

import pyart


radar = pyart.testing.make_empty_ppi_radar(10, 36, 1)
def test_datetime_from_radar():
test_date = cftime.DatetimeGregorian(1989, 1, 1, 0, 0, 1, 0)

date = pyart.util.datetime_from_radar(radar, epoch=False)
assert date == test_date

date_epoch = pyart.util.datetime_from_radar(radar, epoch=True)
assert date_epoch == test_date


def test_datetimes_from_radar():
test_date_first = cftime.DatetimeGregorian(1989, 1, 1, 0, 0, 1, 0)
test_date_last = cftime.DatetimeGregorian(1989, 1, 1, 0, 0, 36, 0)

dates = pyart.util.datetimes_from_radar(radar, epoch=False)
assert dates[0] == test_date_first
assert dates[-1] == test_date_last

dates_epoch = pyart.util.datetimes_from_radar(radar, epoch=True)
assert dates_epoch[0] == test_date_first
assert dates_epoch[-1] == test_date_last


ds = netCDF4.Dataset(pyart.testing.CFRADIAL_PPI_FILE)
def test_datetime_from_dataset():
test_date = cftime.DatetimeGregorian(2011, 5, 20, 10, 54, 16, 0)

date = pyart.util.datetime_from_dataset(ds, epoch=False)
assert date == test_date

date_epoch = pyart.util.datetime_from_dataset(ds, epoch=True)
assert date_epoch == test_date


def test_datetimes_from_dataset():
test_date_first = cftime.DatetimeGregorian(2011, 5, 20, 10, 54, 16, 0)
test_date_last = cftime.DatetimeGregorian(2011, 5, 20, 10, 54, 15, 0)

dates = pyart.util.datetimes_from_dataset(ds, epoch=False)
assert dates[0] == test_date_first
assert dates[-1] == test_date_last

dates_epoch = pyart.util.datetimes_from_dataset(ds, epoch=True)
assert dates_epoch[0] == test_date_first
assert dates_epoch[-1] == test_date_last


grid = pyart.testing.make_empty_grid(
(2, 5, 5), ((0,1000), (-2500, 2500), (-2500, 2500)))
def test_datetime_from_grid():
test_date = cftime.DatetimeGregorian(2000, 1, 1, 0, 0, 0, 0)

date = pyart.util.datetime_from_grid(grid, epoch=False)
assert date == test_date

date_epoch = pyart.util.datetime_from_grid(grid, epoch=True)
assert date_epoch == test_date