diff --git a/tests/opsimblitz1_1133_sqlite.db b/tests/opsimblitz1_1133_sqlite.db deleted file mode 100644 index 2e674df9a..000000000 Binary files a/tests/opsimblitz1_1133_sqlite.db and /dev/null differ diff --git a/tests/pontus_1150.db b/tests/pontus_1150.db deleted file mode 100644 index 7d62a8965..000000000 Binary files a/tests/pontus_1150.db and /dev/null differ diff --git a/tests/testDB.py b/tests/testDB.py index 105299fe9..1c6bfddcb 100644 --- a/tests/testDB.py +++ b/tests/testDB.py @@ -6,7 +6,7 @@ import lsst.sims.maf.db as db import lsst.utils.tests from lsst.sims.utils.CodeUtilities import sims_clean_up - +from lsst.utils import getPackageDir class TestDb(unittest.TestCase): @@ -15,8 +15,8 @@ def tearDownClass(cls): sims_clean_up() def setUp(self): - self.database = os.path.join(os.getenv('SIMS_MAF_DIR'), - 'tests', 'pontus_1150.db') + self.database = os.path.join(getPackageDir('sims_data'), + 'OpSimData', 'astro-lsst-01_2014.db') self.driver = 'sqlite' def tearDown(self): @@ -32,6 +32,7 @@ def testBaseDatabase(self): 'SlewActivities', 'TargetExposures', 'ObsHistory', 'SlewFinalState', 'TargetHistory', 'ObsProposalHistory', 'SlewHistory', 'TargetProposalHistory', 'Proposal', + 'ProposalField', 'SlewInitialState', 'UnscheduledDowntime'] self.assertEqual(set(basedb.tableNames), set(expectedTables)) diff --git a/tests/testMetricBundle.py b/tests/testMetricBundle.py index 9f209ae1d..1cd230001 100644 --- a/tests/testMetricBundle.py +++ b/tests/testMetricBundle.py @@ -10,8 +10,10 @@ import lsst.sims.maf.db as db import glob import os +import tempfile import shutil import lsst.utils.tests +from lsst.utils import getPackageDir from lsst.sims.utils.CodeUtilities import sims_clean_up @@ -22,7 +24,7 @@ def tearDownClass(cls): sims_clean_up() def setUp(self): - self.outDir = 'TMB' + self.outDir = tempfile.mkdtemp(prefix='TMB') def testOut(self): """ @@ -38,9 +40,8 @@ def testOut(self): map2 = maps.StellarDensityMap() metricB = metricBundles.MetricBundle(metric, slicer, sql, stackerList=[stacker1, stacker2]) - filepath = os.path.join(os.getenv('SIMS_MAF_DIR'), 'tests/') + database = os.path.join(getPackageDir('sims_data'), 'OpSimData', 'astro-lsst-01_2014.db') - database = os.path.join(filepath, 'pontus_1150.db') opsdb = db.OpsimDatabaseV4(database=database) resultsDb = db.ResultsDb(outDir=self.outDir) @@ -49,6 +50,8 @@ def testOut(self): bgroup.plotAll() bgroup.writeAll() + opsdb.close() + outThumbs = glob.glob(os.path.join(self.outDir, 'thumb*')) outNpz = glob.glob(os.path.join(self.outDir, '*.npz')) outPdf = glob.glob(os.path.join(self.outDir, '*.pdf')) diff --git a/tests/testOpsimDb.py b/tests/testOpsimDb.py index ab8c7bbfb..49930caf5 100644 --- a/tests/testOpsimDb.py +++ b/tests/testOpsimDb.py @@ -6,6 +6,7 @@ import lsst.sims.maf.db as db import lsst.sims.maf.utils.outputUtils as out import lsst.utils.tests +from lsst.utils import getPackageDir from lsst.sims.utils.CodeUtilities import sims_clean_up from builtins import str @@ -18,8 +19,8 @@ def tearDownClass(cls): sims_clean_up() def setUp(self): - self.database = os.path.join(os.getenv('SIMS_MAF_DIR'), 'tests', - 'pontus_1150.db') + self.database = os.path.join(getPackageDir('sims_data'), 'OpSimData', + 'astro-lsst-01_2014.db') self.oo = db.OpsimDatabaseV4(database=self.database) def tearDown(self): @@ -61,13 +62,13 @@ def testOpsimDbFields(self): def testOpsimDbRunLength(self): """Test query for length of opsim run.""" nrun = self.oo.fetchRunLength() - self.assertEqual(nrun, 1.) + self.assertEqual(nrun, 0.04) def testOpsimDbSimName(self): """Test query for opsim name.""" simname = self.oo.fetchOpsimRunName() self.assertTrue(isinstance(simname, str)) - self.assertEqual(simname, 'pontus_1150') + self.assertEqual(simname, 'astro-lsst-01_2014') def testOpsimDbConfig(self): """Test generation of config data. """ diff --git a/ups/sims_maf.table b/ups/sims_maf.table index e59372132..2e91eea7d 100644 --- a/ups/sims_maf.table +++ b/ups/sims_maf.table @@ -11,6 +11,8 @@ setupRequired(palpy) setupRequired(healpy) # For basic sims utilities setupRequired(sims_utils) +# For opsim database for unit test +setupRequired(sims_data) # For access to the db classes setupRequired(sims_catalogs) # For magnitude and SNR calculations