Skip to content

Commit

Permalink
Update packages tests to write pickle and yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jun 8, 2020
1 parent e88a515 commit 344c03d
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions tests/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,40 @@ def testRuntime(self):
"""
lsst.base.getRuntimeVersions()

def testPackages(self):
"""Test the Packages class"""
packages = lsst.base.Packages.fromSystem()

# Test pickling
def _writeTempFile(self, packages, suffix):
"""Write packages to a temp file using the supplied suffix and read
back.
"""
# Can't use lsst.utils.tests.getTempFilePath because we're its dependency
temp = tempfile.NamedTemporaryFile(prefix="packages.", suffix=".pickle", delete=False)
temp = tempfile.NamedTemporaryFile(prefix="packages.", suffix=suffix, delete=False)
tempName = temp.name
temp.close() # We don't use the fd, just want a filename
try:
packages.write(tempName)
new = lsst.base.Packages.read(tempName)
finally:
os.unlink(tempName)
return new

def testPackages(self):
"""Test the Packages class"""
packages = lsst.base.Packages.fromSystem()

# Test pickling and YAML
new = self._writeTempFile(packages, ".pickle")
new_yaml = self._writeTempFile(packages, ".yaml")

self.assertIsInstance(new, lsst.base.Packages)
self.assertIsInstance(new_yaml, lsst.base.Packages)
self.assertEqual(new, packages)
self.assertEqual(new, new_yaml)

with self.assertRaises(ValueError):
self._writeTempFile(packages, ".txt")

with self.assertRaises(ValueError):
# .txt extension is not recognized
lsst.base.Packages.read("something.txt")

# 'packages' and 'new' should have identical content
self.assertDictEqual(packages.difference(new), {})
Expand Down

0 comments on commit 344c03d

Please sign in to comment.