diff --git a/.circleci/config.yml b/.circleci/config.yml index 833b1daf87b..6e069ab07d0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -84,7 +84,7 @@ jobs: - run: name: Install dependencies one # Cat here to suppress the progress bar - command: pip3 install cython numpy scipy astropy matplotlib | cat + command: pip3 install cython numpy scipy astropy matplotlib asdf | cat - run: name: Install dependencies two # Cat here to suppress the progress bar @@ -124,7 +124,7 @@ jobs: - run: *merge-check - run: *apt-install - run: *tox-install - - run: tox -e py37-build_docs + - run: tox -e build_docs - store_artifacts: path: docs/_build/html diff --git a/.gitignore b/.gitignore index aa111ebd6e1..7f5e125d355 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ coverage.xml *.cover .hypothesis/ .pytest_cache/ +junit/ # Translations *.mo diff --git a/MANIFEST.in b/MANIFEST.in index 80f3aa215cc..59ae0a17b4a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -6,6 +6,7 @@ include pyproject.toml include README.rst include RELEASE.rst include setup.py +include setup.cfg recursive-include astropy_helpers * exclude astropy_helpers/.* diff --git a/azure-pipelines.yml b/azure-pipelines.yml index da30b1b576a..ec43d92ba6d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -27,7 +27,7 @@ jobs: parameters: name: Linux_37_online os: linux - tox: py37-online -- -n=6 + tox: py37-online -- -n=4 - template: azure-templates.yml parameters: diff --git a/conftest.py b/conftest.py deleted file mode 100644 index 2a8de86d426..00000000000 --- a/conftest.py +++ /dev/null @@ -1,8 +0,0 @@ -import importlib - -from pkg_resources import parse_version - -if importlib.util.find_spec('asdf') is not None: - from asdf import __version__ as asdf_version - if parse_version(asdf_version) >= parse_version('2.3.0'): - pytest_plugins = ['asdf.tests.schema_tester'] diff --git a/docs/conf.py b/docs/conf.py index 0b93df6a4a9..ec13fc75588 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -103,9 +103,9 @@ # |version| and |release|, also used in various other places throughout the # built documents. # The short X.Y version. -version = '.'.join(versionmod.version.split('.')[:2]) +release = '.'.join(versionmod.version.split('.')[:3]) # The full version, including alpha/beta/rc tags. -release = versionmod.version +version = versionmod.version.split('+')[0] # -- Shut up numpy warnings from WCSAxes -------------------------------------- diff --git a/setup.cfg b/setup.cfg index bcbd612aea3..34443bc1506 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,7 +50,7 @@ docs = towncrier [options.package_data] -sunpy.data = sunpyrc, test/** +sunpy.data = sunpyrc, test/*, test/*/* sunpy.database = tests/test_table.txt sunpy.io = special/asdf/schemas/sunpy.org/sunpy/*/*.yaml, special/asdf/schemas/sunpy.org/sunpy/*/*/*.yaml sunpy.tests = figure_hashes_py36.json @@ -58,6 +58,8 @@ sunpy.tests = figure_hashes_py36.json [options.entry_points] asdf_extensions = sunpy = sunpy.io.special.asdf.extension:SunpyExtension +pytest11 = + asdf = asdf.tests.schema_tester [ah_bootstrap] auto_use = True diff --git a/sunpy/conftest.py b/sunpy/conftest.py index acbfb78edbd..2e3c9dbec45 100644 --- a/sunpy/conftest.py +++ b/sunpy/conftest.py @@ -4,7 +4,11 @@ import importlib import pytest -from pkg_resources import parse_version + +import sunpy.tests.helpers +from sunpy.tests.hash import HASH_LIBRARY_NAME +from sunpy.tests.helpers import new_hash_library, generate_figure_webpage +from sunpy.util.exceptions import SunpyDeprecationWarning # Force MPL to use non-gui backends for testing. try: @@ -14,12 +18,6 @@ else: matplotlib.use('Agg') -# isort:imports-firstparty -import sunpy.tests.helpers -from sunpy.tests.hash import HASH_LIBRARY_NAME -from sunpy.tests.helpers import new_hash_library, generate_figure_webpage -from sunpy.util.exceptions import SunpyDeprecationWarning - # Don't actually import pytest_remotedata because that can do things to the # entrypoints code in pytest. remotedata_spec = importlib.util.find_spec("pytest_remotedata") diff --git a/sunpy/data/test/__init__.py b/sunpy/data/test/__init__.py index 4a0e3e85455..7cbedff9165 100644 --- a/sunpy/data/test/__init__.py +++ b/sunpy/data/test/__init__.py @@ -14,7 +14,6 @@ file_list = glob.glob(os.path.join(rootdir, '*.[!p]*')) - def get_test_filepath(filename, **kwargs): """ Return the full path to a test file in the ``data/test`` directory. diff --git a/sunpy/instr/fermi.py b/sunpy/instr/fermi.py index 83463065c9e..26c923e77d9 100644 --- a/sunpy/instr/fermi.py +++ b/sunpy/instr/fermi.py @@ -1,7 +1,6 @@ import os import copy import urllib -import datetime import tempfile from collections import OrderedDict diff --git a/sunpy/instr/goes.py b/sunpy/instr/goes.py index 42c910777e3..c9dc979ab42 100644 --- a/sunpy/instr/goes.py +++ b/sunpy/instr/goes.py @@ -230,25 +230,31 @@ def calculate_temperature_em(goests, abundances="coronal", >>> from sunpy.instr.goes import calculate_temperature_em >>> from sunpy.data.sample import GOES_XRS_TIMESERIES # doctest: +REMOTE_DATA >>> goests = ts.TimeSeries(GOES_XRS_TIMESERIES) # doctest: +REMOTE_DATA - >>> goests.data # doctest: +REMOTE_DATA - xrsa xrsb + >>> goests.data[0:10] # doctest: +REMOTE_DATA + xrsa xrsb 2011-06-06 23:59:59.961999893 1.000000e-09 1.887100e-07 2011-06-07 00:00:02.008999944 1.000000e-09 1.834600e-07 2011-06-07 00:00:04.058999896 1.000000e-09 1.860900e-07 2011-06-07 00:00:06.104999900 1.000000e-09 1.808400e-07 2011-06-07 00:00:08.151999950 1.000000e-09 1.860900e-07 - ... - + 2011-06-07 00:00:10.201999903 1.000000e-09 1.808400e-07 + 2011-06-07 00:00:12.248999953 1.000000e-09 1.860900e-07 + 2011-06-07 00:00:14.298999906 1.000000e-09 1.834600e-07 + 2011-06-07 00:00:16.344999909 1.000000e-09 1.808400e-07 + 2011-06-07 00:00:18.391999960 1.000000e-09 1.834600e-07 >>> goests_new = calculate_temperature_em(goests) # doctest: +REMOTE_DATA - >>> goests_new.data # doctest: +REMOTE_DATA - xrsa xrsb temperature em + >>> goests_new.data[0:10] # doctest: +REMOTE_DATA + xrsa xrsb temperature em 2011-06-06 23:59:59.961999893 1.000000e-09 1.887100e-07 3.503510 2.190626e+48 2011-06-07 00:00:02.008999944 1.000000e-09 1.834600e-07 3.534262 2.055847e+48 2011-06-07 00:00:04.058999896 1.000000e-09 1.860900e-07 3.518700 2.122771e+48 2011-06-07 00:00:06.104999900 1.000000e-09 1.808400e-07 3.550100 1.990333e+48 2011-06-07 00:00:08.151999950 1.000000e-09 1.860900e-07 3.518700 2.122771e+48 - ... - + 2011-06-07 00:00:10.201999903 1.000000e-09 1.808400e-07 3.550100 1.990333e+48 + 2011-06-07 00:00:12.248999953 1.000000e-09 1.860900e-07 3.518700 2.122771e+48 + 2011-06-07 00:00:14.298999906 1.000000e-09 1.834600e-07 3.534262 2.055847e+48 + 2011-06-07 00:00:16.344999909 1.000000e-09 1.808400e-07 3.550100 1.990333e+48 + 2011-06-07 00:00:18.391999960 1.000000e-09 1.834600e-07 3.534262 2.055847e+48 """ # Check that input argument is of correct type if not isinstance(goests, timeseries.XRSTimeSeries): @@ -805,27 +811,31 @@ def calculate_radiative_loss_rate(goests, force_download=False, >>> from sunpy.instr.goes import calculate_radiative_loss_rate >>> from sunpy.data.sample import GOES_XRS_TIMESERIES # doctest: +REMOTE_DATA >>> goests = ts.TimeSeries(GOES_XRS_TIMESERIES) # doctest: +REMOTE_DATA - >>> goests.data # doctest: +REMOTE_DATA - xrsa xrsb + >>> goests.data[0:10] # doctest: +REMOTE_DATA + xrsa xrsb 2011-06-06 23:59:59.961999893 1.000000e-09 1.887100e-07 2011-06-07 00:00:02.008999944 1.000000e-09 1.834600e-07 2011-06-07 00:00:04.058999896 1.000000e-09 1.860900e-07 2011-06-07 00:00:06.104999900 1.000000e-09 1.808400e-07 2011-06-07 00:00:08.151999950 1.000000e-09 1.860900e-07 2011-06-07 00:00:10.201999903 1.000000e-09 1.808400e-07 - ... - + 2011-06-07 00:00:12.248999953 1.000000e-09 1.860900e-07 + 2011-06-07 00:00:14.298999906 1.000000e-09 1.834600e-07 + 2011-06-07 00:00:16.344999909 1.000000e-09 1.808400e-07 + 2011-06-07 00:00:18.391999960 1.000000e-09 1.834600e-07 >>> goests_new = calculate_radiative_loss_rate(goests) # doctest: +REMOTE_DATA - >>> goests_new.data # doctest: +REMOTE_DATA - xrsa xrsb temperature em rad_loss_rate + >>> goests_new.data[0:10] # doctest: +REMOTE_DATA + xrsa xrsb temperature em rad_loss_rate 2011-06-06 23:59:59.961999893 1.000000e-09 1.887100e-07 3.503510 2.190626e+48 1.781001e+19 2011-06-07 00:00:02.008999944 1.000000e-09 1.834600e-07 3.534262 2.055847e+48 1.660031e+19 2011-06-07 00:00:04.058999896 1.000000e-09 1.860900e-07 3.518700 2.122771e+48 1.719931e+19 2011-06-07 00:00:06.104999900 1.000000e-09 1.808400e-07 3.550100 1.990333e+48 1.601718e+19 2011-06-07 00:00:08.151999950 1.000000e-09 1.860900e-07 3.518700 2.122771e+48 1.719931e+19 2011-06-07 00:00:10.201999903 1.000000e-09 1.808400e-07 3.550100 1.990333e+48 1.601718e+19 - ... - + 2011-06-07 00:00:12.248999953 1.000000e-09 1.860900e-07 3.518700 2.122771e+48 1.719931e+19 + 2011-06-07 00:00:14.298999906 1.000000e-09 1.834600e-07 3.534262 2.055847e+48 1.660031e+19 + 2011-06-07 00:00:16.344999909 1.000000e-09 1.808400e-07 3.550100 1.990333e+48 1.601718e+19 + 2011-06-07 00:00:18.391999960 1.000000e-09 1.834600e-07 3.534262 2.055847e+48 1.660031e+19 """ if not download_dir: download_dir = get_and_create_download_dir() @@ -1054,26 +1064,31 @@ def calculate_xray_luminosity(goests): >>> from sunpy.instr.goes import calculate_xray_luminosity >>> from sunpy.data.sample import GOES_XRS_TIMESERIES # doctest: +REMOTE_DATA >>> goests = ts.TimeSeries(GOES_XRS_TIMESERIES) # doctest: +REMOTE_DATA - >>> goests.data # doctest: +REMOTE_DATA - xrsa xrsb + >>> goests.data[0:10] # doctest: +REMOTE_DATA + xrsa xrsb 2011-06-06 23:59:59.961999893 1.000000e-09 1.887100e-07 2011-06-07 00:00:02.008999944 1.000000e-09 1.834600e-07 2011-06-07 00:00:04.058999896 1.000000e-09 1.860900e-07 2011-06-07 00:00:06.104999900 1.000000e-09 1.808400e-07 2011-06-07 00:00:08.151999950 1.000000e-09 1.860900e-07 - ... - - + 2011-06-07 00:00:10.201999903 1.000000e-09 1.808400e-07 + 2011-06-07 00:00:12.248999953 1.000000e-09 1.860900e-07 + 2011-06-07 00:00:14.298999906 1.000000e-09 1.834600e-07 + 2011-06-07 00:00:16.344999909 1.000000e-09 1.808400e-07 + 2011-06-07 00:00:18.391999960 1.000000e-09 1.834600e-07 >>> goests_new = calculate_xray_luminosity(goests) # doctest: +REMOTE_DATA - >>> goests_new.data # doctest: +REMOTE_DATA - xrsa xrsb luminosity_xrsa luminosity_xrsb + >>> goests_new.data[0:10] # doctest: +REMOTE_DATA + xrsa xrsb luminosity_xrsa luminosity_xrsb 2011-06-06 23:59:59.961999893 1.000000e-09 1.887100e-07 2.896209e+14 5.465435e+16 2011-06-07 00:00:02.008999944 1.000000e-09 1.834600e-07 2.896209e+14 5.313384e+16 2011-06-07 00:00:04.058999896 1.000000e-09 1.860900e-07 2.896209e+14 5.389555e+16 2011-06-07 00:00:06.104999900 1.000000e-09 1.808400e-07 2.896209e+14 5.237503e+16 2011-06-07 00:00:08.151999950 1.000000e-09 1.860900e-07 2.896209e+14 5.389555e+16 - ... - + 2011-06-07 00:00:10.201999903 1.000000e-09 1.808400e-07 2.896209e+14 5.237503e+16 + 2011-06-07 00:00:12.248999953 1.000000e-09 1.860900e-07 2.896209e+14 5.389555e+16 + 2011-06-07 00:00:14.298999906 1.000000e-09 1.834600e-07 2.896209e+14 5.313384e+16 + 2011-06-07 00:00:16.344999909 1.000000e-09 1.808400e-07 2.896209e+14 5.237503e+16 + 2011-06-07 00:00:18.391999960 1.000000e-09 1.834600e-07 2.896209e+14 5.313384e+16 """ # Check that input argument is of correct type if not isinstance(goests, timeseries.XRSTimeSeries): diff --git a/sunpy/net/dataretriever/tests/test_noaa.py b/sunpy/net/dataretriever/tests/test_noaa.py index 76d7c7da7c4..97328b6076e 100644 --- a/sunpy/net/dataretriever/tests/test_noaa.py +++ b/sunpy/net/dataretriever/tests/test_noaa.py @@ -21,13 +21,13 @@ def mock_query_object(start_date, end_date): """ # Create a mock QueryResponse object map_ = { - 'TimeRange' : TimeRange(parse_time(start_date), parse_time(end_date)), + 'TimeRange': TimeRange(parse_time(start_date), parse_time(end_date)), 'Time_start': parse_time(start_date), 'Time_end': parse_time(end_date), 'source': 'sdic', 'instrument': 'noaa-indices', - 'physobs':'sunspot number', - 'provider':'swpc' + 'physobs': 'sunspot number', + 'provider': 'swpc' } resp = QueryResponse.create(map_, LCClient._get_default_uri()) @@ -37,7 +37,7 @@ def mock_query_object(start_date, end_date): @pytest.mark.remote_data -def test_fetch_working(): +def test_fetch_working(tmpdir): """ Tests if the online server for noaa is working. Uses the url : ftp://ftp.swpc.noaa.gov/pub/weekly/RecentIndices.txt @@ -63,7 +63,8 @@ def test_fetch_working(): # Assert if the timerange is same assert qr1.time_range() == TimeRange('2012/10/4', '2012/10/6') - res = LCClient.fetch(qr1) + target_dir = tmpdir.mkdir("down") + res = LCClient.fetch(qr1, path=target_dir.strpath) download_list = res.wait(progress=False) assert len(download_list) == len(qr1) assert download_list[0].split('/')[-1] == 'RecentIndices.txt' diff --git a/sunpy/net/tests/test_fido.py b/sunpy/net/tests/test_fido.py index a5795f0e01d..85de6d27679 100644 --- a/sunpy/net/tests/test_fido.py +++ b/sunpy/net/tests/test_fido.py @@ -1,23 +1,21 @@ import os import copy -import tempfile import pathlib import pytest import hypothesis.strategies as st -from hypothesis import given, assume, example, settings +from hypothesis import given, assume, settings import astropy.units as u from drms import DrmsQueryError from sunpy.net import attr -from sunpy.net.vso import attrs as va from sunpy.net import Fido, attrs as a from sunpy.net.base_client import BaseClient from sunpy.net.vso import QueryResponse as vsoQueryResponse from sunpy.net.fido_factory import DownloadResponse, UnifiedResponse from sunpy.net.dataretriever.client import QueryResponse -from sunpy.util.datatype_factory_base import NoMatchError, MultipleMatchError +from sunpy.util.datatype_factory_base import MultipleMatchError from sunpy.time import TimeRange, parse_time from sunpy import config @@ -95,29 +93,30 @@ def check_response(query, unifiedresp): @pytest.mark.remote_data -def test_save_path(): +def test_save_path(tmpdir): qr = Fido.search(a.Instrument('EVE'), a.Time("2016/10/01", "2016/10/02"), a.Level(0)) # Test when path is str - with tempfile.TemporaryDirectory() as target_dir: - files = Fido.fetch(qr, path=os.path.join(target_dir, "{instrument}", "{level}")) - for f in files: - assert target_dir in f - assert "eve{}0".format(os.path.sep) in f + target_dir = tmpdir.mkdir("down") + path = os.path.join(target_dir, "{instrument}", "{level}") + files = Fido.fetch(qr, path=path) + for f in files: + assert target_dir.strpath in f + assert "eve{}0".format(os.path.sep) in f @pytest.mark.remote_data -def test_save_path_pathlib(): - pathlib = pytest.importorskip('pathlib') +@pytest.mark.flaky(reruns=5) +def test_save_path_pathlib(tmpdir): qr = Fido.search(a.Instrument('EVE'), a.Time("2016/10/01", "2016/10/02"), a.Level(0)) # Test when path is pathlib.Path - with tempfile.TemporaryDirectory() as target_dir: - path = pathlib.Path(target_dir, "{instrument}", "{level}") - files = Fido.fetch(qr, path=path) - for f in files: - assert target_dir in f - assert "eve{}0".format(os.path.sep) in f + target_dir = tmpdir.mkdir("down") + path = pathlib.Path(target_dir, "{instrument}", "{level}") + files = Fido.fetch(qr, path=path) + for f in files: + assert target_dir.strpath in f + assert "eve{}0".format(os.path.sep) in f """ diff --git a/tox.ini b/tox.ini index 9d2cabf78ec..4625d36e1b2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,53 +1,36 @@ [tox] -envlist = py{36,37}-{offline,online,astropydev,numpydev,build_docs},figure,conda +envlist = py{36,37}-{offline,online,astropydev,numpydev},build_docs,figure,conda isolated_build=true [testenv] +changedir = tmp setenv = MPLBACKEND = agg COLUMNS = 180 +extras = all,tests deps = astropydev,numpydev: cython numpydev: git+git://github.com/numpy/numpy - offline,online,astropydev: numpy astropydev: git+git://github.com/astropy/astropy - offline,online,build_docs: astropy - matplotlib - scipy - asdf - beautifulsoup4 - dask - drms - glymur - jinja2 - lxml - pandas - scikit-image - sqlalchemy - zeep - hypothesis - pytest-astropy pytest-cov - pytest-mock pytest-xdist pytest-sugar online: pytest-rerunfailures online: pytest-timeout - build_docs: ruamel.yaml - build_docs: sphinx - build_docs: sphinx-astropy - build_docs: sunpy-sphinx-theme - build_docs: git+git://github.com/hawkowl/towncrier commands = - offline,astropydev,numpydev: pytest -m "not figure" --cov=./sunpy {posargs} - online: pytest --timeout=500 -m "not figure" --remote-data=any --cov=./sunpy {posargs} - build_docs: sphinx-build docs docs/_build/html -W -b html + offline,astropydev,numpydev: pytest --verbose --pyargs sunpy -m "not figure" --cov=sunpy --rootdir={toxinidir} {posargs} {toxinidir}/docs + online: pytest --verbose --pyargs sunpy --timeout=300 -m "not figure" --remote-data=any --cov=sunpy --rootdir={toxinidir} {posargs} {toxinidir}/docs + +[testenv:build_docs] +basepython = python3.7 +changedir = {toxinidir} +extras = all,docs +commands = sphinx-build docs docs/_build/html -W -b html # This env requires tox-conda. [testenv:figure] basepython = python3.6 -setenv = - {[testenv]setenv} +extras = all,tests conda_deps = python = 3.6.5 astropy = 3.1.0 @@ -58,13 +41,12 @@ conda_deps = pandas = 0.23.4 pytest-cov conda_channels = conda-forge -commands = pytest -m "figure" --cov=./sunpy +commands = pytest --verbose --pyargs sunpy -m "figure" --rootdir={toxinidir} --cov=sunpy {posargs} # This env requires tox-conda. [testenv:conda] basepython = python3.6 -setenv = - {[testenv]setenv} +extras = deps = conda_deps = jsonschema=2.6 @@ -91,4 +73,4 @@ conda_deps = zeep conda_channels = conda-forge commands = - pytest -m "not figure" --cov=./sunpy {posargs} + pytest --verbose --pyargs sunpy -m "not figure" --rootdir={toxinidir} --cov=sunpy {posargs}