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#!/usr/bin/env python 

2# 

3# LSST Data Management System 

4# Copyright 2016 AURA/LSST. 

5# 

6# This product includes software developed by the 

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

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 LSST License Statement and 

20# the GNU General Public License along with this program. If not, 

21# see <https://www.lsstcorp.org/LegalNotices/>. 

22# 

23import os 

24import unittest 

25import tempfile 

26 

27import lsst.base 

28 

29 

30class PackagesTestCase(unittest.TestCase): 

31 """Tests for package version collection 

32 

33 Unfortunately, we're somewhat limited in what we can test because 

34 we only get the versions of things being used at runtime, and this 

35 package sits rather low in the dependency chain so there's not 

36 usually a lot of other packages available when this test gets run. 

37 Therefore some of the tests are only checking that things don't 

38 explode, since they are incapable of testing much more than that. 

39 """ 

40 

41 def testPython(self): 

42 """Test that we get the right version for this python package""" 

43 versions = lsst.base.getPythonPackages() 

44 expected = (lsst.base.version.__version__) 

45 self.assertEqual(versions["base"], expected) 

46 

47 def testEnvironment(self): 

48 """Test getting versions from the environment 

49 

50 Unfortunately, none of the products that need their versions divined from the 

51 environment are dependencies of this package, and so all we can do is test 

52 that this doesn't fall over. 

53 """ 

54 lsst.base.getEnvironmentPackages() 

55 

56 def testRuntime(self): 

57 """Test getting versions from runtime libraries 

58 

59 Unfortunately, none of the products that we get runtime versions from are 

60 dependencies of this package, and so all we can do is test that this doesn't 

61 fall over. 

62 """ 

63 lsst.base.getRuntimeVersions() 

64 

65 def testPackages(self): 

66 """Test the Packages class""" 

67 packages = lsst.base.Packages.fromSystem() 

68 

69 # Test pickling 

70 # Can't use lsst.utils.tests.getTempFilePath because we're its dependency 

71 temp = tempfile.NamedTemporaryFile(prefix="packages.", suffix=".pickle", delete=False) 

72 tempName = temp.name 

73 temp.close() # We don't use the fd, just want a filename 

74 try: 

75 packages.write(tempName) 

76 new = lsst.base.Packages.read(tempName) 

77 finally: 

78 os.unlink(tempName) 

79 

80 # 'packages' and 'new' should have identical content 

81 self.assertDictEqual(packages.difference(new), {}) 

82 self.assertDictEqual(packages.missing(new), {}) 

83 self.assertDictEqual(packages.extra(new), {}) 

84 self.assertEqual(len(packages), len(new)) 

85 

86 # Check inverted comparisons 

87 self.assertDictEqual(new.difference(packages), {}) 

88 self.assertDictEqual(new.missing(packages), {}) 

89 self.assertDictEqual(new.extra(packages), {}) 

90 

91 # Now load an obscure python package and the list of packages should change 

92 import smtpd # noqa Shouldn't be used by anything we've previously imported 

93 new = lsst.base.Packages.fromSystem() 

94 self.assertDictEqual(packages.difference(new), {}) # No inconsistencies 

95 self.assertDictEqual(packages.extra(new), {}) # Nothing in 'packages' that's not in 'new' 

96 missing = packages.missing(new) 

97 self.assertGreater(len(missing), 0) # 'packages' should be missing some stuff in 'new' 

98 self.assertIn("smtpd", missing) 

99 

100 # Inverted comparisons 

101 self.assertDictEqual(new.difference(packages), {}) 

102 self.assertDictEqual(new.missing(packages), {}) # Nothing in 'new' that's not in 'packages' 

103 extra = new.extra(packages) 

104 self.assertGreater(len(extra), 0) # 'new' has extra stuff compared to 'packages' 

105 self.assertIn("smtpd", extra) 

106 

107 packages.update(new) # Should now be identical 

108 self.assertDictEqual(packages.difference(new), {}) 

109 self.assertDictEqual(packages.missing(new), {}) 

110 self.assertDictEqual(packages.extra(new), {}) 

111 self.assertEqual(len(packages), len(new)) 

112 

113 

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

115 unittest.main()