Coverage for tests/test_posixStorage.py : 35%

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
# # LSST Data Management System # Copyright 2017 LSST Corporation. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. #
lsst.utils.tests.init()
"""A test case for getting the relative path to parent from a symlink in PosixStorage."""
self.testDir = tempfile.mkdtemp(dir=ROOT, prefix='GetParentFromSymlink-') self.parentFolderPath = os.path.join(self.testDir, "theParent") self.childFolderPath = os.path.join(self.testDir, "theChild") self.parentlessFolderPath = os.path.join(self.testDir, "parentlessRepo") for p in (self.parentFolderPath, self.childFolderPath, self.parentlessFolderPath): os.makedirs(p) relpath = os.path.relpath(self.parentFolderPath, self.childFolderPath) os.symlink(relpath, os.path.join(self.childFolderPath, '_parent'))
if os.path.exists(self.testDir): shutil.rmtree(self.testDir)
parentPath = dp.PosixStorage.getParentSymlinkPath(self.childFolderPath) self.assertEqual(parentPath, os.path.relpath(self.parentFolderPath, self.childFolderPath))
parentPath = dp.PosixStorage.getParentSymlinkPath(self.parentlessFolderPath) self.assertEqual(parentPath, None)
"""A test case for the PosixStorage.relativePath function."""
self.testDir = tempfile.mkdtemp(dir=ROOT, prefix='TestRelativePath-')
if os.path.exists(self.testDir): shutil.rmtree(self.testDir)
"""Test that a relative path returns the correct relative path for 1. relative inputs, 2. absolute inputs.""" abspathA = os.path.join(self.testDir, 'a') abspathB = os.path.join(self.testDir, 'b') os.makedirs(abspathA) os.makedirs(abspathB) # 1. relpathA = os.path.relpath(abspathA) relpathB = os.path.relpath(abspathB) relpathAtoB = dp.PosixStorage.relativePath(relpathA, relpathB) self.assertEqual('../b', relpathAtoB) # 2. relpathAtoB = dp.PosixStorage.relativePath(abspathA, abspathB) self.assertEqual('../b', relpathAtoB)
"""A test case for the PosixStorage.absolutePath function."""
self.testDir = tempfile.mkdtemp(dir=ROOT, prefix='TestAbsolutePath-')
if os.path.exists(self.testDir): shutil.rmtree(self.testDir)
"""Tests that given a path and a relative path, the correct aboslute path to the relative path is returned.""" abspathA = os.path.join(self.testDir, 'a') abspathB = os.path.join(self.testDir, 'b') os.makedirs(abspathA) os.makedirs(abspathB) relpathA = os.path.relpath(abspathA) self.assertEqual(abspathB, dp.PosixStorage.absolutePath(abspathA, '../b')) self.assertEqual(abspathB, dp.PosixStorage.absolutePath(relpathA, '../b'))
"""A test case for the PosixStorage.getLocalFile function."""
self.testDir = tempfile.mkdtemp(dir=ROOT, prefix='TestGetLocalFile-')
if os.path.exists(self.testDir): shutil.rmtree(self.testDir)
"""Tests that GetLocalFile returns a file when it exists and returns None when it does not exist.""" storage = dp.PosixStorage(self.testDir, create=True) self.assertIsNone(storage.getLocalFile('foo.txt')) with open(os.path.join(self.testDir, 'foo.txt'), 'w') as f: f.write('foobarbaz') del f f = storage.getLocalFile('foo.txt') self.assertIsInstance(f, FileType) self.assertEqual(f.read(), 'foobarbaz') f.close()
lsst.utils.tests.init() unittest.main() |