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# 

2# This file is part of ap_verify. 

3# 

4# Developed for the LSST Data Management System. 

5# This product includes software developed by the LSST Project 

6# (http://www.lsst.org). 

7# See the COPYRIGHT file at the top-level directory of this distribution 

8# for details of code ownership. 

9# 

10# This program is free software: you can redistribute it and/or modify 

11# it under the terms of the GNU General Public License as published by 

12# the Free Software Foundation, either version 3 of the License, or 

13# (at your option) any later version. 

14# 

15# This program is distributed in the hope that it will be useful, 

16# but WITHOUT ANY WARRANTY; without even the implied warranty of 

17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

18# GNU General Public License for more details. 

19# 

20# You should have received a copy of the GNU General Public License 

21# along with this program. If not, see <http://www.gnu.org/licenses/>. 

22# 

23 

24import os 

25import shutil 

26import tempfile 

27import unittest 

28from urllib.request import url2pathname 

29 

30import lsst.utils.tests 

31from lsst.ap.verify.workspace import Workspace 

32 

33 

34class WorkspaceTestSuite(lsst.utils.tests.TestCase): 

35 

36 def setUp(self): 

37 self._testWorkspace = tempfile.mkdtemp() 

38 self._testbed = Workspace(self._testWorkspace) 

39 

40 def tearDown(self): 

41 shutil.rmtree(self._testWorkspace, ignore_errors=True) 

42 

43 def _assertInDir(self, path, baseDir): 

44 """Test that ``path`` is a subpath of ``baseDir``. 

45 """ 

46 _canonPath = os.path.abspath(os.path.realpath(path)) 

47 _canonDir = os.path.abspath(os.path.realpath(baseDir)) 

48 ancestor = os.path.commonprefix([_canonPath, _canonDir]) 

49 self.assertEqual(ancestor, _canonDir) 

50 

51 def _assertNotInDir(self, path, baseDir): 

52 """Test that ``path`` is not a subpath of ``baseDir``. 

53 """ 

54 _canonPath = os.path.abspath(os.path.realpath(path)) 

55 _canonDir = os.path.abspath(os.path.realpath(baseDir)) 

56 ancestor = os.path.commonprefix([_canonPath, _canonDir]) 

57 self.assertNotEqual(ancestor, _canonDir) 

58 

59 def testMakeDir(self): 

60 """Verify that a Workspace creates the workspace directory if it does not exist. 

61 """ 

62 newPath = '_temp' 

63 shutil.rmtree(newPath, ignore_errors=True) 

64 self.assertFalse(os.path.exists(newPath), 'Workspace directory must not exist before test.') 

65 

66 try: 

67 Workspace(newPath) 

68 self.assertTrue(os.path.exists(newPath), 'Workspace directory must exist.') 

69 finally: 

70 shutil.rmtree(newPath, ignore_errors=True) 

71 

72 @staticmethod 

73 def _allRepos(workspace): 

74 """An iterator over all repos exposed by a Workspace. 

75 """ 

76 yield workspace.dataRepo 

77 yield workspace.calibRepo 

78 yield workspace.templateRepo 

79 yield workspace.outputRepo 

80 

81 def testDirectories(self): 

82 """Verify that a Workspace creates repositories in the target directory. 

83 

84 The exact repository locations are not tested, as they are likely to change. 

85 """ 

86 # Workspace should report all paths as absolute 

87 root = os.path.abspath(os.path.realpath(self._testWorkspace)) 

88 self.assertEqual(self._testbed.workDir, root) 

89 self._assertInDir(self._testbed.configDir, root) 

90 for repo in WorkspaceTestSuite._allRepos(self._testbed): 

91 # Workspace spec allows these to be URIs or paths, whatever the Butler accepts 

92 self._assertInDir(url2pathname(repo), root) 

93 

94 def testDatabase(self): 

95 """Verify that a Workspace requests a database file in the target 

96 directory, but not in any repository. 

97 """ 

98 root = self._testWorkspace 

99 self._assertInDir(self._testbed.dbLocation, root) 

100 for repo in WorkspaceTestSuite._allRepos(self._testbed): 

101 # Workspace spec allows these to be URIs or paths, whatever the Butler accepts 

102 self._assertNotInDir(self._testbed.dbLocation, url2pathname(repo)) 

103 

104 

105class MemoryTester(lsst.utils.tests.MemoryTestCase): 

106 pass 

107 

108 

109def setup_module(module): 

110 lsst.utils.tests.init() 

111 

112 

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

114 lsst.utils.tests.init() 

115 unittest.main()