Coverage for tests/test_registry.py: 52%
25 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-07 09:51 +0000
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-07 09:51 +0000
1#
2# LSST Data Management System
3# Copyright 2015 LSST Corporation.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
23import collections
24import unittest
25import os
26import lsst.utils.tests
28import lsst.daf.persistence as dafPersist
30# Define the root of the tests relative to this file
31ROOT = os.path.abspath(os.path.dirname(__file__))
34class PosixRegistryTestCase(unittest.TestCase):
36 def test1(self):
37 """Basic test case to verify parameter extraction from template + filename.
39 :return:
40 """
41 testData = collections.namedtuple('testData', 'root template returnFields dataId expectedLookup')
42 td = (
43 testData(os.path.join(ROOT, 'posixRegistry/repo01'),
44 'foo-%(ccd)02d.fits',
45 ('ccd',),
46 {},
47 [(1,)]),
48 testData(os.path.join(ROOT, 'posixRegistry/repo02'),
49 'foo-%(ccd)02d-%(filter)s.fits',
50 ('ccd', 'filter'),
51 {},
52 [(1, 'g'), (1, 'h'), (2, 'g'), (2, 'h'), (3, 'i'), ]),
53 testData(os.path.join(ROOT, 'posixRegistry/repo02'),
54 'foo-%(ccd)02d-%(filter)s.fits',
55 # intentionally no comma on 'filter'; it becomes a string not a tuple. This is handled,
56 # and here is where it is tested.
57 ('filter'),
58 {'ccd': 1},
59 [('g',), ('h',), ]),
60 testData(os.path.join(ROOT, 'posixRegistry/repo02'),
61 'foo-%(ccd)02d-%(filter)s.fits',
62 ('ccd',),
63 {'filter': 'i'},
64 [(3,), ]),
65 )
67 policyTables = None
68 storage = 'FitsStorage'
69 for root, template, returnFields, dataId, expectedLookup in td:
70 registry = dafPersist.PosixRegistry(root)
71 lookups = registry.lookup(returnFields, policyTables, dataId, template=template, storage=storage)
72 lookups.sort()
73 expectedLookup.sort()
74 self.assertEqual(lookups, expectedLookup)
77class TestMemory(lsst.utils.tests.MemoryTestCase):
78 pass
81def setup_module(module):
82 lsst.utils.tests.init()
85if __name__ == "__main__": 85 ↛ 86line 85 didn't jump to line 86, because the condition on line 85 was never true
86 lsst.utils.tests.init()
87 unittest.main()