-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite Location and LocationFactory to be more correct
Previously we were a bit loose with our definition of URI. This rewrite changes the API to Location such that it now takes a URI ParseResult as the root of the datastore and a relative path reflecting the position in the datastore. This means that we no longer have to deal with strange relative path URIs that are non-standard for files. This change removes fromUri from the LocationFactory API since it makes no sense to define a root URI for the datastore and then allow another URI to be provided. No butler code called fromUri. It also changes the Location constructor but only LocationFactory was calling it. There are some shenanigans with trying to deal with the difference between a posixpath and an os.path but given that I am testing this on a posix system there might be some inconsistencies still. Tests have been added.
- Loading branch information
Showing
2 changed files
with
242 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# This file is part of daf_butler. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (http://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# 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 GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import unittest | ||
import os.path | ||
import posixpath | ||
|
||
from lsst.daf.butler import LocationFactory | ||
|
||
|
||
class LocationTestCase(unittest.TestCase): | ||
"""Tests for Location within datastore | ||
""" | ||
|
||
def testFileLocation(self): | ||
root = os.path.abspath(os.path.curdir) | ||
factory = LocationFactory(root) | ||
print(f"Factory created: {factory}") | ||
|
||
pathInStore = "relative/path/file.ext" | ||
loc1 = factory.fromPath(pathInStore) | ||
|
||
self.assertEqual(loc1.path, os.path.join(root, pathInStore)) | ||
self.assertEqual(loc1.pathInStore, pathInStore) | ||
self.assertTrue(loc1.uri.startswith("file:///")) | ||
self.assertTrue(loc1.uri.endswith("file.ext")) | ||
loc1.updateExtension("fits") | ||
self.assertTrue(loc1.uri.endswith("file.fits")) | ||
loc1.updateExtension(None) | ||
self.assertTrue(loc1.uri.endswith("file.fits")) | ||
loc1.updateExtension("") | ||
self.assertTrue(loc1.uri.endswith("file")) | ||
|
||
def testHttpLocation(self): | ||
root = "https://www.lsst.org/butler/datastore" | ||
factory = LocationFactory(root) | ||
print(f"Factory created: {factory}") | ||
|
||
pathInStore = "relative/path/file.ext" | ||
loc1 = factory.fromPath(pathInStore) | ||
|
||
self.assertEqual(loc1.path, posixpath.join("/butler/datastore", pathInStore)) | ||
self.assertEqual(loc1.pathInStore, pathInStore) | ||
self.assertTrue(loc1.uri.startswith("https://")) | ||
self.assertTrue(loc1.uri.endswith("file.ext")) | ||
loc1.updateExtension("fits") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |