Skip to content

Commit

Permalink
Merge pull request #758 from matteobachetti/slow_tests
Browse files Browse the repository at this point in the history
Separate slow tests from quick ones
  • Loading branch information
matteobachetti authored Sep 25, 2023
2 parents e3acafe + 67087e3 commit 5fac201
Show file tree
Hide file tree
Showing 21 changed files with 85 additions and 24 deletions.
59 changes: 46 additions & 13 deletions .github/workflows/ci_test.yml
Original file line number Diff line number Diff line change
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}}

# 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 }}
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

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit 5fac201

Please sign in to comment.