Skip to content

Commit

Permalink
Sometimes, 5 coffees is not a good idea
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis committed Mar 29, 2024
1 parent 2baee1a commit a826b7c
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 31 deletions.
2 changes: 2 additions & 0 deletions sunpy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ def pytest_runtest_teardown(item):

@pytest.fixture(scope="session")
def aia171_test_map():
pytest.importorskip("sunpy.map")
from sunpy.map import Map

return Map(get_test_filepath('aia_171_level1.fits'))


Expand Down
2 changes: 2 additions & 0 deletions sunpy/coordinates/tests/test_spice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import numpy as np
import pytest

pytest.importorskip('spiceypy')
import spiceypy

import astropy.units as u
Expand Down
1 change: 1 addition & 0 deletions sunpy/coordinates/tests/test_transformations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pytest

pytest.importorskip('matplotlib')
import astropy.units as u
from astropy.constants import c as speed_of_light
from astropy.coordinates import (
Expand Down
3 changes: 2 additions & 1 deletion sunpy/coordinates/tests/test_wcs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from astropy.time import Time
from astropy.wcs import WCS

import sunpy.map
from sunpy.coordinates.frames import (
Heliocentric,
HeliographicCarrington,
Expand Down Expand Up @@ -93,6 +92,8 @@ def test_wcs_aux():
Make sure auxiliary information round trips properly from coordinate frames
to WCS and back.
"""
pytest.importorskip('sunpy.map')
import sunpy.map
data = np.ones([6, 6], dtype=np.float64)
header = {'CRVAL1': 0,
'CRVAL2': 0,
Expand Down
11 changes: 2 additions & 9 deletions sunpy/io/special/asdf/tests/test_genericmap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import pytest

import asdf
import astropy.units as u
Expand All @@ -25,19 +24,13 @@ def assert_roundtrip_map(old):
assert old.unit == new.unit


@pytest.fixture
def aia171_test_map():
aia_path = get_test_filepath("aia_171_level1.fits")
return sunpy.map.Map(aia_path)


@asdf_entry_points
def test_genericmap_basic(aia171_test_map, tmpdir):
def test_genericmap_basic(aia171_test_map):
assert_roundtrip_map(aia171_test_map)


@asdf_entry_points
def test_genericmap_mask(aia171_test_map, tmpdir):
def test_genericmap_mask(aia171_test_map):
mask = np.zeros_like(aia171_test_map.data)
mask[10, 10] = 1
aia171_test_map.mask = mask
Expand Down
9 changes: 0 additions & 9 deletions sunpy/map/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ def hmi_test_map():
return sunpy.map.Map((data, header))


@pytest.fixture
def aia171_test_map():
(data, header), = sunpy.io.read_file(get_test_filepath('aia_171_level1.fits'))

# Get rid of the blank keyword to prevent some astropy fits fixing warnings
header.pop('BLANK')
return sunpy.map.Map((data, header))


@pytest.fixture
def aia171_roll_map(aia171_test_map):
return aia171_test_map.rotate(-45*u.deg)
Expand Down
1 change: 1 addition & 0 deletions sunpy/physics/tests/test_differential_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import pytest

pytest.importorskip('matplotlib')
import astropy.units as u
from astropy.coordinates import Longitude, SkyCoord
from astropy.tests.helper import assert_quantity_allclose
Expand Down
5 changes: 3 additions & 2 deletions sunpy/tests/self_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

__all__ = ['self_test', '_test_base_deps']
__all__ = ['self_test']

Check warning on line 2 in sunpy/tests/self_test.py

View check run for this annotation

Codecov / codecov/patch

sunpy/tests/self_test.py#L2

Added line #L2 was not covered by tests

def _print_missing_dependencies_report(missing, package="sunpy"):

Check warning on line 4 in sunpy/tests/self_test.py

View check run for this annotation

Codecov / codecov/patch

sunpy/tests/self_test.py#L4

Added line #L4 was not covered by tests
printed = False
Expand Down Expand Up @@ -75,9 +75,10 @@ def self_test(*, package=None, online=False, online_only=False, figure_only=Fals
return pytest.main(test_args)

def _test_base_deps():

Check warning on line 77 in sunpy/tests/self_test.py

View check run for this annotation

Codecov / codecov/patch

sunpy/tests/self_test.py#L77

Added line #L77 was not covered by tests
# Provide a way to test the base dependencies without running the full test suite.
import pytest

Check warning on line 79 in sunpy/tests/self_test.py

View check run for this annotation

Codecov / codecov/patch

sunpy/tests/self_test.py#L79

Added line #L79 was not covered by tests

module_names = ["coordinates", "data", "io", "physics", "sun", "time", "util"]
module_names = ["coordinates", "physics", "sun", "time", "util"]
test_args = ["-c", "/dev/null", "--pyargs"] + [f"sunpy.{name}" for name in module_names]
return pytest.main(test_args)

Check warning on line 83 in sunpy/tests/self_test.py

View check run for this annotation

Codecov / codecov/patch

sunpy/tests/self_test.py#L81-L83

Added lines #L81 - L83 were not covered by tests

Expand Down
10 changes: 5 additions & 5 deletions sunpy/time/tests/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_parse_time_int():


def test_parse_time_pandas_timestamp():
import pandas
pandas = pytest.importorskip('pandas')

ts = pandas.Timestamp(LANDING.datetime)

Expand All @@ -82,7 +82,7 @@ def test_parse_time_pandas_timestamp():


def test_parse_time_nanoseconds():
import pandas
pandas = pytest.importorskip('pandas')

# Check that nanosecon precision is retained when parsing pandas timestamps
ts = pandas.Timestamp('2020-07-31 00:00:26.166196864')
Expand All @@ -93,7 +93,7 @@ def test_parse_time_nanoseconds():


def test_parse_time_pandas_series():
import pandas
pandas = pytest.importorskip('pandas')

inputs = [datetime(2012, 1, i) for i in range(1, 13)]
ind = pandas.Series(inputs)
Expand All @@ -106,7 +106,7 @@ def test_parse_time_pandas_series():


def test_parse_time_pandas_series_2():
import pandas
pandas = pytest.importorskip('pandas')

inputs = [[datetime(2012, 1, 1, 0, 0), datetime(2012, 1, 2, 0, 0)],
[datetime(2012, 1, 3, 0, 0), datetime(2012, 1, 4, 0, 0)]]
Expand All @@ -121,7 +121,7 @@ def test_parse_time_pandas_series_2():


def test_parse_time_pandas_index():
import pandas
pandas = pytest.importorskip('pandas')

inputs = [datetime(2012, 1, i) for i in range(1, 13)]
ind = pandas.DatetimeIndex(inputs)
Expand Down
5 changes: 3 additions & 2 deletions sunpy/util/tests/test_sysinfo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from packaging.requirements import Requirement

from sunpy.util.sysinfo import (
Expand Down Expand Up @@ -52,11 +53,11 @@
'visualization',
]

@pytest.mark.xfail(reason="This test is expected to fail due to missing dependencies")
def test_find_dependencies():
"""
This is ran in several test environments with varying dependencies installed.
So it will be common to find not docs installed, so there will be "missing" dependencies.
But this is not a problem.
So there will be "missing" dependencies, but this is not a problem.
"""
_, installed = find_dependencies(package="sunpy", extras=["required", *EXTRA_ALL_GROUPS])
for package in EXTRA_DEPS:
Expand Down
9 changes: 6 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,27 @@ commands =
pre-commit run --color always --all-files --show-diff-on-failure

[testenv:base_deps]
description = Check the test suite does not fail if all optional dependencies are missing
description = Check the test suite does not fail if only the base and test dependencies are installed
extras =
allowlist_externals=
pytest
deps =
astropy
numpy
packaging
pytest
pytest-astropy
pytest-mock
pytest-xdist
commands =
python -c "import sunpy; sunpy.self_test()"
# Test that we can import subpackages which don't have specific extras
# and that the tests don't fail if optional dependencies are missing
python -c "import sunpy.coordinates"
python -c "import sunpy.data"
python -c "import sunpy.io"
python -c "import sunpy.physics" # TODO: This doesn't import differential_rotation
python -c "import sunpy.physics"
python -c "import sunpy.sun"
python -c "import sunpy.time"
python -c "import sunpy.util"
python -m pip install pytest # Needed for the below command
python -c "from sunpy.tests.self_test import _test_base_deps; _test_base_deps()"

0 comments on commit a826b7c

Please sign in to comment.