Skip to content

Commit

Permalink
Merge pull request sunpy#7351 from nabobalis/py312
Browse files Browse the repository at this point in the history
Add python 3.12 tests
  • Loading branch information
nabobalis authored Jan 10, 2024
2 parents 6b159bc + afeee63 commit 7961e29
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 25 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
apt:
- libopenjp2-7
envs: |
- linux: py311
- linux: py312
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Expand All @@ -47,8 +47,9 @@ jobs:
brew:
- openjpeg
envs: |
- windows: py310
- macos: py39
- windows: py311
- macos: py310
- linux: py39
- linux: py39-oldestdeps
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Expand Down Expand Up @@ -178,9 +179,9 @@ jobs:
test_command: 'pytest -p no:warnings --doctest-rst -m "not mpl_image_compare" --pyargs sunpy'
submodules: false
targets: |
- cp3{9,10,11}-manylinux*_x86_64
- cp3{9,10,11}-macosx_x86_64
- cp3{9,10,11}-macosx_arm64
- cp3{9,10,11,12}-manylinux*_x86_64
- cp3{9,10,11,12}-macosx_x86_64
- cp3{9,10,11,12}-macosx_arm64
secrets:
pypi_token: ${{ secrets.pypi_token }}

Expand Down
1 change: 1 addition & 0 deletions changelog/7351.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added testing and explicit support for Python 3.12.
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ classifiers =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Topic :: Scientific/Engineering :: Physics

[options]
Expand Down Expand Up @@ -60,7 +61,7 @@ image =
scipy>=1.7.0,!=1.10.0
jpeg2000 =
glymur>=0.9.1,!=0.9.5
lxml>=4.8.0
lxml>=4.8.0,!=5.0.0
map =
matplotlib>=3.5.0
mpl-animators>=1.0.0
Expand Down Expand Up @@ -236,6 +237,8 @@ filterwarnings =
ignore:.*module is deprecated, as it was designed for internal use
# This is raised when the VSO redirects and we do not want this to stop the CI
ignore::sunpy.util.exceptions.SunpyConnectionWarning
# Can be removed when https://github.com/dateutil/dateutil/issues/1314 is resolved
ignore:datetime.datetime.utcfromtimestamp():DeprecationWarning

