Coverage for tests/test_cli.py: 57%
21 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-27 03:01 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-27 03:01 -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 apdb-cli commands."""
24import os
25import shutil
26import tempfile
27import unittest
29from lsst.dax.apdb import Apdb
30from lsst.dax.apdb.cli import apdb_cli
32TEST_SCHEMA = os.path.join(os.path.abspath(os.path.dirname(__file__)), "config/schema.yaml")
35class CreateSqlTestCase(unittest.TestCase):
36 """A test case for apdb-cli create-sql command."""
38 def setUp(self) -> None:
39 self.tempdir = tempfile.mkdtemp()
40 self.db_url = f"sqlite:///{self.tempdir}/apdb.sqlite3"
41 self.config_path = f"{self.tempdir}/apdb-sql.py"
43 def tearDown(self) -> None:
44 shutil.rmtree(self.tempdir, ignore_errors=True)
46 def test_create_sql(self) -> None:
47 """Create SQLite APDB instance and config file for it."""
48 args = ["create-sql", "--schema-file", TEST_SCHEMA, self.db_url, self.config_path]
49 apdb_cli.main(args)
50 self.assertTrue(os.path.exists(f"{self.tempdir}/apdb.sqlite3"))
51 self.assertTrue(os.path.exists(self.config_path))
53 # Make Apdb instance from this new config.
54 Apdb.from_uri(self.config_path)
57if __name__ == "__main__":
58 unittest.main()