Coverage for tests/test_apdbSqlSchema.py: 36%
52 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-14 02:46 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-14 02:46 -0700
1# This file is part of dax_apdb.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22"""Unit test for ApdbSqlSchema class.
23"""
25import os
26import unittest
28from lsst.dax.apdb.apdbSqlSchema import ApdbSqlSchema
29import lsst.utils.tests
30from sqlalchemy import create_engine
32TEST_SCHEMA = os.path.join(os.path.abspath(os.path.dirname(__file__)), "config/schema.yaml")
35class ApdbSchemaTestCase(unittest.TestCase):
36 """A test case for ApdbSqlSchema class
37 """
39 @classmethod
40 def setUpClass(cls):
41 pass
43 def _assertTable(self, table, name, ncol):
44 """validation for tables schema.
46 Parameters
47 ----------
48 table : `sqlalchemy.Table`
49 name : `str`
50 Expected table name
51 ncol : `int`
52 Expected number of columns
53 """
54 self.assertIsNotNone(table)
55 self.assertEqual(table.name, name)
56 self.assertEqual(len(table.columns), ncol)
58 def test_makeSchema(self):
59 """Test for creating schemas.
61 Schema is defined in YAML files, some checks here depend on that
62 configuration and will need to be updated when configuration changes.
63 """
64 engine = create_engine('sqlite://')
66 # create standard (baseline) schema
67 schema = ApdbSqlSchema(engine=engine,
68 dia_object_index="baseline",
69 htm_index_column="pixelId",
70 schema_file=TEST_SCHEMA)
71 schema.makeSchema()
72 self._assertTable(schema.objects, "DiaObject", 8)
73 self.assertEqual(len(schema.objects.primary_key), 2)
74 self.assertIsNone(schema.objects_last)
75 self._assertTable(schema.sources, "DiaSource", 10)
76 self._assertTable(schema.forcedSources, "DiaForcedSource", 4)
78 # create schema using prefix
79 schema = ApdbSqlSchema(engine=engine,
80 dia_object_index="baseline",
81 htm_index_column="pixelId",
82 schema_file=TEST_SCHEMA,
83 prefix="Pfx")
84 # Drop existing tables (but we don't check it here)
85 schema.makeSchema(drop=True)
86 self._assertTable(schema.objects, "PfxDiaObject", 8)
87 self.assertIsNone(schema.objects_last)
88 self._assertTable(schema.sources, "PfxDiaSource", 10)
89 self._assertTable(schema.forcedSources, "PfxDiaForcedSource", 4)
91 # use different indexing for DiaObject, need extra schema for that
92 schema = ApdbSqlSchema(engine=engine,
93 dia_object_index="pix_id_iov",
94 htm_index_column="pixelId",
95 schema_file=TEST_SCHEMA)
96 schema.makeSchema(drop=True)
97 self._assertTable(schema.objects, "DiaObject", 8)
98 self.assertEqual(len(schema.objects.primary_key), 3)
99 self.assertIsNone(schema.objects_last)
100 self._assertTable(schema.sources, "DiaSource", 10)
101 self._assertTable(schema.forcedSources, "DiaForcedSource", 4)
103 # use DiaObjectLast table for DiaObject
104 schema = ApdbSqlSchema(engine=engine,
105 dia_object_index="last_object_table",
106 htm_index_column="pixelId",
107 schema_file=TEST_SCHEMA)
108 schema.makeSchema(drop=True)
109 self._assertTable(schema.objects, "DiaObject", 8)
110 self.assertEqual(len(schema.objects.primary_key), 2)
111 self._assertTable(schema.objects_last, "DiaObjectLast", 6)
112 self.assertEqual(len(schema.objects_last.primary_key), 2)
113 self._assertTable(schema.sources, "DiaSource", 10)
114 self._assertTable(schema.forcedSources, "DiaForcedSource", 4)
117class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
118 pass
121def setup_module(module):
122 lsst.utils.tests.init()
125if __name__ == "__main__": 125 ↛ 126line 125 didn't jump to line 126, because the condition on line 125 was never true
126 lsst.utils.tests.init()
127 unittest.main()