Skip to content

Commit

Permalink
Merge pull request #2155 from desihub/fix-2142
Browse files Browse the repository at this point in the history
remove deprecated test_suite() function from all unit tests that use it
  • Loading branch information
sbailey authored Jan 3, 2024
2 parents dc2e306 + 5a9fbe5 commit 46aa857
Show file tree
Hide file tree
Showing 47 changed files with 20 additions and 321 deletions.
3 changes: 1 addition & 2 deletions py/desispec/database/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
from pytz import utc
from sqlalchemy import (create_engine, text, Table, ForeignKey, Column,
Integer, String, Float, DateTime)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm import sessionmaker, relationship, reconstructor
from sqlalchemy.orm import sessionmaker, relationship, reconstructor, declarative_base
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from matplotlib.patches import Circle, Polygon, Wedge
from matplotlib.collections import PatchCollection
Expand Down
2 changes: 1 addition & 1 deletion py/desispec/image_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from desispec.qproc.qsky import qproc_sky_subtraction
from desispec.qproc.qfiberflat import qproc_apply_fiberflat

@numba.jit
@numba.jit(nopython=True)
def numba_proj(image,x,sigma,flux) :
'''
Add a spectrum to a model of the pixel values in a CCD image assuming a Gaussian cross-dispersion profile.
Expand Down
2 changes: 1 addition & 1 deletion py/desispec/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import warnings
warnings.filterwarnings('ignore', message="'.*nanomaggie.* did not parse as fits unit.*")
warnings.filterwarnings('ignore', message="'.*nanomaggy.* did not parse as fits unit.*")
warnings.filterwarnings('ignore', message=".*'10\*\*6 arcsec.* did not parse as fits unit.*")
warnings.filterwarnings('ignore', message=r".*'10\*\*6 arcsec.* did not parse as fits unit.*")

# from .download import download, filepath2url
from .fiberflat import read_fiberflat, write_fiberflat
Expand Down
2 changes: 1 addition & 1 deletion py/desispec/preproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def _background(image,header,patch_width=200,stitch_width=10,stitch=False) :
log.info("done")
return bkg

@numba.jit
@numba.jit(nopython=True)
def numba_mean(image_flux,image_ivar,x,hw=3) :
"""
Returns mean of pixels vs. row about x+-hw
Expand Down
2 changes: 1 addition & 1 deletion py/desispec/qproc/qextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from desispec.qproc.qframe import QFrame


@numba.jit
@numba.jit(nopython=True)
def numba_extract(image_flux,image_var,x,hw=3) :
n0=image_flux.shape[0]
flux=np.zeros(n0)
Expand Down
12 changes: 0 additions & 12 deletions py/desispec/test/test_binscripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,3 @@ def test_compute_sky(self):
result, success = runcmd(desispec.scripts.sky.main, args=args,
inputs=inputs, outputs=outputs, clobber=True)
self.assertTrue(success)

def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m <modulename>
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)


#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
unittest.main()
4 changes: 1 addition & 3 deletions py/desispec/test/test_bitmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ def test_names(self):
self.assertEqual(m.mask(name), m.mask(m.bitnum(name)), 'Failed matching mask to name for '+name)
self.assertEqual(m.bitname(m.bitnum(name)), name, 'Failed bit name->num->name roundtrip for '+name)
c = m.comment(name)

if __name__ == '__main__':
unittest.main()

6 changes: 0 additions & 6 deletions py/desispec/test/test_bootcalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,3 @@ def test_main(self):
y = psf.y(ispec=indices, wavelength=waves)


def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m <modulename>
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)
4 changes: 0 additions & 4 deletions py/desispec/test/test_calibfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,3 @@ def test_init(self):
print(cfinder.value("DETECTOR"))
if cfinder.haskey("BIAS") :
print(cfinder.findfile("BIAS"))


if __name__ == '__main__':
unittest.main()
12 changes: 0 additions & 12 deletions py/desispec/test/test_ccdcalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,3 @@ def test_select_zero_expids(self):
del os.environ['DESI_LOGLEVEL']
else:
os.environ['DESI_LOGLEVEL'] = original_log_level


def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m desispec.test.test_ccdcalib
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)


if __name__ == '__main__':
unittest.main()
12 changes: 0 additions & 12 deletions py/desispec/test/test_coadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,15 +891,3 @@ def test_coadd_cameras(self):
spec.R = None
spec.mask = None
coadd = coadd_cameras(spec)


def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m desispec.test.test_coadd
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)


if __name__ == '__main__':
unittest.main()
4 changes: 0 additions & 4 deletions py/desispec/test/test_cosmics.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,3 @@ def test_reject_cosmics(self):
reject_cosmic_rays(image)
cosmic = (image.pix > 0)
self.assertTrue(np.all(image.mask[cosmic] & ccdmask.COSMIC))

#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
unittest.main()
6 changes: 0 additions & 6 deletions py/desispec/test/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,3 @@ def test_frameid(self):
self.assertEqual(frameid(9876543, 'z9'), 987654329)


def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m <modulename>
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)
10 changes: 0 additions & 10 deletions py/desispec/test/test_emlinefit.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,3 @@ def test_get_emlines(self):
#- but OIII should have NaN for second since it is off wavelength grid
self.assertFalse(np.isnan(results['OIII']['FLUX'][0]))
self.assertTrue(np.isnan(results['OIII']['FLUX'][1]))

def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m desispec.test.test_emlinefit
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)

if __name__ == '__main__':
unittest.main()
3 changes: 0 additions & 3 deletions py/desispec/test/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,3 @@ def test_bundles2(self):

def test_bundles3(self):
self._test_bundles("desi_extract_spectra -i {} -p {} -w 7500,7530,0.75 --nwavestep 10 -f {} --bundlesize 5 -o {} -m {} -s {} -n {}", 20, 5)

if __name__ == '__main__':
unittest.main()
4 changes: 0 additions & 4 deletions py/desispec/test/test_fiberbitmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,3 @@ def test_framebitmask(self):

ivar2 = get_fiberbitmasked_frame_arrays(self.frame, bitmask=1)
self.assertTrue( np.all(ivar1 == ivar2) )

#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
unittest.main()
3 changes: 0 additions & 3 deletions py/desispec/test/test_fibercrosstalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,3 @@ def test_fiber_crosstalk(self):

xyset = read_xytraceset(self.psffile)
correct_fiber_crosstalk(spectra,xyset=xyset)

if __name__ == '__main__':
unittest.main()
5 changes: 0 additions & 5 deletions py/desispec/test/test_fiberflat.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,3 @@ def test_slice(self):
x = self.ff[1:2]
x = self.ff[[1,2,3]]
x = self.ff[self.ff.fibers<3]


#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
unittest.main()
11 changes: 0 additions & 11 deletions py/desispec/test/test_fibermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,3 @@ def test_update_survey_keywords(self):
update_survey_keywords(hdr)
self.assertEqual(hdr['SURVEY'], 'sv2')
self.assertEqual(hdr['FAPRGRM'], 'dark')


def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m <modulename>
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)

if __name__ == '__main__':
unittest.main()
6 changes: 0 additions & 6 deletions py/desispec/test/test_flux_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,3 @@ def test_isStdStar(self):

def test_main(self):
pass



#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
unittest.main()
4 changes: 0 additions & 4 deletions py/desispec/test/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,3 @@ def test_vet(self):
# Mess with shape
frame.nspec = 5
self.assertEqual(frame.vet(), 1)

#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
unittest.main()
7 changes: 0 additions & 7 deletions py/desispec/test/test_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,3 @@ def gather(self, value, root):

desispec.gpu.redistribute_gpu_ranks(comm=FakeComm(0,16))
desispec.gpu.redistribute_gpu_ranks(comm=FakeComm(1,16))




#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
unittest.main()
4 changes: 0 additions & 4 deletions py/desispec/test/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,3 @@ def test_slicing(self):
img1[1:2, 'blat']
with self.assertRaises(ValueError):
img1[None, 1:2]

#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
unittest.main()
22 changes: 7 additions & 15 deletions py/desispec/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
"""

import sys
if __name__ == '__main__':
print('Run this instead:')
# print('python setup.py test -m desispec.test.test_io')
print('pytest py/desispec/test/test_io.py')
sys.exit(1)

import unittest
from unittest.mock import patch, MagicMock
import os
Expand Down Expand Up @@ -83,16 +77,19 @@ def tearDownClass(cls):
for testfile in [cls.testfile, cls.testyfile, cls.testbrfile, cls.testlog]:
if os.path.exists(testfile):
os.remove(testfile)

for e in cls.origEnv:
if cls.origEnv[e] is None:
del os.environ[e]
else:
os.environ[e] = cls.origEnv[e]

if os.path.exists(cls.testDir):
if os.path.isdir(cls.testDir):
rmtree(cls.testDir)

# reset the readonly cache
from ..io import meta
meta._desi_root_readonly = None

def test_write_bintable(self):
"""Test writing binary tables to FITS.
"""
Expand Down Expand Up @@ -975,7 +972,8 @@ def test_desi_root_readonly(self):
meta._desi_root_readonly = None

#- Case 1: $DESI_ROOT_READONLY is set and exists -> use it
os.environ['DESI_ROOT_READONLY'] = tempfile.mkdtemp()
tmpdir = tempfile.mkdtemp()
os.environ['DESI_ROOT_READONLY'] = tmpdir
blat = meta.get_desi_root_readonly()
self.assertEqual(blat, os.environ['DESI_ROOT_READONLY'])

Expand Down Expand Up @@ -1636,9 +1634,3 @@ def test_camword_spectros(self):
self.assertEqual(spectros_to_camword([5,6,0]), 'a056')


def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m <modulename>
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)
3 changes: 0 additions & 3 deletions py/desispec/test/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,3 @@ def test_cholesky_invert(self):

def runTest(self):
pass

if __name__ == '__main__':
unittest.main()
11 changes: 0 additions & 11 deletions py/desispec/test/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,3 @@ def check_weight_distribution(weights, groups, num_nodes, groups_per_node):

groups = weighted_partition(weights, num_groups-3, groups_per_node=groups_per_node)
check_weight_distribution(weights, groups, num_nodes, groups_per_node)

def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m <modulename>
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)

#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
unittest.main()
6 changes: 0 additions & 6 deletions py/desispec/test/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,3 @@ def test_read(self):
self.assertIsNot(p3, p4)
self.assertIsNot(p2, p4)

def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m <modulename>
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)
13 changes: 7 additions & 6 deletions py/desispec/test/test_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

class TestPhoto(unittest.TestCase):

def setUp(self):
@classmethod
def setUpClass(self):
from astropy.table import Table

# for testing gather_targetphot and gather_tractorphot

# sv3-dark (secondary), sv1-bright (primary), main-dark (secondary), main-dark (primary, south), main-dark (primary, north), sv3-bright (TOO)
input_cat = Table()
input_cat['TARGETID'] = [929413348720641, 39627061832191195, 2253225356951552, 39627565329026280, 39633086782113662, 43977491483722156]
Expand Down Expand Up @@ -54,6 +54,10 @@ def setUp(self):
tractorphot['LS_ID'] = np.array([10995128657712508, 10995128743167117, 10995128743105186]).astype(np.int64)
self.tractorphot_dr10 = tractorphot

@classmethod
def tearDownClass(self):
pass

@unittest.skipUnless('NERSC_HOST' in os.environ, "not at NERSC")
def test_gather_targetdirs(self):
"""Test that we get the correct targeting directories given a tile."""
Expand Down Expand Up @@ -102,6 +106,3 @@ def test_gather_tractorphot_dr10(self):
tractorphot = gather_tractorphot(self.input_cat_dr10, legacysurveydir=legacysurveydir)
for col in self.tractorphot_dr10.colnames:
self.assertTrue(np.all(tractorphot[col] == self.tractorphot_dr10[col]))

if __name__ == '__main__':
unittest.main()
12 changes: 0 additions & 12 deletions py/desispec/test/test_pipeline_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,3 @@ def test_create_load_prod(self):
# fullgrph = load_prod()
# self.assertTrue(grph == fullgrph)
pass


def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m <modulename>
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)

#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
unittest.main()
5 changes: 0 additions & 5 deletions py/desispec/test/test_pipeline_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,3 @@ def test_run(self):
pass


def test_suite():
"""Allows testing of only this module with the command::
python setup.py test -m <modulename>
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)
Loading

0 comments on commit 46aa857

Please sign in to comment.