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

Update test suite #81

Merged
merged 6 commits into from
Apr 28, 2020
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
31 changes: 17 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ os:
- linux
# - osx

# As of early 2017, the default Linux environment is Ubuntu 12.04 (precise).
# This will soon change to 14.04 (trusty). To prepare, set it explicitly.
dist: trusty
# xenial = Ubuntu 16.04
# bionic = Ubuntu 18.04
dist: xenial
# Setting sudo to false opts in to Travis-CI container-based builds.
sudo: false

Expand All @@ -27,17 +27,18 @@ addons:
- texlive-latex-extra
- dvipng
python:
- 3.5
# - 3.5
- 3.6
# - 3.7
- 3.7
- 3.8
env:
global:
# The following versions are the 'default' for tests, unless
# overidden underneath. They are defined here in order to save having
# to repeat them for all configurations.
- MAIN_CMD='python setup.py'
- DESIUTIL_VERSION=2.0.1
- SPHINX_VERSION=1.8.5
- DESIUTIL_VERSION=2.0.3
- SPHINX_VERSION='<2.0'
matrix:
- SETUP_CMD='egg_info'
- SETUP_CMD='bdist_egg'
Expand Down Expand Up @@ -65,12 +66,13 @@ matrix:
python: 3.6
env: MAIN_CMD='coverage' SETUP_CMD='run --source=desidatamodel setup.py test'

# Experimental OS X test.
# As of March 2017, Python builds on OS X are not available.
# See https://docs.travis-ci.com/user/languages/python/
# - os: osx
# python: 3.5
# env: SETUP_CMD='test'
- os: linux
python: 3.6
env: SETUP_CMD='test' ASTROPY_VERSION='>=4.0'

- os: linux
python: 3.6
env: SETUP_CMD='test' ASTROPY_VERSION='<4.0'

# PEP 8 compliance.
- os: linux
Expand All @@ -82,10 +84,11 @@ matrix:

install:
- if [[ $MAIN_CMD == 'pycodestyle' ]]; then pip install pycodestyle; fi
- if [[ $SETUP_CMD == build_sphinx* ]]; then pip install Sphinx==${SPHINX_VERSION}; fi
- if [[ $SETUP_CMD == build_sphinx* ]]; then pip install Sphinx${SPHINX_VERSION}; fi
- if [[ $MAIN_CMD == 'coverage' ]]; then pip install coverage coveralls; fi
- pip install git+https://github.com/desihub/desiutil.git@${DESIUTIL_VERSION}#egg=desiutil
- if [[ $SETUP_CMD == 'test' || $MAIN_CMD == 'coverage' ]]; then pip install -r requirements.txt; fi
- if [[ -n "${ASTROPY_VERSION}" ]]; then pip install -U "astropy${ASTROPY_VERSION}"; fi

script:
- $MAIN_CMD $SETUP_CMD
Expand Down
4 changes: 3 additions & 1 deletion doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
desidatamodel Change Log
========================

19.9 (unreleased)
20.4 (unreleased)
-----------------

* Update Travis test configuration (PR `#81`_).
* Update data model to reflect 19.9 software release (PR `#78`_).

.. _`#78`: https://github.com/desihub/desidatamodel/pull/78
.. _`#81`: https://github.com/desihub/desidatamodel/pull/81

19.2 (2019-10-01)
------------------
Expand Down
11 changes: 11 additions & 0 deletions py/desidatamodel/test/datamodeltestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import logging
import shutil

from astropy import __version__ as astropyVersion

from desiutil.log import log
from desiutil.test.test_log import TestHandler

