Coverage for tests/test_connectionString.py: 46%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of daf_butler.
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"""Tests for ConnectionStringBuilder.
23"""
25import glob
26import os
27import os.path
28import unittest
30import lsst.daf.butler.registry.connectionString as ConnectionStringModule
31from lsst.daf.butler.registry import DbAuthError, RegistryConfig
32from lsst.daf.butler.registry.connectionString import ConnectionStringFactory
34TESTDIR = os.path.abspath(os.path.dirname(__file__))
37class ConnectionStringBuilderTestCase(unittest.TestCase):
38 """Tests for ConnectionStringBuilder."""
40 configDir = os.path.join(TESTDIR, "config", "dbAuth")
41 configFiles = glob.glob(os.path.join(configDir, "registryConf*"))
42 credentialsFile = os.path.join(configDir, "db-auth.yaml")
44 def setUp(self):
45 self.resetDbAuthPathValue = ConnectionStringModule.DB_AUTH_PATH
46 ConnectionStringModule.DB_AUTH_PATH = self.credentialsFile
47 os.chmod(self.credentialsFile, 0o600)
49 def tearDown(self):
50 ConnectionStringModule.DB_AUTH_PATH = self.resetDbAuthPathValue
52 def testBuilder(self):
53 """Tests ConnectionStringFactory returns correct connection strings."""
54 regConfigs = [RegistryConfig(os.path.join(self.configDir, name)) for name in self.configFiles]
56 conStrFactory = ConnectionStringFactory()
57 for regConf, fileName in zip(regConfigs, self.configFiles):
58 conStr = conStrFactory.fromConfig(regConf)
59 with self.subTest(confFile=fileName):
60 self.assertEqual(str(conStr), regConf["expected"], "test connection string built from config")
62 def testRelVsAbsPath(self):
63 """Tests that relative and absolute paths are preserved."""
64 regConf = RegistryConfig(os.path.join(self.configDir, "registryConf1.yaml"))
65 regConf["db"] = "sqlite:///relative/path/conf1.sqlite3"
66 conStrFactory = ConnectionStringFactory()
67 conStr = conStrFactory.fromConfig(regConf)
68 self.assertEqual(str(conStr), "sqlite:///relative/path/conf1.sqlite3")
70 def testRaises(self):
71 """Test that DbAuthError propagates through the class."""
72 ConnectionStringModule.DB_AUTH_PATH = os.path.join(self.configDir, "badDbAuth2.yaml")
73 regConf = RegistryConfig(os.path.join(self.configDir, "registryConf2.yaml"))
74 conStrFactory = ConnectionStringFactory()
75 with self.assertRaises(DbAuthError):
76 conStrFactory.fromConfig(regConf)
79if __name__ == "__main__": 79 ↛ 80line 79 didn't jump to line 80, because the condition on line 79 was never true
80 unittest.main()