11import calendar
22import datetime
33import warnings
4+ import zoneinfo
45
56import numpy as np
6- import pandas as pd
7-
8- from .conftest import assert_frame_equal , assert_series_equal
97from numpy .testing import assert_allclose
8+ import pandas as pd
109import pytest
11- import pytz
1210
13- from pvlib .location import Location
1411from pvlib import solarposition , spa
15-
16- from .conftest import (
17- requires_ephem , requires_spa_c , requires_numba , requires_pandas_2_0
12+ from pvlib .location import Location
13+ from pvlib .tests .conftest import (
14+ assert_frame_equal , assert_series_equal , requires_ephem , requires_spa_c ,
15+ requires_numba , requires_pandas_2_0 ,
1816)
1917
18+
2019# setup times and locations to be tested.
2120times = pd .date_range (start = datetime .datetime (2014 , 6 , 24 ),
2221 end = datetime .datetime (2014 , 6 , 26 ), freq = '15min' )
@@ -348,13 +347,12 @@ def test_calc_time():
348347 # validation from USNO solar position calculator online
349348
350349 epoch = datetime .datetime (1970 , 1 , 1 )
351- epoch_dt = pytz . utc . localize ( epoch )
350+ epoch_dt = epoch . replace ( tzinfo = zoneinfo . ZoneInfo ( "UTC" ) )
352351
353352 loc = tus
354- actual_time = pytz .timezone (loc .tz ).localize (
355- datetime .datetime (2014 , 10 , 10 , 8 , 30 ))
356- lb = pytz .timezone (loc .tz ).localize (datetime .datetime (2014 , 10 , 10 , tol ))
357- ub = pytz .timezone (loc .tz ).localize (datetime .datetime (2014 , 10 , 10 , 10 ))
353+ actual_time = datetime .datetime (2014 , 10 , 10 , 8 , 30 , tzinfo = loc .tz )
354+ lb = datetime .datetime (2014 , 10 , 10 , tol , tzinfo = loc .tz )
355+ ub = datetime .datetime (2014 , 10 , 10 , 10 , tzinfo = loc .tz )
358356 alt = solarposition .calc_time (lb , ub , loc .latitude , loc .longitude ,
359357 'alt' , math .radians (24.7 ))
360358 az = solarposition .calc_time (lb , ub , loc .latitude , loc .longitude ,
@@ -724,9 +722,12 @@ def test_hour_angle_with_tricky_timezones():
724722 '2014-09-07 02:00:00' ,
725723 ]).tz_localize ('America/Santiago' , nonexistent = 'shift_forward' )
726724
727- with pytest .raises (pytz .exceptions .NonExistentTimeError ):
725+ # should raise `pytz.exceptions.NonExistentTimeError`
726+ with pytest .raises (Exception , match = "2014-09-07 00:00:00" ) as exc_info :
728727 times .normalize ()
729728
729+ assert exc_info .type .__name__ == "NonExistentTimeError"
730+
730731 # should not raise `pytz.exceptions.NonExistentTimeError`
731732 solarposition .hour_angle (times , longitude , eot )
732733
@@ -738,9 +739,15 @@ def test_hour_angle_with_tricky_timezones():
738739 '2014-11-02 02:00:00' ,
739740 ]).tz_localize ('America/Havana' , ambiguous = [True , True , False , False ])
740741
741- with pytest .raises (pytz .exceptions .AmbiguousTimeError ):
742+ # should raise `pytz.exceptions.AmbiguousTimeError`
743+ with pytest .raises (
744+ Exception ,
745+ match = "Cannot infer dst time from 2014-11-02 00:00:00" ,
746+ ) as exc_info :
742747 solarposition .hour_angle (times , longitude , eot )
743748
749+ assert exc_info .type .__name__ == "AmbiguousTimeError"
750+
744751
745752def test_sun_rise_set_transit_geometric (expected_rise_set_spa , golden_mst ):
746753 """Test geometric calculations for sunrise, sunset, and transit times"""
0 commit comments