Coverage for tests/test_connectionString.py : 46%

Hot-keys 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 unittest
26import os
27import os.path
29from lsst.daf.butler.registry import RegistryConfig
30import lsst.daf.butler.registry.connectionString as ConnectionStringModule
31from lsst.daf.butler.registry.connectionString import ConnectionStringFactory
33TESTDIR = os.path.abspath(os.path.dirname(__file__))
36class ConnectionStringBuilderTestCase(unittest.TestCase):
37 """Tests for ConnectionStringBuilder."""
38 configDir = os.path.join(TESTDIR, "config/basic/connectionStringConfs/")
39 configFiles = os.listdir(configDir)
40 credentialsFile = os.path.join(TESTDIR, "testDbAuth.yaml")
42 def setUp(self):
43 self.resetDbAuthPathValue = ConnectionStringModule.DB_AUTH_PATH
44 ConnectionStringModule.DB_AUTH_PATH = self.credentialsFile
45 os.chmod(self.credentialsFile, 0o600)
47 def tearDown(self):
48 ConnectionStringModule.DB_AUTH_PATH = self.resetDbAuthPathValue
50 def testBuilder(self):
51 """Tests ConnectionStringBuilder builds correct connection strings.
52 """
53 regConfigs = [RegistryConfig(os.path.join(self.configDir, name)) for name in self.configFiles]
55 conStrFactory = ConnectionStringFactory()
56 for regConf, fileName in zip(regConfigs, self.configFiles):
57 conStr = conStrFactory.fromConfig(regConf)
58 with self.subTest(confFile=fileName):
59 self.assertEqual(str(conStr), regConf['expected'],
60 "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, 'conf1.yaml'))
65 regConf['db'] = 'sqlite:///relative/path/conf1.sqlite3'
67 conStrFactory = ConnectionStringFactory()
68 conStr = conStrFactory.fromConfig(regConf)
69 self.assertEqual(str(conStr), 'sqlite:///relative/path/conf1.sqlite3')
72if __name__ == "__main__": 72 ↛ 73line 72 didn't jump to line 73, because the condition on line 72 was never true
73 unittest.main()