Coverage for tests/test_doImport.py : 16%

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# Developed for the LSST Data Management System.
2# This product includes software developed by the LSST Project
3# (http://www.lsst.org).
4# See the COPYRIGHT file at the top-level directory of this distribution
5# for details of code ownership.
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
20import unittest
21import inspect
23import lsst.utils.tests
25from lsst.utils import doImport
28class ImportTestCase(lsst.utils.tests.TestCase):
29 """Basic tests of doImport."""
31 def testDoImport(self):
32 c = doImport("lsst.utils.tests.TestCase")
33 self.assertEqual(c, lsst.utils.tests.TestCase)
35 c = doImport("lsst.utils.tests.TestCase.assertFloatsAlmostEqual")
36 self.assertEqual(c, lsst.utils.tests.TestCase.assertFloatsAlmostEqual)
38 c = doImport("lsst.utils.doImport")
39 self.assertEqual(type(c), type(doImport))
40 self.assertTrue(inspect.isfunction(c))
42 c = doImport("lsst.utils")
43 self.assertTrue(inspect.ismodule(c))
45 with self.assertRaises(ImportError):
46 doImport("lsst.utils.tests.TestCase.xyprint")
48 with self.assertRaises(ImportError):
49 doImport("lsst.utils.nothere")
51 with self.assertRaises(ModuleNotFoundError):
52 doImport("missing module")
54 with self.assertRaises(ModuleNotFoundError):
55 doImport("lsstdummy.import.fail")
57 with self.assertRaises(ImportError):
58 doImport("lsst.import.fail")
60 with self.assertRaises(ImportError):
61 doImport("lsst.utils.x")
63 with self.assertRaises(TypeError):
64 doImport([])
66 # Use a special test module
67 with self.assertRaises(RuntimeError):
68 doImport("import_test.two.three.runtime")
70 with self.assertRaises(ImportError):
71 doImport("import_test.two.three.success.not_okay")
73 with self.assertRaises(ImportError):
74 doImport("import_test.two.three.fail")
76 # Check that the error message reports the notthere failure
77 try:
78 doImport("import_test.two.three.fail.myfunc")
79 except ImportError as e:
80 self.assertIn("notthere", str(e))
82 c = doImport("import_test.two.three.success")
83 self.assertTrue(c.okay())
84 c = doImport("import_test.two.three.success.okay")
85 self.assertTrue(c())
86 c = doImport("import_test.two.three.success.Container")
87 self.assertEqual(c.inside(), "1")
88 c = doImport("import_test.two.three.success.Container.inside")
89 self.assertEqual(c(), "1")
92if __name__ == "__main__": 92 ↛ 93line 92 didn't jump to line 93, because the condition on line 92 was never true
93 unittest.main()