Hide keyboard shortcuts

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/>. 

19 

20import unittest 

21import inspect 

22 

23import lsst.utils.tests 

24 

25from lsst.utils import doImport 

26 

27 

28class ImportTestCase(lsst.utils.tests.TestCase): 

29 """Basic tests of doImport.""" 

30 

31 def testDoImport(self): 

32 c = doImport("lsst.utils.tests.TestCase") 

33 self.assertEqual(c, lsst.utils.tests.TestCase) 

34 

35 c = doImport("lsst.utils.doImport") 

36 self.assertEqual(type(c), type(doImport)) 

37 self.assertTrue(inspect.isfunction(c)) 

38 

39 c = doImport("lsst.utils") 

40 self.assertTrue(inspect.ismodule(c)) 

41 

42 with self.assertRaises(ImportError): 

43 doImport("lsst.utils.tests.TestCase.xyprint") 

44 

45 with self.assertRaises(ImportError): 

46 doImport("lsst.utils.nothere") 

47 

48 with self.assertRaises(ModuleNotFoundError): 

49 doImport("missing module") 

50 

51 with self.assertRaises(ModuleNotFoundError): 

52 doImport("lsstdummy.import.fail") 

53 

54 with self.assertRaises(ImportError): 

55 doImport("lsst.import.fail") 

56 

57 with self.assertRaises(ImportError): 

58 doImport("lsst.utils.x") 

59 

60 with self.assertRaises(TypeError): 

61 doImport([]) 

62 

63 

64if __name__ == "__main__": 64 ↛ 65line 64 didn't jump to line 65, because the condition on line 64 was never true

65 unittest.main()