Coverage for tests / test_legacy_config.py: 40%
23 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-01 08:19 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-01 08:19 +0000
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/>.
22import os
23import shutil
24import tempfile
25import unittest
27from lsst.dax.apdb.sql import ApdbSql
29TEST_SCHEMA = os.path.join(os.path.abspath(os.path.dirname(__file__)), "config/schema-apdb+sso.yaml")
32class LegacyConfigTestCase(unittest.TestCase):
33 """Test case for using old pex_config files with a new config system.
35 This test will be removed when we drop support for legacy configs.
36 """
38 def setUp(self) -> None:
39 self.tempdir = tempfile.mkdtemp()
40 self.db_url = f"sqlite:///{self.tempdir}/apdb.sqlite3"
42 def tearDown(self) -> None:
43 shutil.rmtree(self.tempdir, ignore_errors=True)
45 def test_lecagy_config(self) -> None:
46 """Create SQLite APDB instance open it using old pex_config file."""
47 new_config = ApdbSql.init_database(self.db_url, schema_file=TEST_SCHEMA)
49 # Generate old pex_config file, old config class existed at two
50 # different locations.
51 config_locations = ["lsst.dax.apdb.apdbSql", "lsst.dax.apdb.sql.apdbSql"]
52 for location in config_locations:
53 legacy_config_str = (
54 f"import {location}\n"
55 f'assert type(config) is {location}.ApdbSqlConfig, ""\n'
56 f'config.db_url="{new_config.db_url}"\n'
57 f'config.schema_file="{TEST_SCHEMA}"\n'
58 )
59 legacy_config_path = os.path.join(self.tempdir, "legacy_config.py")
60 with open(legacy_config_path, "w") as file:
61 file.write(legacy_config_str)
63 # Make APDB instance using legacy config.
64 warning_message = "APDB is instantiated using legacy pex_config format"
65 with self.assertWarnsRegex(FutureWarning, warning_message):
66 ApdbSql.from_uri(legacy_config_path)
69if __name__ == "__main__":
70 unittest.main()