Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 5ef656a

Browse files
Merge pull request #113 from lsst/feature/update-test-db
Use new opsim v4 db from sims_data
2 parents c82c60c + c7e1b84 commit 5ef656a

File tree

6 files changed

+17
-10
lines changed

6 files changed

+17
-10
lines changed

tests/opsimblitz1_1133_sqlite.db

-33.7 MB
Binary file not shown.

tests/pontus_1150.db

-6.46 MB
Binary file not shown.

tests/testDB.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import lsst.sims.maf.db as db
77
import lsst.utils.tests
88
from lsst.sims.utils.CodeUtilities import sims_clean_up
9-
9+
from lsst.utils import getPackageDir
1010

1111
class TestDb(unittest.TestCase):
1212

@@ -15,8 +15,8 @@ def tearDownClass(cls):
1515
sims_clean_up()
1616

1717
def setUp(self):
18-
self.database = os.path.join(os.getenv('SIMS_MAF_DIR'),
19-
'tests', 'pontus_1150.db')
18+
self.database = os.path.join(getPackageDir('sims_data'),
19+
'OpSimData', 'astro-lsst-01_2014.db')
2020
self.driver = 'sqlite'
2121

2222
def tearDown(self):
@@ -32,6 +32,7 @@ def testBaseDatabase(self):
3232
'SlewActivities', 'TargetExposures', 'ObsHistory',
3333
'SlewFinalState', 'TargetHistory', 'ObsProposalHistory',
3434
'SlewHistory', 'TargetProposalHistory', 'Proposal',
35+
'ProposalField',
3536
'SlewInitialState', 'UnscheduledDowntime']
3637
self.assertEqual(set(basedb.tableNames),
3738
set(expectedTables))

tests/testMetricBundle.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import lsst.sims.maf.db as db
1111
import glob
1212
import os
13+
import tempfile
1314
import shutil
1415
import lsst.utils.tests
16+
from lsst.utils import getPackageDir
1517
from lsst.sims.utils.CodeUtilities import sims_clean_up
1618

1719

@@ -22,7 +24,7 @@ def tearDownClass(cls):
2224
sims_clean_up()
2325

2426
def setUp(self):
25-
self.outDir = 'TMB'
27+
self.outDir = tempfile.mkdtemp(prefix='TMB')
2628

2729
def testOut(self):
2830
"""
@@ -38,9 +40,8 @@ def testOut(self):
3840
map2 = maps.StellarDensityMap()
3941

4042
metricB = metricBundles.MetricBundle(metric, slicer, sql, stackerList=[stacker1, stacker2])
41-
filepath = os.path.join(os.getenv('SIMS_MAF_DIR'), 'tests/')
43+
database = os.path.join(getPackageDir('sims_data'), 'OpSimData', 'astro-lsst-01_2014.db')
4244

43-
database = os.path.join(filepath, 'pontus_1150.db')
4445
opsdb = db.OpsimDatabaseV4(database=database)
4546
resultsDb = db.ResultsDb(outDir=self.outDir)
4647

@@ -49,6 +50,8 @@ def testOut(self):
4950
bgroup.plotAll()
5051
bgroup.writeAll()
5152

53+
opsdb.close()
54+
5255
outThumbs = glob.glob(os.path.join(self.outDir, 'thumb*'))
5356
outNpz = glob.glob(os.path.join(self.outDir, '*.npz'))
5457
outPdf = glob.glob(os.path.join(self.outDir, '*.pdf'))

tests/testOpsimDb.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import lsst.sims.maf.db as db
77
import lsst.sims.maf.utils.outputUtils as out
88
import lsst.utils.tests
9+
from lsst.utils import getPackageDir
910
from lsst.sims.utils.CodeUtilities import sims_clean_up
1011
from builtins import str
1112

@@ -18,8 +19,8 @@ def tearDownClass(cls):
1819
sims_clean_up()
1920

2021
def setUp(self):
21-
self.database = os.path.join(os.getenv('SIMS_MAF_DIR'), 'tests',
22-
'pontus_1150.db')
22+
self.database = os.path.join(getPackageDir('sims_data'), 'OpSimData',
23+
'astro-lsst-01_2014.db')
2324
self.oo = db.OpsimDatabaseV4(database=self.database)
2425

2526
def tearDown(self):
@@ -61,13 +62,13 @@ def testOpsimDbFields(self):
6162
def testOpsimDbRunLength(self):
6263
"""Test query for length of opsim run."""
6364
nrun = self.oo.fetchRunLength()
64-
self.assertEqual(nrun, 1.)
65+
self.assertEqual(nrun, 0.04)
6566

6667
def testOpsimDbSimName(self):
6768
"""Test query for opsim name."""
6869
simname = self.oo.fetchOpsimRunName()
6970
self.assertTrue(isinstance(simname, str))
70-
self.assertEqual(simname, 'pontus_1150')
71+
self.assertEqual(simname, 'astro-lsst-01_2014')
7172

7273
def testOpsimDbConfig(self):
7374
"""Test generation of config data. """

ups/sims_maf.table

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ setupRequired(palpy)
1111
setupRequired(healpy)
1212
# For basic sims utilities
1313
setupRequired(sims_utils)
14+
# For opsim database for unit test
15+
setupRequired(sims_data)
1416
# For access to the db classes
1517
setupRequired(sims_catalogs)
1618
# For magnitude and SNR calculations

0 commit comments

Comments
 (0)