[pycodestyle]
max_line_length = 110
Expand Down Expand Up @@ -273,7 +276,6 @@ omit =
sunpy/cython_version*
sunpy/*setup*
sunpy/extern/*
sunpy/*/tests/*
sunpy/version*
sunpy/__init__*
sunpy/data/sample.py
Expand All @@ -283,7 +285,6 @@ omit =
*/sunpy/cython_version*
*/sunpy/*setup*
*/sunpy/extern/*
*/sunpy/*/tests/*
*/sunpy/version*
*/sunpy/__init__*
*/sunpy/data/sample.py
Expand Down
28 changes: 27 additions & 1 deletion sunpy/map/header_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,33 @@ def make_heliographic_header(date, observer_coordinate, shape, *, frame, project
>>> observer = get_earth(date)
>>> header = make_heliographic_header(date, observer, [90, 180], frame='carrington')
>>> header
MetaDict([('wcsaxes', 2), ('crpix1', 90.5), ('crpix2', 45.5), ('cdelt1', 2.0), ('cdelt2', 2.0), ('cunit1', 'deg'), ('cunit2', 'deg'), ('ctype1', 'CRLN-CAR'), ('ctype2', 'CRLT-CAR'), ('crval1', 0.0), ('crval2', 0.0), ('lonpole', 0.0), ('latpole', 90.0), ('mjdref', 0.0), ('date-obs', '2020-01-01T12:00:00.000'), ('rsun_ref', 695700000.0), ('dsun_obs', 147096975776.97), ('hgln_obs', 0.0), ('hglt_obs', -3.0011725838606), ('naxis', 2), ('naxis1', 180), ('naxis2', 90), ('pc1_1', 1.0), ('pc1_2', -0.0), ('pc2_1', 0.0), ('pc2_2', 1.0), ('rsun_obs', 975.5398432033492)])
MetaDict([('wcsaxes': '2')
('crpix1': '90.5')
('crpix2': '45.5')
('cdelt1': '2.0')
('cdelt2': '2.0')
('cunit1': 'deg')
('cunit2': 'deg')
('ctype1': 'CRLN-CAR')
('ctype2': 'CRLT-CAR')
('crval1': '0.0')
('crval2': '0.0')
('lonpole': '0.0')
('latpole': '90.0')
('mjdref': '0.0')
('date-obs': '2020-01-01T12:00:00.000')
('rsun_ref': '695700000.0')
('dsun_obs': '147096975776.97')
('hgln_obs': '0.0')
('hglt_obs': '-3.0011725838606')
('naxis': '2')
('naxis1': '180')
('naxis2': '90')
('pc1_1': '1.0')
('pc1_2': '-0.0')
('pc2_1': '0.0')
('pc2_2': '1.0')
('rsun_obs': '975.53984320334...
.. minigallery:: sunpy.map.make_heliographic_header
"""
Expand Down
12 changes: 8 additions & 4 deletions sunpy/net/dataretriever/sources/tests/test_noaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ def test_fetch(mock_wait, mock_search, mock_enqueue, tmp_path, indices_client):
# Downloader.enqueue_file method with the correct arguments. Everything
# that happens after this point should either be tested in the
# GenericClient tests or in parfive itself.
assert mock_enqueue.called_once_with(("https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json",
path / "observed-solar-cycle-indices.json"))
mock_enqueue.assert_called_once_with(
Time("2012-10-04 00:00:00.000", "2012-10-06 00:00:00.000"),
Instrument("noaa-indices")
)


@mock.patch('sunpy.net.dataretriever.sources.noaa.NOAAIndicesClient.search',
Expand All @@ -151,8 +153,10 @@ def test_fido(mock_wait, mock_search, mock_enqueue, tmp_path, indices_client):
# Downloader.enqueue_file method with the correct arguments. Everything
# that happens after this point should either be tested in the
# GenericClient tests or in parfive itself.
assert mock_enqueue.called_once_with(("https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json",
path / "observed-solar-cycle-indices.json"))
mock_enqueue.assert_called_once_with(
Time('2012-10-04 00:00:00.000', '2012-10-06 00:00:00.000'),
Instrument("noaa-indices")
)


@no_vso
Expand Down
2 changes: 1 addition & 1 deletion sunpy/net/jsoc/tests/test_jsoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def test_row_and_warning(mocker, client, jsoc_response_double):
request_data = mocker.patch("sunpy.net.jsoc.jsoc.JSOCClient.request_data")
with pytest.warns(SunpyUserWarning):
client.fetch(jsoc_response_double[0], sleep=0)
assert request_data.called_once_with(jsoc_response_double[0].as_table())
request_data.assert_called_once_with(jsoc_response_double[0].as_table())


@pytest.mark.remote_data
Expand Down
10 changes: 5 additions & 5 deletions sunpy/net/tests/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
from sunpy.net import attrs as a
from sunpy.time import TimeRange, parse_time

TimesLeapsecond = sampled_from((Time('2015-06-30T23:59:60'),
TIME_LEAP_SECONDS = sampled_from((Time('2015-06-30T23:59:60'),
Time('2012-06-30T23:59:60')))


@st.composite
def Times(draw, max_value, min_value):
time = one_of(datetimes(max_value=max_value, min_value=min_value),
TimesLeapsecond)
TIME_LEAP_SECONDS)

time = Time(draw(time))

Expand Down Expand Up @@ -74,7 +74,7 @@ def online_instruments():

@st.composite
def time_attr(draw, time=Times(
max_value=datetime.datetime(datetime.datetime.utcnow().year, 1, 1, 0, 0),
max_value=datetime.datetime(datetime.datetime.now(datetime.timezone.utc).year, 1, 1, 0, 0),
min_value=datetime.datetime(1981, 1, 1, 0, 0)),
delta=TimeDelta()):
"""
Expand All @@ -90,7 +90,7 @@ def time_attr(draw, time=Times(

@st.composite
def goes_time(draw, time=Times(
max_value=datetime.datetime(datetime.datetime.utcnow().year, 1, 1, 0, 0),
max_value=datetime.datetime(datetime.datetime.now(datetime.timezone.utc).year, 1, 1, 0, 0),
min_value=datetime.datetime(1981, 1, 1, 0, 0)),
delta=TimeDelta()):
"""
Expand All @@ -116,7 +116,7 @@ def goes_time(draw, time=Times(

@st.composite
def srs_time(draw, time=Times(
max_value=datetime.datetime.now(),
max_value=datetime.datetime.now(datetime.timezone.utc),
min_value=datetime.datetime(1996, 1, 1)),
delta=TimeDelta()):
t1 = draw(time)
Expand Down
4 changes: 2 additions & 2 deletions sunpy/time/tests/test_time.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date, datetime
from datetime import date, datetime, timezone

import numpy as np
import pandas
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_parse_time_list_3():


def test_is_time():
assert time.is_time(datetime.utcnow()) is True
time.is_time(datetime.now(timezone.utc)) is True
assert time.is_time('2017-02-14 08:08:12.999') is True
assert time.is_time(Time.now()) is True

Expand Down
2 changes: 1 addition & 1 deletion sunpy/timeseries/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class TimeSeriesMetaData:
>>> md.find(parse_time('2012-06-01T21:08:12')).values()
['eve_val', 'goes_val']
>>> md.find(parse_time('2012-06-01T21:08:12')).metas
[MetaDict([('goes_key', 'goes_val')]), MetaDict([('eve_key', 'eve_val')])]
[MetaDict([('goes_key': 'goes_val')]), MetaDict([('eve_key': 'eve_val')])]
>>> md.find(parse_time('2012-06-01T21:08:12'), 'GOES')
|-------------------------------------------------------------------------------------------------|
|TimeRange | Columns | Meta |
Expand Down
5 changes: 4 additions & 1 deletion sunpy/util/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def __init__(self, *args, save_original=True):
self._original_meta = MetaDict(*args, save_original=False)

def __str__(self):
return '\n'.join([f'{key}: {item}' for key, item in self.items()])
return '\n'.join([f"('{key}': '{item}')" for key, item in self.items()])

def __repr__(self):
return f"{self.__class__.__name__}([{self}])"

# Deliberately a property to prevent external modification
@property
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
min_version = 4.0
envlist =
py{39,310,311}{,-oldestdeps,-devdeps,-online,-figure,-conda}
py{39,310,311,312}{,-oldestdeps,-devdeps,-online,-figure,-conda}
build_docs{,-gallery}
codestyle
base_deps
Expand Down

0 comments on commit 7961e29

Please sign in to comment.