Skip to content

Commit

Permalink
Merge pull request dendrograms#193 from astrofrog/fix-ci
Browse files Browse the repository at this point in the history
Fix tests/continuous integration
  • Loading branch information
astrofrog authored Aug 8, 2023
2 parents 9818555 + 8dac4ad commit 3181c36
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 53 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
envs: |
- linux: codestyle
pytest: false
- linux: py37-test-oldestdeps
- macos: py38-test
- linux: py38-test-oldestdeps
- macos: py39-test
- windows: py39-test
- linux: py310-test
- linux: py310-test-devdeps
- linux: py311-test-devdeps
coverage: 'codecov'
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
build:
os: ubuntu-20.04
tools:
python: '3.7'
python: '3.8'

python:
install:
Expand Down
2 changes: 1 addition & 1 deletion astrodendro/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def v_rms(self):
0 following the Numpy convention - the third axis in the FITS
convention).
"""
dv = self.velocity_scale or u.pixel
dv = self.velocity_scale if self.velocity_scale is not None else u.pixel
ax = [0, 0, 0]
ax[self.vaxis] = 1
return dv * np.sqrt(self.stat.mom2_along(tuple(ax)))
Expand Down
2 changes: 1 addition & 1 deletion astrodendro/io/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _construct_tree(repr):
idx = int(idx)
structure_indices = indices_by_structure[idx]
f = flux_by_structure[idx]
if type(repr[idx]) == tuple:
if type(repr[idx]) is tuple:
sub_structures_repr = repr[idx][0] # Parsed representation of sub structures
sub_structures = _construct_tree(sub_structures_repr)
for i in sub_structures:
Expand Down
12 changes: 1 addition & 11 deletions astrodendro/tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@
from numpy.testing import assert_allclose
import astropy.units as u
from astropy.wcs import WCS

from astropy.tests.helper import assert_quantity_allclose as assert_allclose_quantity

from ._testdata import data
from ..analysis import (ScalarStatistic, PPVStatistic, ppv_catalog,
Metadata, PPStatistic, pp_catalog)
from .. import Dendrogram, periodic_neighbours
from ..structure import Structure


def assert_allclose_quantity(a, b):
if not isinstance(a, u.Quantity):
raise TypeError("a is not a quantity")
if not isinstance(b, u.Quantity):
raise TypeError("b is not a quantity")
assert_allclose(a.value, b.value)
assert a.unit == b.unit


wcs_2d = WCS(header=dict(cdelt1=1, crval1=0, crpix1=1,
cdelt2=2, crval2=0, crpix2=1))
wcs_3d = WCS(header=dict(cdelt1=1, crval1=0, crpix1=1,
Expand Down
31 changes: 9 additions & 22 deletions astrodendro/tests/test_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
from ..flux import compute_flux


def strip_parentheses(string):
return string.replace('(', '').replace(')', '')


COMBINATIONS = \
[
(np.array([1, 2, 3]) * u.Jy, u.Jy, {}, 6 * u.Jy),
Expand All @@ -31,50 +27,41 @@ def test_compute_flux(input_quantities, output_unit, keywords, output):


def test_monochromatic_wav_missing():
with pytest.raises(ValueError) as exc:
with pytest.raises(ValueError, match='wavelength is needed to convert from erg'):
compute_flux(np.array([1, 2, 3]) * u.erg / u.cm ** 2 / u.s / u.micron, u.Jy)
assert exc.value.args[0] == 'wavelength is needed to convert from erg / (cm2 micron s) to Jy'


def test_monochromatic_wav_invalid_units():
with pytest.raises(ValueError) as exc:
with pytest.raises(ValueError, match='wavelength should be a physical length'):
compute_flux(np.array([1, 2, 3]) * u.erg / u.cm ** 2 / u.s / u.micron, u.Jy, wavelength=3 * u.L)
assert exc.value.args[0] == 'wavelength should be a physical length'


def test_surface_brightness_scale_missing():
with pytest.raises(ValueError) as exc:
with pytest.raises(ValueError, match='spatial_scale is needed to convert from Jy'):
compute_flux(np.array([1, 2, 3]) * u.Jy / u.arcsec ** 2, u.Jy)
assert strip_parentheses(exc.value.args[0]) == 'spatial_scale is needed to convert from Jy / arcsec2 to Jy'


def test_surface_brightness_invalid_units():
with pytest.raises(ValueError) as exc:
with pytest.raises(ValueError, match='spatial_scale should be an angle'):
compute_flux(np.array([1, 2, 3]) * u.Jy / u.arcsec ** 2, u.Jy, spatial_scale=3 * u.m)
assert exc.value.args[0] == 'spatial_scale should be an angle'


def test_per_beam_scale_missing():

with pytest.raises(ValueError) as exc:
with pytest.raises(ValueError, match='spatial_scale is needed to convert from Jy / beam to Jy'):
compute_flux(np.array([1, 2, 3]) * u.Jy / u.beam, u.Jy, beam_major=3 * u.arcsec, beam_minor=2. * u.arcsec)
assert strip_parentheses(exc.value.args[0]) == 'spatial_scale is needed to convert from Jy / beam to Jy'

with pytest.raises(ValueError) as exc:
with pytest.raises(ValueError, match='beam_major is needed to convert from Jy / beam to Jy'):
compute_flux(np.array([1, 2, 3]) * u.Jy / u.beam, u.Jy, spatial_scale=3 * u.arcsec, beam_minor=2. * u.arcsec)
assert strip_parentheses(exc.value.args[0]) == 'beam_major is needed to convert from Jy / beam to Jy'

with pytest.raises(ValueError) as exc:
with pytest.raises(ValueError, match='beam_minor is needed to convert from Jy / beam to Jy'):
compute_flux(np.array([1, 2, 3]) * u.Jy / u.beam, u.Jy, spatial_scale=3 * u.arcsec, beam_major=2. * u.arcsec)
assert strip_parentheses(exc.value.args[0]) == 'beam_minor is needed to convert from Jy / beam to Jy'


def test_per_beam_invalid_units():

with pytest.raises(ValueError) as exc:
with pytest.raises(ValueError, match='beam_major should be an angle'):
compute_flux(np.array([1, 2, 3]) * u.Jy / u.beam, u.Jy, spatial_scale=3 * u.arcsec, beam_major=3 * u.m, beam_minor=2. * u.arcsec)
assert exc.value.args[0] == 'beam_major should be an angle'

with pytest.raises(ValueError) as exc:
with pytest.raises(ValueError, match='beam_minor should be an angle'):
compute_flux(np.array([1, 2, 3]) * u.Jy / u.beam, u.Jy, spatial_scale=3 * u.arcsec, beam_major=3 * u.arcsec, beam_minor=2. * u.m)
assert exc.value.args[0] == 'beam_minor should be an angle'
4 changes: 2 additions & 2 deletions astrodendro/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ def assert_permuted_fancyindex(x, y):
""" Assert that two fancy indices (tuples of integer ndarrays)
are permutations of each other
"""
if not isinstance(x, tuple) or not(isinstance(x[0], np.ndarray)):
if not isinstance(x, tuple) or not (isinstance(x[0], np.ndarray)):
raise TypeError("First argument not a fancy index: %s" % x)

if not isinstance(y, tuple) or not(isinstance(y[0], np.ndarray)):
if not isinstance(y, tuple) or not (isinstance(y[0], np.ndarray)):
raise TypeError("Second argument not a fancy index: %s" % y)

dtype = [('%i' % i, 'i') for i in range(len(x))]
Expand Down
12 changes: 6 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ github_project = dendrograms/astrodendro
[options]
zip_safe = False
packages = find:
python_requires = >=3.7
python_requires = >=3.8
setup_requires = setuptools_scm
install_requires =
numpy>1.16
astropy>4
matplotlib>3
h5py>3
numpy>=1.20
astropy>=5.0
matplotlib>=3.3
h5py>=3

[options.extras_require]
test =
pytest
pytest-cov
docs =
sphinx
sphinx<7
numpydoc
sphinx-astropy
aplpy
Expand Down
11 changes: 5 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{37,38,39,310}-test{,-alldeps,-devdeps}{,-cov}
py{38,39,310,311}-test{,-alldeps,-devdeps}{,-cov}
build_docs
linkcheck
codestyle
Expand All @@ -12,8 +12,7 @@ isolated_build = true
[testenv]
setenv =
MPLBACKEND=agg
devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/scipy-wheels-nightly/simple
passenv = HOME WINDIR LC_ALL LC_CTYPE CC CI TRAVIS
devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/scientific-python-nightly-wheels/
changedir = .tmp/{envname}
description =
run tests
Expand All @@ -26,10 +25,10 @@ deps =
cov: coverage
devdeps: numpy>=0.0.dev0
devdeps: astropy>=0.0.dev0
oldestdeps: astropy==4.0.*
oldestdeps: astropy==5.0.*
oldestdeps: h5py==3.0.*
oldestdeps: matplotlib==3.0.*
oldestdeps: numpy==1.16.*
oldestdeps: matplotlib==3.3.*
oldestdeps: numpy==1.20.*

extras =
test
Expand Down

0 comments on commit 3181c36

Please sign in to comment.