Skip to content

Commit

Permalink
Move dbAuth exception message inside test class.
Browse files Browse the repository at this point in the history
Pytest only captures stderr/stdout messages that occur inside test
environment, not those that occur at module level.
  • Loading branch information
jmeyers314 committed Sep 9, 2016
1 parent f3fba9c commit f28d79e
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions tests/testSelectSdssImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#
from __future__ import print_function
import unittest
import sys

import lsst.utils.tests
from lsst.daf.persistence import DbAuth
Expand All @@ -42,8 +41,9 @@
try:
DbAuth.username(config.host, str(config.port)),
except Exception as e:
print("Did not find host={0}, port={1} in your db-auth file; \nWarning generated: {2} ".format(
config.host, str(config.port), e), file=sys.stderr)
noConnectionStr = ("No remote connection to SDSS image database\n"
"Did not find host={0}, port={1} in your db-auth file;\n"
"Warning generated: {2} ".format(config.host, str(config.port), e))
noConnection = True


Expand All @@ -60,7 +60,7 @@ def getCoordList(minRa, minDec, maxRa, maxDec):
class SelectSdssImagesTestCase(unittest.TestCase):
"""A test case for SelectSdssImagesTask."""

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testMaxFwhm(self):
"""Test config.maxFwhm
"""
Expand All @@ -74,7 +74,7 @@ def testMaxFwhm(self):
expInfoList = task.run(coordList=coordList, filter=filter).exposureInfoList
self.assertEqual(tuple(expInfo for expInfo in expInfoList if expInfo.fwhm > maxFwhm), ())

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testMaxAirmass(self):
"""Test config.maxAirmass
"""
Expand All @@ -88,7 +88,7 @@ def testMaxAirmass(self):
expInfoList = task.run(coordList=coordList, filter=filter).exposureInfoList
self.assertEqual(tuple(expInfo for expInfo in expInfoList if expInfo.airmass > maxAirmass), ())

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testMaxSky(self):
"""Test config.maxSky
"""
Expand All @@ -102,7 +102,7 @@ def testMaxSky(self):
expInfoList = task.run(coordList=coordList, filter=filter).exposureInfoList
self.assertEqual(tuple(expInfo for expInfo in expInfoList if expInfo.sky > maxSky), ())

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testQuality(self):
"""Test config.quality
"""
Expand All @@ -116,7 +116,7 @@ def testQuality(self):
expInfoList = task.run(coordList=coordList, filter=filter).exposureInfoList
self.assertEqual(tuple(expInfo for expInfo in expInfoList if expInfo.quality < quality), ())

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testCullBlacklisted(self):
"""Test config.cullBlacklisted
"""
Expand All @@ -135,7 +135,7 @@ def testCullBlacklisted(self):
else:
self.assertGreater(len(blacklistedList), 0)

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testCamcols(self):
"""Test config.camcols
"""
Expand All @@ -150,7 +150,7 @@ def testCamcols(self):
self.assertEqual(
tuple(expInfo for expInfo in expInfoList if expInfo.dataId["camcol"] not in camcols), ())

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testStrip(self):
"""Test config.strip
"""
Expand All @@ -169,7 +169,7 @@ def testStrip(self):
self.assertEqual(tuple(expInfo for expInfo in expInfoList if expInfo.strip != 'N'), ())
# no assert for "Both"

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testRejectWholeRuns(self):
"""Test config.rejectWholeRuns
"""
Expand All @@ -193,7 +193,7 @@ def testRejectWholeRuns(self):

self.checkExpList(minRa, maxRa, runExpInfoDict)

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testMaxExposures(self):
"""Test config.maxExposures
"""
Expand All @@ -207,7 +207,7 @@ def testMaxExposures(self):
expInfoList = task.run(coordList=coordList, filter=filter).exposureInfoList
self.assertEqual(len(expInfoList), maxExposures)

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testMaxRuns(self):
"""Test config.maxRuns
"""
Expand All @@ -222,7 +222,7 @@ def testMaxRuns(self):
runSet = set(expInfo.dataId["run"] for expInfo in expInfoList)
self.assertEqual(len(runSet), maxRuns)

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testQScore(self):
"""Test QScore sorting
"""
Expand All @@ -243,7 +243,7 @@ def testQScore(self):
self.assertGreater(bestExp.quality, worstExp.quality)
self.assertEqual(bestExp.quality, 3)

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testConfigValidate(self):
"""Test validation of config
"""
Expand All @@ -265,7 +265,7 @@ def testConfigValidate(self):
with self.assertRaises(Exception):
config.validate()

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testFilterValidation(self):
"""Test filter name validation
"""
Expand All @@ -281,7 +281,7 @@ def testFilterValidation(self):
with self.assertRaises(Exception):
task.run(coordList, filter)

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testAcrossWrap(self):
"""Test rejectWholeRuns across the RA 0/360 boundary
"""
Expand Down Expand Up @@ -327,7 +327,7 @@ def checkExpList(self, minRa, maxRa, runExpInfoDict):
self.assertGreaterEqual(minRa, raDegList[0])
self.assertGreaterEqual(raDegList[-1], maxRa)

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testTable(self):
"""Test config.table
"""
Expand All @@ -339,7 +339,7 @@ def testTable(self):
with self.assertRaises(Exception):
task.run(coordList, filter)

@unittest.skipIf(noConnection, "No remote connection to SDSS image database")
@unittest.skipIf(noConnection, noConnectionStr)
def testWholeSky(self):
"""Test whole-sky search (slow so don't do much)
"""
Expand Down

0 comments on commit f28d79e

Please sign in to comment.