Skip to content

Commit

Permalink
Trigger unittest.SkipTest() if DBauth doesn't connect.
Browse files Browse the repository at this point in the history
Previously these DB connection tests were being skipped by scons.
The shift here to being a setUpClass method allows for the exception
to be raised and the test formally "Skipped" instead falsely "Passed"
as it was before.
  • Loading branch information
wmwv committed Aug 25, 2016
1 parent 9041dc9 commit 0fc7137
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
31 changes: 15 additions & 16 deletions tests/testSelectFluxMag0.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ def __init__(self, dataId):
class ScaleLsstSimZeroPointTaskTestCase(unittest.TestCase):
"""A test case for ScaleLsstSimZeroPointTask
"""
@classmethod
def setUpClass(self):
"""Initialize the DB connection. Raise SkipTest if unable to access DB."""
config = SpatialScaleZeroPointTask.ConfigClass()
config.selectFluxMag0.retarget(SelectLsstSimFluxMag0Task)
print config
try:
DbAuth.username(config.selectFluxMag0.host, str(config.selectFluxMag0.port)),
except (Exception, RuntimeError) as e:
reason = "Warning: did not find host=%s, port=%s in your db-auth file; or %s " \
"skipping unit tests" % \
(config.selectFluxMag0.host, str(config.selectFluxMag0.port), e)
raise unittest.SkipTest(reason)


def makeTestExposure(self, xNumPix, yNumPix):
"""
Create and return an exposure that is completely covered by the database: test_select_lsst_images
Expand Down Expand Up @@ -152,22 +167,6 @@ class MemoryTester(lsst.utils.tests.MemoryTestCase):
pass


return unittest.TestSuite(suites)


def run(shouldExit=False):
"""Run the tests"""

config = SpatialScaleZeroPointTask.ConfigClass()
config.selectFluxMag0.retarget(SelectLsstSimFluxMag0Task)
print config
try:
DbAuth.username(config.selectFluxMag0.host, str(config.selectFluxMag0.port)),
except Exception, e:
print "Warning: did not find host=%s, port=%s in your db-auth file; or %s " \
"skipping unit tests" % \
(config.selectFluxMag0.host, str(config.selectFluxMag0.port), e)
return
def setup_module(module):
lsst.utils.tests.init()

Expand Down
20 changes: 11 additions & 9 deletions tests/testSelectLsstImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ def getCoordList(minRa, minDec, maxRa, maxDec):

class LsstMapperTestCase(unittest.TestCase):
"""A test case for SelectLsstImagesTask."""
@classmethod
def setUpClass(self):
"""Initialize the DB connection. Raise SkipTest if unable to access DB."""
config = SelectLsstImagesTask.ConfigClass()
try:
DbAuth.username(config.host, str(config.port)),
except (Exception, RuntimeError) as e:
reason = "Warning: did not find host=%s, port=%s in your db-auth file; skipping SelectLsstImagesTask unit tests" % \
(config.host, str(config.port))
raise unittest.SkipTest(reason)

def testMaxFwhm(self):
"""Test config.maxFwhm
"""
Expand Down Expand Up @@ -89,15 +100,6 @@ class MemoryTester(lsst.utils.tests.MemoryTestCase):
pass


def run(shouldExit=False):
config = SelectLsstImagesTask.ConfigClass()
try:
DbAuth.username(config.host, str(config.port)),
except Exception:
print "Warning: did not find host=%s, port=%s in your db-auth file; skipping SelectLsstImagesTask unit tests" % \
(config.host, str(config.port))
return

def setup_module(module):
lsst.utils.tests.init()

Expand Down

0 comments on commit 0fc7137

Please sign in to comment.