Skip to content

Commit

Permalink
Merge pull request #799 from desihub/refresh-tests
Browse files Browse the repository at this point in the history
Refresh test infrastructure
  • Loading branch information
weaverba137 committed Nov 21, 2022
2 parents c5e89fa + dd577ce commit 73ee3fd
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 24 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/python-package.yml
Expand Up @@ -17,14 +17,14 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
python-version: [3.8] # fitsio does not like Python < 3.7, astropy does not like Python < 3.8, might be too soon for 3.9.
astropy-version: ['==4.0.1.post1', '==5.0'] # everest & fuji versions
fitsio-version: ['==1.1.2', '==1.1.6'] # everest & fuji versions
python-version: [3.9]
astropy-version: ['==5.0', '<6'] # fuji version
fitsio-version: ['==1.1.6'] # fuji version
numpy-version: ['<1.23'] # to keep asscalar, used by astropy

env:
DESIUTIL_VERSION: 3.2.3
DESIMODEL_DATA: branches/test-0.12
DESIUTIL_VERSION: 3.2.5
DESIMODEL_DATA: branches/test-0.17

steps:
- name: Checkout code
Expand Down Expand Up @@ -56,12 +56,12 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
python-version: [3.8]
fitsio-version: ['==1.1.2'] # everest version
python-version: [3.9]
fitsio-version: ['==1.1.6'] # fuji version
numpy-version: ['<1.23'] # to keep asscalar, used by astropy
env:
DESIUTIL_VERSION: 3.2.3
DESIMODEL_DATA: branches/test-0.12
DESIUTIL_VERSION: 3.2.5
DESIMODEL_DATA: branches/test-0.17

steps:
- name: Checkout code
Expand All @@ -75,7 +75,7 @@ jobs:
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip wheel
python -m pip install pytest pytest-cov coveralls
python -m pip install pytest\<7 pytest-cov\<4 coveralls
python -m pip install git+https://github.com/desihub/desiutil.git@${DESIUTIL_VERSION}#egg=desiutil
python -m pip install -r requirements.txt
python -m pip install -U 'numpy${{ matrix.numpy-version }}'
Expand All @@ -97,7 +97,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.8]
python-version: [3.9]

steps:
- name: Checkout code
Expand All @@ -120,7 +120,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.8]
python-version: [3.9]

steps:
- name: Checkout code
Expand Down
8 changes: 6 additions & 2 deletions .gitignore
@@ -1,7 +1,7 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
.ipynb_checkpoints
.ipynb_checkpoints
# C extensions
*.so

Expand Down Expand Up @@ -36,7 +36,7 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage*
.cache
nosetests.xml
coverage.xml
Expand All @@ -60,3 +60,7 @@ target/
# VIM stuff
*.swo
*.swp

# VS Code stuff
.vscode
.env
2 changes: 1 addition & 1 deletion doc/Makefile
Expand Up @@ -2,7 +2,7 @@
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXOPTS = -W --keep-going
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
Expand Down
6 changes: 4 additions & 2 deletions doc/changes.rst
Expand Up @@ -5,11 +5,13 @@ desitarget Change Log
2.5.1 (unreleased)
------------------

* Address deprecated np.int and np.float dependencies [`PR #797`_]
* Functionality to download and reformat files for Gaia DR3 [`PR #796`_]
* Address deprecated np.int and np.float dependencies [`PR #797`_].
* Functionality to download and reformat files for Gaia DR3 [`PR #796`_].
* Restore coverage for svX code [`PR #799`_].

.. _`PR #796`: https://github.com/desihub/desitarget/pull/796
.. _`PR #797`: https://github.com/desihub/desitarget/pull/797
.. _`PR #799`: https://github.com/desihub/desitarget/pull/799

