Coverage for tests/test_convertReferenceCatalog.py : 47%

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 meas_algorithms.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://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 <https://www.gnu.org/licenses/>.
22import os.path
23import sys
24import unittest
25import unittest.mock
26import tempfile
28from lsst.pex.config import FieldValidationError
29from lsst.meas.algorithms import convertReferenceCatalog
30import lsst.utils
33class TestMain(lsst.utils.tests.TestCase):
34 """Test mocking commandline arguments and calling
35 ``convertReferenceCatalog.main()``.
36 """
37 def setUp(self):
38 self.inpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data/mockrefcat/")
39 self.expected_files = [os.path.join(self.inpath, "123.fits"),
40 os.path.join(self.inpath, "124.fits"),
41 os.path.join(self.inpath, "125.fits")]
43 def test_main_args(self):
44 """Test that main configures the task and calls run() with the correct
45 file list.
46 """
47 outpath = tempfile.mkdtemp()
48 args = ["convertReferenceCatalog",
49 outpath,
50 os.path.join(self.inpath, "mock_config.py"),
51 os.path.join(self.inpath, "*.fits")]
52 with unittest.mock.patch.object(convertReferenceCatalog.ConvertReferenceCatalogTask, "run") as run, \
53 unittest.mock.patch.object(sys, "argv", args):
54 convertReferenceCatalog.main()
55 # Test with sets because the glob can come out in any order.
56 self.assertEqual(set(run.call_args.args[0]), set(self.expected_files))
58 def test_main_args_bad_config(self):
59 """Test that a bad config file produces a useful error, i.e. that
60 main() validates the config.
61 """
62 outpath = tempfile.mkdtemp()
63 args = ["convertReferenceCatalog",
64 outpath,
65 os.path.join(self.inpath, "bad_config.py"),
66 os.path.join(self.inpath, "*.fits")]
67 with self.assertRaisesRegex(FieldValidationError, "Field 'ra_name' failed validation"), \
68 unittest.mock.patch.object(sys, "argv", args):
69 convertReferenceCatalog.main()
71 def test_main_args_expanded_glob(self):
72 """Test that an un-quoted glob (i.e. list of files) fails with a
73 useful error.
74 """
75 outpath = tempfile.mkdtemp()
76 args = ["convertReferenceCatalog",
77 outpath,
78 os.path.join(self.inpath, "mock_config.py"),
79 # an un-quoted glob will be shell-expanded to a list of files.
80 "file1", "file2", "file3"]
81 msg = "Final argument must be a quoted file glob, not a shell-expanded list of files."
82 with self.assertRaisesRegex(RuntimeError, msg), \
83 unittest.mock.patch.object(sys, "argv", args):
84 convertReferenceCatalog.main()
87class TestMemory(lsst.utils.tests.MemoryTestCase):
88 pass
91def setup_module(module):
92 lsst.utils.tests.init()
95if __name__ == "__main__": 95 ↛ 96line 95 didn't jump to line 96, because the condition on line 95 was never true
96 lsst.utils.tests.init()
97 unittest.main()