Expand All @@ -18,6 +20,7 @@ class DataModelTestCase(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.astropyVersion = int(astropyVersion.split('.')[0])
cls.maxDiff = None
cls.data_dir = tempfile.mkdtemp()
if DM in os.environ:
Expand Down Expand Up @@ -71,3 +74,11 @@ def assertLog(self, logger, order=-1, message=''):
handler = root_logger.handlers[0]
record = handler.buffer[order]
self.assertEqual(record.getMessage(), message)

def badUnitMessage(self, unit):
"""Returns a string that can be used to match errors related to bad units.
"""
m = "'{0}' did not parse as fits unit: At col {1:d}, Unit 'ergs' not supported by the FITS standard. Did you mean erg?".format(unit, unit.index('ergs'))
if self.astropyVersion >= 4:
m += " If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see http://docs.astropy.org/en/latest/units/combining_and_defining.html"
return m
10 changes: 6 additions & 4 deletions py/desidatamodel/test/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def test_extract_metadata_missing_extname(self):
def test_extract_metadata_bad_keyword_unit(self):
"""Test reading metadata with bad FITS BUNIT values.
"""
erg_msg = self.badUnitMessage('ergs')
modelfile = resource_filename('desidatamodel.test', 't/fits_file.rst')
model = DataModel(modelfile, os.path.dirname(modelfile))
meta = model.extract_metadata()
Expand All @@ -159,10 +160,10 @@ def test_extract_metadata_bad_keyword_unit(self):
model._metafile_data = '\n'.join(lines) + '\n'
with self.assertRaises(ValueError) as e:
meta = model.extract_metadata(error=True)
self.assertEqual(str(e.exception), "'ergs' did not parse as fits unit: At col 0, Unit 'ergs' not supported by the FITS standard. Did you mean erg?")
self.assertEqual(str(e.exception), erg_msg)
meta = model.extract_metadata(error=False)
self.assertLog(log, -1, "HDU 0 in {0} should have a more meaningful EXTNAME than 'PRIMARY'.".format(modelfile))
self.assertLog(log, -2, "'ergs' did not parse as fits unit: At col 0, Unit 'ergs' not supported by the FITS standard. Did you mean erg?")
self.assertLog(log, -2, erg_msg)

def test_extract_metadata_missing_keyword_unit(self):
"""Test reading metadata with missing units for header keywords.
Expand All @@ -183,6 +184,7 @@ def test_extract_metadata_missing_keyword_unit(self):
def test_extract_metadata_bad_column_unit(self):
"""Test reading metadata with bad FITS column units.
"""
erg_msg = self.badUnitMessage('ergs')
modelfile = resource_filename('desidatamodel.test', 't/fits_file.rst')
model = DataModel(modelfile, os.path.dirname(modelfile))
meta = model.extract_metadata()
Expand All @@ -191,9 +193,9 @@ def test_extract_metadata_bad_column_unit(self):
model._metafile_data = '\n'.join(lines) + '\n'
with self.assertRaises(ValueError) as e:
meta = model.extract_metadata(error=True)
self.assertEqual(str(e.exception), "'ergs' did not parse as fits unit: At col 0, Unit 'ergs' not supported by the FITS standard. Did you mean erg?")
self.assertEqual(str(e.exception), erg_msg)
meta = model.extract_metadata(error=False)
self.assertLog(log, -1, "'ergs' did not parse as fits unit: At col 0, Unit 'ergs' not supported by the FITS standard. Did you mean erg?")
self.assertLog(log, -1, erg_msg)

def test_extract_metadata_missing_column_type(self):
"""Test reading metadata with missing FITS column types.
Expand Down
10 changes: 6 additions & 4 deletions py/desidatamodel/test/test_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def test_Stub_BINTABLE_with_units(self):
def test_Stub_BINTABLE_with_bad_units(self):
"""Test BINTABLE HDU with bad units.
"""
erg_msg = self.badUnitMessage('ergs')
hdulist = list()
hdr = sim_header()
hdr['SIMPLE'] = True
Expand Down Expand Up @@ -264,17 +265,18 @@ def test_Stub_BINTABLE_with_bad_units(self):
stub.filename = 'fits_file.fits'
stub._filesize = '10 MB'
self.assertEqual(stub.hdumeta[1]['format'][2], ('luminosity', 'float32', 'ergs', 'This is a TCOMM comment on luminosity.'))
# self.assertLog(log, 1, "'ergs' did not parse as fits unit: At col 0, Unit 'ergs' not supported by the FITS standard. Did you mean erg?")
# self.assertLog(log, 1, erg_msg)
stub = Stub(hdulist, error=True)
stub.filename = 'fits_file.fits'
stub._filesize = '10 MB'
with self.assertRaises(ValueError) as e:
foo = stub.hdumeta[1]['format'][2]
self.assertEqual(str(e.exception), "'ergs' did not parse as fits unit: At col 0, Unit 'ergs' not supported by the FITS standard. Did you mean erg?")
self.assertEqual(str(e.exception), erg_msg)

def test_Stub_image_format(self):
"""Test format string for image HDUs.
"""
erg_msg = self.badUnitMessage('10**-17 ergs/(cm**2*s*Angstrom)')
hdr = sim_header()
hdr['SIMPLE'] = True
hdr['BITPIX'] = 8
Expand Down Expand Up @@ -319,10 +321,10 @@ def test_Stub_image_format(self):
stub = Stub([sim_hdu(hdr)], error=True)
with self.assertRaises(ValueError) as e:
i = stub.image_format(hdr)
self.assertEqual(str(e.exception), "'10**-17 ergs/(cm**2*s*Angstrom)' did not parse as fits unit: At col 8, Unit 'ergs' not supported by the FITS standard. Did you mean erg?")
self.assertEqual(str(e.exception), erg_msg)
stub = Stub([sim_hdu(hdr)], error=False)
i = stub.image_format(hdr)
self.assertLog(log, 1, "'10**-17 ergs/(cm**2*s*Angstrom)' did not parse as fits unit: At col 8, Unit 'ergs' not supported by the FITS standard. Did you mean erg?")
self.assertLog(log, 1, erg_msg)
self.assertEqual(i, 'Data: FITS image [BITPIX=128, 1000x1000]')
hdr = sim_header()
hdr['SIMPLE'] = True
Expand Down
8 changes: 4 additions & 4 deletions py/desidatamodel/test/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# import os
import unittest
# from pkg_resources import resource_filename

# from .. import DataModelError
from .datamodeltestcase import DataModelTestCase
from ..unit import DataModelUnit, log
Expand All @@ -18,18 +17,19 @@ class TestUnit(DataModelTestCase):
def test_check_model(self):
"""Test method to validate units.
"""
erg_msg = self.badUnitMessage('ergs')
u = DataModelUnit()
c = u.check_unit('erg')
self.assertIsNone(c)
c = u.check_unit('ergs', error=False)
self.assertIsNone(c)
c = u.check_unit('nanomaggies', error=True)
self.assertEqual(c, "'nanomaggies'")
self.assertLog(log, -1, "'ergs' did not parse as fits unit: At col 0, Unit 'ergs' not supported by the FITS standard. Did you mean erg?")
self.assertLog(log, -1, erg_msg)
with self.assertRaises(ValueError) as e:
c = u.check_unit('ergs', error=True)
self.assertEqual(str(e.exception), "'ergs' did not parse as fits unit: At col 0, Unit 'ergs' not supported by the FITS standard. Did you mean erg?")
self.assertLog(log, -1, "'ergs' did not parse as fits unit: At col 0, Unit 'ergs' not supported by the FITS standard. Did you mean erg?")
self.assertEqual(str(e.exception), erg_msg)
self.assertLog(log, -1, erg_msg)


def test_suite():
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
astropy
git+https://github.com/desihub/desiutil.git@2.0.1#egg=desiutil
astropy==2.0.16
git+https://github.com/desihub/desiutil.git@2.0.3#egg=desiutil