def testSplit(self): """Tests split functionality.""" testRoot = "/tmp/" testPaths = ("/absolute/file.ext", "/absolute/", "file:///absolute/file.ext", "file:///absolute/", "s3://bucket/root/file.ext", "s3://bucket/root/", "https://www.lsst.org/root/file.ext", "https://www.lsst.org/root/", "relative/file.ext", "relative/") osRelExpected = os.path.join(testRoot, "relative") expected = (("file:///absolute/", "file.ext"), ("file:///absolute/", ""), ("file:///absolute/", "file.ext"), ("file:///absolute/", ""), ("s3://bucket/root/", "file.ext"), ("s3://bucket/root/", ""), ("https://www.lsst.org/root/", "file.ext"), ("https://www.lsst.org/root/", ""), (f"file://{osRelExpected}/", "file.ext"), (f"file://{osRelExpected}/", "")) for p, e in zip(testPaths, expected): with self.subTest(path=p): uri = ButlerURI(p, testRoot) head, tail = uri.split() self.assertEqual((head.geturl(), tail), e) # explicit file scheme should force posixpath, check os.path is ignored posixRelFilePath = posixpath.join(testRoot, "relative") uri = ButlerURI("file:relative/file.ext", testRoot) head, tail = uri.split() self.assertEqual((head.geturl(), tail), (f"file://{posixRelFilePath}/", "file.ext")) # check head can be empty and we do not get an absolute path back uri = ButlerURI("file.ext", forceAbsolute=False) head, tail = uri.split() self.assertEqual((head.geturl(), tail), ("./", "file.ext")) # ensure empty path splits to a directory URL uri = ButlerURI("", forceAbsolute=False) head, tail = uri.split() self.assertEqual((head.geturl(), tail), ("./", "")) uri = ButlerURI(".", forceAbsolute=False) head, tail = uri.split() self.assertEqual((head.geturl(), tail), ("./", ""))
def testSplit(self): """Tests split functionality.""" testRoot = "/tmp/" testPaths = ("/absolute/file.ext", "/absolute/", "file:///absolute/file.ext", "file:///absolute/", "s3://bucket/root/file.ext", "s3://bucket/root/", "relative/file.ext", "relative/") osRelExpected = os.path.join(testRoot, "relative") expected = (("file:///absolute/", "file.ext"), ("file:///absolute/", ""), ("file:///absolute/", "file.ext"), ("file:///absolute/", ""), ("s3://bucket/root/", "file.ext"), ("s3://bucket/root/", ""), (f"file://{osRelExpected}/", "file.ext"), (f"file://{osRelExpected}/", "")) for p, e in zip(testPaths, expected): with self.subTest(path=p): uri = ButlerURI(p, testRoot) head, tail = uri.split() self.assertEqual((head.geturl(), tail), e) # explicit file scheme should force posixpath, check os.path is ignored posixRelFilePath = posixpath.join(testRoot, "relative") uri = ButlerURI("file:relative/file.ext", testRoot) head, tail = uri.split() self.assertEqual((head.geturl(), tail), (f"file://{posixRelFilePath}/", "file.ext")) # check head can be empty curDir = os.path.abspath(os.path.curdir) + os.sep uri = ButlerURI("file.ext", forceAbsolute=False) head, tail = uri.split() self.assertEqual((head.geturl(), tail), (curDir, "file.ext")) # ensure empty path is not a problem and conforms to os.path.split uri = ButlerURI("", forceAbsolute=False) head, tail = uri.split() self.assertEqual((head.geturl(), tail), (curDir, "")) uri = ButlerURI(".", forceAbsolute=False) head, tail = uri.split() self.assertEqual((head.geturl(), tail), (curDir, "."))