Coverage for tests/test_convertReferenceCatalog.py: 36%
42 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-25 00:24 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-25 00:24 -0700
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 outdir = tempfile.TemporaryDirectory()
48 outpath = outdir.name
49 args = ["convertReferenceCatalog",
50 outpath,
51 os.path.join(self.inpath, "mock_config.py"),
52 os.path.join(self.inpath, "*.fits")]
53 with unittest.mock.patch.object(convertReferenceCatalog.ConvertReferenceCatalogTask, "run") as run, \
54 unittest.mock.patch.object(sys, "argv", args):
55 convertReferenceCatalog.main()
56 # Test with sets because the glob can come out in any order.
57 self.assertEqual(set(run.call_args.args[0]), set(self.expected_files))
58 # This is necessary to avoid a ResourceWarning.
59 outdir.cleanup()
61 def test_main_args_bad_config(self):
62 """Test that a bad config file produces a useful error, i.e. that
63 main() validates the config.
64 """
65 outdir = tempfile.TemporaryDirectory()
66 outpath = outdir.name
67 args = ["convertReferenceCatalog",
68 outpath,
69 os.path.join(self.inpath, "bad_config.py"),
70 os.path.join(self.inpath, "*.fits")]
71 with self.assertRaisesRegex(FieldValidationError, "Field 'ra_name' failed validation"), \
72 unittest.mock.patch.object(sys, "argv", args):
73 convertReferenceCatalog.main()
74 # This is necessary to avoid a ResourceWarning.
75 outdir.cleanup()
77 def test_main_args_expanded_glob(self):
78 """Test that an un-quoted glob (i.e. list of files) fails with a
79 useful error.
80 """
81 outdir = tempfile.TemporaryDirectory()
82 outpath = outdir.name
83 args = ["convertReferenceCatalog",
84 outpath,
85 os.path.join(self.inpath, "mock_config.py"),
86 # an un-quoted glob will be shell-expanded to a list of files.
87 "file1", "file2", "file3"]
88 msg = "Final argument must be a quoted file glob, not a shell-expanded list of files."
89 with self.assertRaisesRegex(RuntimeError, msg), \
90 unittest.mock.patch.object(sys, "argv", args):
91 convertReferenceCatalog.main()
92 # This is necessary to avoid a ResourceWarning.
93 outdir.cleanup()
96class TestMemory(lsst.utils.tests.MemoryTestCase):
97 pass
100def setup_module(module):
101 lsst.utils.tests.init()
104if __name__ == "__main__": 104 ↛ 105line 104 didn't jump to line 105, because the condition on line 104 was never true
105 lsst.utils.tests.init()
106 unittest.main()