Coverage for tests/test_import.py: 32%

28 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-18 09:19 +0000

1# This file is part of pipe_tasks. 

2# 

3# LSST Data Management System 

4# This product includes software developed by the 

5# LSST Project (http://www.lsst.org/). 

6# See COPYRIGHT file at the top of the source tree. 

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 <https://www.lsstcorp.org/LegalNotices/>. 

21 

22import importlib.resources 

23import os.path 

24import unittest 

25 

26from lsst.utils import doImport 

27 

28 

29class ImportTestCase(unittest.TestCase): 

30 """Test that every file can be imported. 

31 

32 pipe_tasks does not import all the task code by default and not 

33 every file currently has a test. 

34 """ 

35 

36 def test_import(self): 

37 self.assertImport("lsst.pipe.tasks") 

38 

39 def test_import_script(self): 

40 self.assertImport("lsst.pipe.tasks.script") 

41 

42 def test_import_dataFrameActions(self): 

43 self.assertImport("lsst.pipe.tasks.dataFrameActions") 

44 

45 def test_import_configurableActions(self): 

46 self.assertImport("lsst.pipe.tasks.configurableActions") 

47 

48 def assertImport(self, root_pkg): 

49 for file in importlib.resources.contents(root_pkg): 

50 if not file.endswith(".py"): 

51 continue 

52 if file.startswith("__"): 

53 continue 

54 root, ext = os.path.splitext(file) 

55 module_name = f"{root_pkg}.{root}" 

56 with self.subTest(module=module_name): 

57 try: 

58 doImport(module_name) 

59 except ImportError as e: 

60 raise AssertionError(f"Error importing module {module_name}: {e}") from e 

61 

62 

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

64 unittest.main()