Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate slow tests from quick ones #758

Merged
merged 7 commits into from Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 46 additions & 13 deletions .github/workflows/ci_test.yml
Expand Up @@ -25,6 +25,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one fixes a problem we had with PRs from forks, while maintaining consistency in catching the correct commit message. There was some issue with the commit message, that sometimes was the correct one and sometimes the merge message (when github makes the merge with the current main before testing). Now it looks robust enough (I'm doing this PR from a fork to prove it)


# Found this solution at
# https://monadical.com/posts/filters-github-actions.html#Case-2-Pull-request
Expand All @@ -45,7 +48,7 @@ jobs:
ci-tests:
needs: check_commit
if: ${{ needs.check_commit.outputs.match != 'true' }}
name: ${{ matrix.os }}, ${{ matrix.tox_env }}
# name: ${{ matrix.os }}, ${{ matrix.tox_env }}
matteobachetti marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
Expand All @@ -56,47 +59,72 @@ jobs:
# we select only a few, in order to conserve resources. If you add
# an additional environment, please include a comment to indicate
# why it is useful.
- os: ubuntu-latest
- name: Black test
os: ubuntu-latest
python: '3.10'
tox_env: 'black'
experimental: false

# Basic tests on the oldest & newest supported versions of Python,
# recording coverage data for the latter.
- os: ubuntu-latest
- name: Py3.8 with old Astropy version
os: ubuntu-latest
python: '3.8'
tox_env: 'py38-test-astropy4-cov'
experimental: false

- os: ubuntu-latest
- name: Linux, Py3.10 with coverage
os: ubuntu-latest
python: '3.10'
tox_env: 'py310-test-cov'
experimental: false

# Basic tests on alternative operating systems.
- os: windows-latest
- name: Windows, Py3.11 with coverage
os: windows-latest
python: '3.11'
tox_env: 'py311-test-cov'
experimental: false

- os: macos-latest
- name: Mac OS, Py3.11
os: macos-latest
python: '3.11'
tox_env: 'py311-test'
experimental: false

# Test with all optional dependencies installed.
- os: ubuntu-latest
- name: Linux, Py3.11 all dependencies and coverage
os: ubuntu-latest
python: '3.11'
tox_env: 'py311-test-alldeps-cov'
use_remote_data: true
experimental: false

# Development version of dependencies
- os: ubuntu-latest
- name: Linux, Py3.11 with dev versions of dependencies
os: ubuntu-latest
python: '3.11'
tox_env: 'py311-test-devdeps'
experimental: false

# Test with all optional dependencies installed.
- name: Slow tests on Linux, Py3.11, all deps and coverage
os: ubuntu-latest
python: '3.11'
tox_env: 'py311-test-alldeps-cov'
use_remote_data: true
experimental: false
slow: true

# Test with all optional dependencies installed.
- name: Slow tests on Linux, Py3.11, basic deps and coverage
os: ubuntu-latest
python: '3.11'
tox_env: 'py311-test-cov'
use_remote_data: true
experimental: false
slow: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does this take the previous matrix of operating systems and environments, and basically just writes them out individually? Does this mean we're no longer testing python 3.9, for example, and we're only testing Windows and MacOS on Python 3.11?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our matrix was never an actual matrix, but always a list of single tests, as far as I remember. At this moment, indeed, we are testing with py38, py310 and py311. I couldn't manage to make py312-dev work, so left it out. Would you prefer to also have py39?


steps:
- name: Check out repository
uses: actions/checkout@v3
Expand All @@ -121,14 +149,19 @@ jobs:
python -c "import pip; print(f'pip {pip.__version__}')"
python -c "import setuptools; print(f'setuptools {setuptools.__version__}')"
python -c "import tox; print(f'tox {tox.__version__}')"
- name: Run tests
if: "! matrix.use_remote_data"
run: tox -e ${{ matrix.tox_env }}
- name: Run tests with remote data
if: "matrix.use_remote_data"
- name: Run quick tests
if: "(! matrix.use_remote_data) && (! matrix.slow)"
run: tox -e ${{ matrix.tox_env }} --
- name: Run quick tests with remote data
if: "matrix.use_remote_data && (! matrix.slow)"
run: |
pip install pytest-remotedata
tox -e ${{ matrix.tox_env }} -- --remote-data=any
- name: Run slow tests with remote data
if: "matrix.use_remote_data && matrix.slow"
run: |
pip install pytest-remotedata
tox -e ${{ matrix.tox_env }} -- --remote-data=any -m slow --run-slow
- name: Upload coverage to codecov
if: "endsWith(matrix.tox_env, '-cov')"
uses: codecov/codecov-action@v3
Expand Down
Empty file added docs/changes/758.trivial.rst
Empty file.
2 changes: 1 addition & 1 deletion stingray/deadtime/tests/test_fad.py
Expand Up @@ -19,7 +19,7 @@
HAS_HDF5 = True
except ImportError:
HAS_HDF5 = False

pytestmark = pytest.mark.slow
# np.random.seed(2134791)


Expand Down
4 changes: 4 additions & 0 deletions stingray/deadtime/tests/test_models.py
@@ -1,4 +1,5 @@
import os
import pytest
import numpy as np
from scipy.interpolate import interp1d

Expand All @@ -9,6 +10,9 @@
from stingray.filters import filter_for_deadtime


pytestmark = pytest.mark.slow


def test_heaviside():
assert heaviside(2) == 1
assert heaviside(0) == 1
Expand Down
4 changes: 3 additions & 1 deletion stingray/modeling/tests/test_parameterestimation.py
Expand Up @@ -4,7 +4,7 @@
import warnings
import logging

from astropy.tests.helper import pytest
import pytest
from astropy.modeling import models

try:
Expand Down Expand Up @@ -32,6 +32,8 @@

import matplotlib.pyplot as plt

pytestmark = pytest.mark.slow


class LogLikelihoodDummy(LogLikelihood):
def __init__(self, x, y, model):
Expand Down
2 changes: 1 addition & 1 deletion stingray/modeling/tests/test_posterior.py
Expand Up @@ -2,7 +2,7 @@
import scipy.stats
import copy

from astropy.tests.helper import pytest
import pytest
from astropy.modeling import models
from scipy.special import gammaln as scipy_gammaln

Expand Down
1 change: 1 addition & 0 deletions stingray/pulse/overlapandsave/test_ols.py
Expand Up @@ -85,6 +85,7 @@ def testReflect():
assert np.allclose(yRef, ypadRef[py : py + nx, px : px + nx])


@pytest.mark.slow
def testOls():
def testouter(nx, nh):
x = np.random.randint(-30, 30, size=(nx, nx)) + 1.0
Expand Down
2 changes: 2 additions & 0 deletions stingray/pulse/tests/test_accelsearch.py
Expand Up @@ -3,6 +3,8 @@
from stingray.pulse.accelsearch import accelsearch
from stingray.utils import HAS_NUMBA

pytestmark = pytest.mark.slow


np.random.seed(235425899)

Expand Down
2 changes: 2 additions & 0 deletions stingray/pulse/tests/test_pulse.py
Expand Up @@ -29,6 +29,7 @@ def setup_class(cls):
cls.curdir = os.path.abspath(os.path.dirname(__file__))
cls.datadir = os.path.join(cls.curdir, "data")

@pytest.mark.slow
@pytest.mark.remote_data
@pytest.mark.skipif("not HAS_PINT")
def test_pint_installed_correctly(self):
Expand All @@ -51,6 +52,7 @@ def test_pint_installed_correctly(self):
# Due to the gps2utc clock correction. We are at 3e-8 seconds level.
assert np.all(np.abs(pint_resids_us.value) < 3e-6)

@pytest.mark.slow
@pytest.mark.remote_data
@pytest.mark.skipif("not HAS_PINT")
def test_orbit_from_parfile(self):
Expand Down
2 changes: 2 additions & 0 deletions stingray/pulse/tests/test_search.py
Expand Up @@ -11,6 +11,8 @@
from stingray import Lightcurve
from stingray.events import EventList

pytestmark = pytest.mark.slow

np.random.seed(20150907)


Expand Down
2 changes: 1 addition & 1 deletion stingray/simulator/tests/test_simulator.py
Expand Up @@ -3,7 +3,7 @@
import warnings

from scipy.interpolate import interp1d
from astropy.tests.helper import pytest
import pytest
import astropy.modeling.models
from stingray import Lightcurve, Crossspectrum, sampledata, Powerspectrum
from stingray.simulator import Simulator
Expand Down
2 changes: 2 additions & 0 deletions stingray/tests/test_bexvar.py
Expand Up @@ -8,6 +8,8 @@
from astropy.io import fits
import signal

pytestmark = pytest.mark.slow


class TimeoutException(Exception):
pass
Expand Down
2 changes: 1 addition & 1 deletion stingray/tests/test_bispectrum.py
@@ -1,6 +1,6 @@
import numpy as np

from astropy.tests.helper import pytest
import pytest
import warnings
import os

Expand Down
5 changes: 5 additions & 0 deletions stingray/tests/test_crossspectrum.py
Expand Up @@ -324,6 +324,7 @@ def iter_lc_counts_only(iter_lc):
power2 = self.acs.power.real
assert np.allclose(power1, power2, rtol=0.01)

@pytest.mark.slow
def test_from_time_array_works_with_memmap(self):
with fits.open(os.path.join(datadir, "monol_testA.evt"), memmap=True) as hdul:
times1 = hdul[1].data["TIME"]
Expand Down Expand Up @@ -853,6 +854,7 @@ def test_rebin_error(self):
with pytest.raises(ValueError):
cs.rebin()

@pytest.mark.slow
def test_classical_significances_runs(self):
with pytest.warns(UserWarning) as record:
cs = Crossspectrum(self.lc1, self.lc2, norm="leahy")
Expand All @@ -864,6 +866,7 @@ def test_classical_significances_fails_in_rms(self):
with pytest.raises(ValueError):
cs.classical_significances()

@pytest.mark.slow
def test_classical_significances_threshold(self):
with pytest.warns(UserWarning) as record:
cs = Crossspectrum(self.lc1, self.lc2, norm="leahy")
Expand All @@ -880,6 +883,7 @@ def test_classical_significances_threshold(self):
assert pval[0, 0] < threshold
assert pval[1, 0] == index

@pytest.mark.slow
def test_classical_significances_trial_correction(self):
with pytest.warns(UserWarning) as record:
cs = Crossspectrum(self.lc1, self.lc2, norm="leahy")
Expand All @@ -899,6 +903,7 @@ def test_classical_significances_with_logbinned_psd(self):

assert len(pval[0]) == len(cs_log.power)

@pytest.mark.slow
def test_pvals_is_numpy_array(self):
cs = Crossspectrum(self.lc1, self.lc2, norm="leahy")
# change the powers so that just one exceeds the threshold
Expand Down
2 changes: 1 addition & 1 deletion stingray/tests/test_io.py
Expand Up @@ -2,7 +2,7 @@
import os
import matplotlib.pyplot as plt

from astropy.tests.helper import pytest
import pytest
from astropy.utils.exceptions import AstropyUserWarning

from ..io import split_numbers
Expand Down
3 changes: 2 additions & 1 deletion stingray/tests/test_lightcurve.py
@@ -1,7 +1,7 @@
import os
import copy
import numpy as np
from astropy.tests.helper import pytest
import pytest
import warnings
import os
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -1499,6 +1499,7 @@ def test_eq_different_counts(self):
assert not lc1 == lc2


@pytest.mark.slow
class TestBexvar(object):
@classmethod
def setup_class(cls):
Expand Down
3 changes: 2 additions & 1 deletion stingray/tests/test_multitaper.py
Expand Up @@ -2,14 +2,15 @@
import copy
import warnings

from astropy.tests.helper import pytest
import pytest
from numpy.random import poisson, standard_cauchy
from scipy.signal import TransferFunction

from stingray import Lightcurve
from stingray.events import EventList
from stingray import Multitaper, Powerspectrum

pytestmark = pytest.mark.slow
np.random.seed(1)


Expand Down
3 changes: 2 additions & 1 deletion stingray/tests/test_powerspectrum.py
Expand Up @@ -3,7 +3,7 @@
import copy
import warnings

from astropy.tests.helper import pytest
import pytest
from astropy.io import fits
from stingray import Lightcurve
from stingray.events import EventList
Expand Down Expand Up @@ -202,6 +202,7 @@ def iter_lc_counts_only(iter_lc):
power2 = self.leahy_pds.power.real
assert np.allclose(power1, power2, rtol=0.01)

@pytest.mark.slow
def test_from_time_array_works_with_memmap(self):
with fits.open(os.path.join(datadir, "monol_testA.evt"), memmap=True) as hdul:
times = hdul[1].data["TIME"]
Expand Down
3 changes: 3 additions & 0 deletions stingray/tests/test_spectroscopy.py
Expand Up @@ -90,6 +90,8 @@ def fake_qpo(
return phase, qpo_lc


@pytest.mark.slow
@pytest.mark.xfail
class TestCCF(object):
@classmethod
def setup_class(cls):
Expand Down Expand Up @@ -195,6 +197,7 @@ def test_ccf(self):
"DT": self.dt,
"N_BINS": self.n_bins,
}

error_ccf, avg_seg_ccf = spec.ccf_error(
self.ref_counts,
ci_counts_0,
Expand Down
2 changes: 1 addition & 1 deletion stingray/tests/test_utils.py
@@ -1,4 +1,4 @@
from astropy.tests.helper import pytest
import pytest
import numpy as np
import stingray.utils as utils
from scipy.stats import sem
Expand Down
4 changes: 3 additions & 1 deletion stingray/tests/test_varenergyspectrum.py
Expand Up @@ -9,7 +9,7 @@
from stingray.varenergyspectrum import ExcessVarianceSpectrum
from stingray.lightcurve import Lightcurve

from astropy.tests.helper import pytest
import pytest
from astropy.table import Table

_HAS_XARRAY = _HAS_PANDAS = _HAS_H5PY = True
Expand Down Expand Up @@ -166,6 +166,7 @@ def test_counts(self, use_pi):
assert np.allclose(ctsspec.spectrum, 2)


@pytest.mark.slow
class TestRmsAndCovSpectrum(object):
@classmethod
def setup_class(cls):
Expand Down Expand Up @@ -352,6 +353,7 @@ def test_rms_invalid_evlist_warns(self):
assert np.all(np.isnan(rms.spectrum_error))


@pytest.mark.slow
class TestLagEnergySpectrum(object):
@classmethod
def setup_class(cls):
Expand Down