Coverage for tests/test_schemeless.py: 24%
Shortcuts 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
Shortcuts 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# This file is part of lsst-resources.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
12import unittest
14from lsst.resources import ResourcePath
17class SchemelessTestCase(unittest.TestCase):
18 """Test the behavior of a schemeless URI."""
20 def test_creation(self) -> None:
21 """Test creation from schemeless URI."""
22 relative = "a/b/c.txt"
23 abspath = "/a/b/c.txt"
25 relative_uri = ResourcePath(relative, forceAbsolute=False)
26 self.assertFalse(relative_uri.scheme)
27 self.assertFalse(relative_uri.isabs())
28 self.assertEqual(relative_uri.ospath, relative)
30 # This will be a schemeless absolute URI.
31 # It is not converted to a file URI (but maybe should be).
32 abs_uri = ResourcePath(relative, forceAbsolute=True)
33 self.assertFalse(abs_uri.scheme)
34 self.assertTrue(abs_uri.isabs())
36 # For historical reasons an absolute path is converted
37 # to a file URI.
38 file_uri = ResourcePath(abspath)
39 self.assertEqual(file_uri.scheme, "file")
40 self.assertTrue(file_uri.isabs())
42 # Use a prefix root.
43 # This will remain schemeless.
44 prefix = "/a/b/"
45 abs_uri = ResourcePath(relative, root=prefix)
46 self.assertEqual(abs_uri.ospath, f"{prefix}{relative}")
47 self.assertEqual(abs_uri.scheme, "")
49 # Only the path is used.
50 prefix = "file://localhost/a/b/"
51 prefix_uri = ResourcePath(prefix)
52 file_uri = ResourcePath(relative, root=prefix_uri)
53 self.assertEqual(str(file_uri), f"{prefix_uri.ospath}{relative}")
55 # Fragments should be fine.
56 relative_uri = ResourcePath(relative + "#frag", forceAbsolute=False)
57 self.assertEqual(str(relative_uri), f"{relative}#frag")
59 # For historical reasons a a root can not be anything other
60 # than a file. This does not really make sense in the general
61 # sense but can be implemented using uri.join().
62 with self.assertRaises(ValueError):
63 ResourcePath(relative, root=ResourcePath("resource://lsst.resources/something.txt"))
66if __name__ == "__main__": 66 ↛ 67line 66 didn't jump to line 67, because the condition on line 66 was never true
67 unittest.main()