Skip to content

Commit

Permalink
removed the code that skips unit tests from the tests/SConscript
Browse files Browse the repository at this point in the history
added code to Persistence_2.py in tests/ that will simply exit
without running any tests if the user does not have credentials
for the necessary database

added code to the C++ unit tests to exit without failing
if the user does not have credentials to access the
test database

added comments explaining changes to unit test
  • Loading branch information
danielsf committed May 11, 2015
1 parent 92257e6 commit 615041f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
17 changes: 17 additions & 0 deletions tests/DbStorage_1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <sys/time.h>
#include "lsst/daf/persistence/DbStorage.h"
#include "lsst/daf/persistence/LogicalLocation.h"
#include "lsst/daf/persistence/DbAuth.h"
#include "lsst/pex/exceptions.h"

#define BOOST_TEST_MODULE DbStorage_1
Expand All @@ -44,6 +45,14 @@ BOOST_AUTO_TEST_SUITE(DbStorageSuite)
BOOST_AUTO_TEST_CASE(DbStorage) {
lsst::pex::policy::Policy::Ptr policy(new lsst::pex::policy::Policy);

//If the user cannot access the test database, exit
//without failing
dafPersist::DbAuth testAuth;
testAuth.setPolicy(policy);
if(!testAuth.available("lsst10.ncsa.uiuc.edu","3306")){
return;
}

struct timeval tv;
gettimeofday(&tv, 0);
long long testId = tv.tv_sec * 1000000LL + tv.tv_usec;
Expand Down Expand Up @@ -136,6 +145,14 @@ BOOST_AUTO_TEST_CASE(DbStorage) {
BOOST_AUTO_TEST_CASE(DbStorageExprs) {
lsst::pex::policy::Policy::Ptr policy(new lsst::pex::policy::Policy);

//If the user cannot access the test database, exit
//without failing
dafPersist::DbAuth testAuth;
testAuth.setPolicy(policy);
if(!testAuth.available("lsst10.ncsa.uiuc.edu","3306")){
return;
}

// Normally, we would create a DbStorage via
// Persistence::getRetrieveStorage(). For testing purposes, we create one
// ourselves.
Expand Down
9 changes: 9 additions & 0 deletions tests/Persistence_1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern "C" {
#include "lsst/daf/persistence/DbTsvStorage.h"
#include "lsst/daf/persistence/Formatter.h"
#include "lsst/daf/persistence/LogicalLocation.h"
#include "lsst/daf/persistence/DbAuth.h"
#include "lsst/daf/persistence/Persistence.h"

#define BOOST_TEST_MODULE Persistence_1
Expand Down Expand Up @@ -185,6 +186,14 @@ BOOST_AUTO_TEST_CASE(PersistenceTest) {
// Define a blank Policy.
lsst::pex::policy::Policy::Ptr policy(new lsst::pex::policy::Policy);

//If the user cannot access the test database, exit
//without failing
dafPersist::DbAuth testAuth;
testAuth.setPolicy(policy);
if(!testAuth.available("lsst10.ncsa.uiuc.edu","3306")){
return;
}

// Get a unique id for this test.
struct timeval tv;
gettimeofday(&tv, 0);
Expand Down
9 changes: 9 additions & 0 deletions tests/Persistence_2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "lsst/daf/persistence/DbStorage.h"
#include "lsst/daf/persistence/Formatter.h"
#include "lsst/daf/persistence/LogicalLocation.h"
#include "lsst/daf/persistence/DbAuth.h"
#include "lsst/daf/persistence/Persistence.h"

#define BOOST_TEST_MODULE Persistence_2
Expand Down Expand Up @@ -192,6 +193,14 @@ BOOST_AUTO_TEST_CASE(Persistence2Test) {
// Define a blank Policy.
lsst::pex::policy::Policy::Ptr policy(new lsst::pex::policy::Policy);

//If the user cannot access the test database, exit
//without failing
dafPersist::DbAuth testAuth;
testAuth.setPolicy(policy);
if(!testAuth.available("lsst10.ncsa.uiuc.edu","3306")){
return;
}

// Get a unique id for this test.
struct timeval tv;
gettimeofday(&tv, 0);
Expand Down
5 changes: 5 additions & 0 deletions tests/Persistence_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

import sys
import lsst.daf.base as dafBase
import lsst.daf.persistence as dafPersist
import lsst.pex.policy as pexPolicy

if not dafPersist.DbAuth.available("lsst10.ncsa.uiuc.edu", "3306"):
print "*** WARNING*** Database authenticator unavailable. Skipping test."
sys.exit()

def test1():
"""
Test PropertySet persistence to database without policy.
Expand Down
5 changes: 0 additions & 5 deletions tests/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@ from lsst.sconsUtils import scripts
import os

ignoreList = ["cameraMapper.py", "pickleMapper.py"]
if not os.path.exists(os.path.join(os.environ['HOME'], ".lsst/db-auth.paf")):
ignoreList.extend(["DateTime_1", "DbStorage_1", "DbStorage_1.py", "DbStorage_2.py",
"Persistence_1", "Persistence_2", "Persistence_2.py"])
print "WARNING: No fallback database authenticator seen"
print "Database tests are being skipped"

scripts.BasicSConscript.tests(ignoreList=ignoreList)

0 comments on commit 615041f

Please sign in to comment.