2.5.0 (2022-04-22)
------------------
Expand Down
5 changes: 4 additions & 1 deletion py/desitarget/cuts.py
Expand Up @@ -2890,8 +2890,11 @@ def apply_cuts(objects, qso_selection='randomforest',
# code or an iteration of SV.
if survey == 'main':
import desitarget.cuts as targcuts
assert targcuts.__name__ == 'desitarget.cuts'
elif survey[:2] == 'sv':
targcuts = import_module("desitarget.{}.{}_cuts".format(survey, survey))
sv_module = "desitarget.{}.{}_cuts".format(survey, survey)
targcuts = import_module(sv_module)
assert targcuts.__name__ == sv_module
else:
msg = "survey must be either 'main'or 'svX', not {}!!!".format(survey)
log.critical(msg)
Expand Down
4 changes: 4 additions & 0 deletions py/desitarget/test/test_brightmask.py
Expand Up @@ -5,6 +5,7 @@
import unittest
from pkg_resources import resource_filename
import os
import sys
import fitsio
import numpy as np
import numpy.lib.recfunctions as rfn
Expand All @@ -18,6 +19,8 @@

from desiutil import brick

_macos = sys.platform == 'darwin'


class TestBRIGHTMASK(unittest.TestCase):

Expand Down Expand Up @@ -106,6 +109,7 @@ def test_make_bright_star_mask(self):
self.assertTrue(len(set(mx["REF_ID"]) - set(self.allmx["REF_ID"])) == 0)
self.assertTrue(len(set(self.allmx["REF_ID"]) - set(mx["REF_ID"])) > 0)

@unittest.skipIf(_macos, "Skipping parallel test that fails on macOS.")
def test_make_bright_star_mask_parallel(self):
"""Check running the mask-making code in parallel.
"""
Expand Down
4 changes: 4 additions & 0 deletions py/desitarget/test/test_cmx.py
Expand Up @@ -3,6 +3,7 @@
"""Test desitarget.cmx.
"""
import unittest
import sys
from pkg_resources import resource_filename
import os.path
from uuid import uuid4
Expand All @@ -18,6 +19,8 @@
from desitarget import io
from desitarget.cmx import cmx_cuts as cuts

_macos = sys.platform == 'darwin'


class TestCMX(unittest.TestCase):

Expand Down Expand Up @@ -140,6 +143,7 @@ def test_missing_files(self):
with self.assertRaises(ValueError):
targets = cuts.select_targets(['blat.foo1234', ], numproc=1)

@unittest.skipIf(_macos, "Skipping parallel test that fails on macOS.")
def test_parallel_select(self):
"""Test multiprocessing parallelization works
"""
Expand Down
5 changes: 5 additions & 0 deletions py/desitarget/test/test_cuts.py
Expand Up @@ -3,6 +3,7 @@
"""Test desitarget.cuts.
"""
import unittest
import sys
from pkg_resources import resource_filename
import os.path
from uuid import uuid4
Expand All @@ -19,6 +20,8 @@
from desitarget.targetmask import desi_mask
from desitarget.geomask import hp_in_box, pixarea2nside, box_area

_macos = sys.platform == 'darwin'


class TestCuts(unittest.TestCase):

Expand Down Expand Up @@ -298,6 +301,7 @@ def test_select_targets(self):

self.assertTrue(np.all(t1[col][notNaN] == t2[col][notNaN]))

@unittest.skipIf(_macos, "Skipping parallel test that fails on macOS.")
def test_qso_selection_options(self):
"""Test the QSO selection options are passed correctly
"""
Expand Down Expand Up @@ -329,6 +333,7 @@ def test_missing_files(self):
with self.assertRaises(ValueError):
targets = cuts.select_targets(['blat.foo1234', ], numproc=1)

@unittest.skipIf(_macos, "Skipping parallel test that fails on macOS.")
def test_parallel_select(self):
"""Test multiprocessing parallelization works
"""
Expand Down
5 changes: 5 additions & 0 deletions py/desitarget/test/test_qa.py
Expand Up @@ -4,6 +4,7 @@
"""
import unittest
import os
import sys
import shutil
import tempfile
import warnings
Expand All @@ -16,6 +17,8 @@
from desiutil.log import get_logger
log = get_logger()

_macos = sys.platform == 'darwin'


class TestQA(unittest.TestCase):

Expand Down Expand Up @@ -56,6 +59,7 @@ def tearDown(self):
if os.path.exists(filename):
os.remove(filename)

@unittest.skipIf(_macos, "Skipping parallel test that fails on macOS.")
def test_qa_main(self):
"""Test plots/pages made for some main survey target types.
"""
Expand All @@ -80,6 +84,7 @@ def test_qa_main(self):
# ADM there are only .html, .dat and .png files.
self.assertEqual(pngs+htmls+dats, alls)

@unittest.skipIf(_macos, "Skipping parallel test that fails on macOS.")
def test_qa_cmx(self):
"""Test plots/pages are made for some commissioning targets.
"""
Expand Down
1 change: 1 addition & 0 deletions py/desitarget/test/test_secondary.py
Expand Up @@ -30,6 +30,7 @@ def test_flavors(self):
"""Test that secondary masks only have the allowed flavors.
"""
# ADM for each mask...
self.assertEqual(len(self.Mxs), 4)
for Mx in self.Mxs:
# ADM ...if we've already defined the flavor property...
if "flavor" in dir(Mx[Mx[0]]):
Expand Down
13 changes: 13 additions & 0 deletions py/desitarget/test/test_sv.py
Expand Up @@ -3,6 +3,7 @@
"""Test desitarget.sv.
"""
import unittest
import sys
import fitsio
import os
import numpy as np
Expand All @@ -13,6 +14,8 @@
from desitarget import io, cuts
from desitarget.targetmask import desi_mask

_macos = sys.platform == 'darwin'


class TestSV(unittest.TestCase):

Expand Down Expand Up @@ -42,16 +45,19 @@ def tearDownClass(cls):
if cls.gaiadir_orig is not None:
os.environ["GAIA_DIR"] = cls.gaiadir_orig

@unittest.skipIf(_macos, "Skipping parallel test that fails on macOS.")
def test_sv_cuts(self):
"""Test SV cuts work.
"""
# ADM find all svX sub-directories in the desitarget directory.
fns = sorted(glob(resource_filename('desitarget', 'sv*')))
svlist = [os.path.basename(fn) for fn in fns if os.path.isdir(fn)]
self.assertEqual(len(svlist), 3)

for survey in svlist:
desicol, bgscol, mwscol = ["{}_{}_TARGET".format(survey.upper(), tc)
for tc in ["DESI", "BGS", "MWS"]]
number_of_calls = 0
for filelist in [self.tractorfiles, self.sweepfiles]:
# ADM set backup to False as the Gaia unit test
# ADM files only cover a limited pixel range.
Expand All @@ -66,8 +72,12 @@ def test_sv_cuts(self):
bgs1 = (targets[desicol] & desi_mask.BGS_ANY) != 0
bgs2 = targets[bgscol] != 0
self.assertTrue(np.all(bgs1 == bgs2))
number_of_calls += 1

self.assertEqual(number_of_calls, 2)

# ADM backup targets can only be run on sweep files.
number_of_calls = 0
for filelist in self.sweepfiles:
# ADM also test the backup targets in the pixels covered
# ADM by the Gaia unit test files.
Expand All @@ -76,6 +86,9 @@ def test_sv_cuts(self):
for col in desicol, bgscol, mwscol:
self.assertTrue(col in targets.dtype.names)
self.assertEqual(len(targets), np.count_nonzero(targets[desicol]))
number_of_calls += 1

self.assertEqual(number_of_calls, 3)


if __name__ == '__main__':
Expand Down
13 changes: 7 additions & 6 deletions requirements.txt
@@ -1,7 +1,7 @@
# Based on desimodules/20.8.
# Based on desimodules/22.5.
pytz
requests
astropy==4.0.1.post1
astropy==5.0
numba
healpy
speclite
Expand All @@ -10,8 +10,9 @@ fitsio
photutils
# Install desiutil separately since it is needed for the other installs.
# git+https://github.com/desihub/desiutil.git@3.1.0#egg=desiutil
git+https://github.com/desihub/specter.git@0.9.4#egg=specter
git+https://github.com/desihub/desimodel.git@0.13.0#egg=desimodel
git+https://github.com/desihub/specter.git@0.10.0#egg=specter
git+https://github.com/desihub/desimodel.git@0.17.0#egg=desimodel
# Don't forget to install desimodel test data.
git+https://github.com/desihub/desispec.git@0.36.1#egg=desispec
git+https://github.com/desihub/desisim.git@main#egg=desisim
git+https://github.com/desihub/desispec.git@0.53.1#egg=desispec
git+https://github.com/desihub/desisim.git@0.36.0#egg=desisim
git+https://github.com/desihub/redrock.git@0.15.4#egg=redrock

0 comments on commit 73ee3fd

Please sign in to comment.