22import tempfile
33from unittest .mock import Mock
44
5- import dateutil
5+ import dateutil .tz
6+ import dateutil .rrule
67import numpy as np
78import pytest
8- import pytz
99
1010from matplotlib .testing .decorators import image_comparison
1111import matplotlib .pyplot as plt
1212from matplotlib .cbook import MatplotlibDeprecationWarning
1313import matplotlib .dates as mdates
1414
1515
16+ def __has_pytz ():
17+ try :
18+ import pytz
19+ return True
20+ except ImportError :
21+ return False
22+
23+
1624def test_date_numpyx ():
1725 # test that numpy dates work properly...
1826 base = datetime .datetime (2017 , 1 , 1 )
@@ -180,8 +188,8 @@ def test_RRuleLocator():
180188
181189def test_RRuleLocator_dayrange ():
182190 loc = mdates .DayLocator ()
183- x1 = datetime .datetime (year = 1 , month = 1 , day = 1 , tzinfo = pytz .UTC )
184- y1 = datetime .datetime (year = 1 , month = 1 , day = 16 , tzinfo = pytz .UTC )
191+ x1 = datetime .datetime (year = 1 , month = 1 , day = 1 , tzinfo = mdates .UTC )
192+ y1 = datetime .datetime (year = 1 , month = 1 , day = 16 , tzinfo = mdates .UTC )
185193 loc .tick_values (x1 , y1 )
186194 # On success, no overflow error shall be thrown
187195
@@ -482,8 +490,8 @@ def test_date_inverted_limit():
482490
483491def _test_date2num_dst (date_range , tz_convert ):
484492 # Timezones
485- BRUSSELS = pytz . timezone ('Europe/Brussels' )
486- UTC = pytz .UTC
493+ BRUSSELS = dateutil . tz . gettz ('Europe/Brussels' )
494+ UTC = mdates .UTC
487495
488496 # Create a list of timezone-aware datetime objects in UTC
489497 # Interval is 0b0.0000011 days, to prevent float rounding issues
@@ -575,10 +583,7 @@ def tz_convert(*args):
575583 _test_date2num_dst (pd .date_range , tz_convert )
576584
577585
578- @pytest .mark .parametrize ("attach_tz, get_tz" , [
579- (lambda dt , zi : zi .localize (dt ), lambda n : pytz .timezone (n )),
580- (lambda dt , zi : dt .replace (tzinfo = zi ), lambda n : dateutil .tz .gettz (n ))])
581- def test_rrulewrapper (attach_tz , get_tz ):
586+ def _test_rrulewrapper (attach_tz , get_tz ):
582587 SYD = get_tz ('Australia/Sydney' )
583588
584589 dtstart = attach_tz (datetime .datetime (2017 , 4 , 1 , 0 ), SYD )
@@ -593,6 +598,25 @@ def test_rrulewrapper(attach_tz, get_tz):
593598 assert act == exp
594599
595600
601+ def test_rrulewrapper ():
602+ def attach_tz (dt , zi ):
603+ return dt .replace (tzinfo = zi )
604+
605+ _test_rrulewrapper (attach_tz , dateutil .tz .gettz )
606+
607+
608+ @pytest .mark .pytz
609+ @pytest .mark .skipif (not __has_pytz (), reason = "Requires pytz" )
610+ def test_rrulewrapper_pytz ():
611+ # Test to make sure pytz zones are supported in rrules
612+ import pytz
613+
614+ def attach_tz (dt , zi ):
615+ return zi .localize (dt )
616+
617+ _test_rrulewrapper (attach_tz , pytz .timezone )
618+
619+
596620def test_DayLocator ():
597621 with pytest .raises (ValueError ):
598622 mdates .DayLocator (interval = - 1 )
0 commit comments