From 5f417d13e900b8aa645a2b0afcf53beb4e1b9767 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Sat, 14 Oct 2017 14:13:14 -0400 Subject: Add test for dateutil.utils.today --- .travis.yml | 2 ++ dateutil/test/test_utils.py | 24 +++++++++++++++++++++++- setup.py | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 748070d..df75f38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,9 @@ matrix: before_install: # Install codecov - if [[ $TRAVIS_PYTHON_VERSION == '3.2' ]]; then pip install coverage==3.7.1; fi + - if [[ $TRAVIS_PYTHON_VERSION < '3.0' ]]; then pip install mock; fi - pip install codecov + - pip install freezegun install: - pip install six diff --git a/dateutil/test/test_utils.py b/dateutil/test/test_utils.py index e8f605b..9100995 100644 --- a/dateutil/test/test_utils.py +++ b/dateutil/test/test_utils.py @@ -1,10 +1,32 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals from datetime import timedelta, datetime -from dateutil.utils import within_delta + import unittest +from dateutil import tz +from dateutil.utils import within_delta, today + +from freezegun import freeze_time + +UTC = tz.tzutc() +NYC = tz.gettz("America/New_York") + + class UtilsTest(unittest.TestCase): + @freeze_time(datetime(2014, 12, 15, 1, 21, 33, 4003)) + def testToday(self): + self.assertEqual(today(), datetime(2014, 12, 15, 0, 0, 0)) + + @freeze_time(datetime(2014, 12, 15, 12), tz_offset=5) + def testTodayTzInfo(self): + self.assertEqual(today(NYC), + datetime(2014, 12, 15, 0, 0, 0, tzinfo=NYC)) + + @freeze_time(datetime(2014, 12, 15, 23), tz_offset=5) + def testTodayTzInfoDifferentDay(self): + self.assertEqual(today(UTC), + datetime(2014, 12, 16, 0, 0, 0, tzinfo=UTC)) def testWithinDelta(self): d1 = datetime(2016, 1, 1, 12, 14, 1, 9) diff --git a/setup.py b/setup.py index db6e62a..5ac36bc 100644 --- a/setup.py +++ b/setup.py @@ -26,6 +26,7 @@ datetime module available in the Python standard library. package_data={"dateutil.zoneinfo": ["dateutil-zoneinfo.tar.gz"]}, zip_safe=True, requires=["six"], + tests_require=["freezegun"], install_requires=["six >=1.5"], # XXX fix when packaging is sane again classifiers=[ 'Development Status :: 5 - Production/Stable', -- cgit v1.2.3