Coverage for python/lsst/resources/remote_test.py: 100%
16 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-19 01:59 -0700
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-19 01:59 -0700
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.
11from __future__ import annotations
13__all__ = ("RemoteTestResourcePath",)
15import contextlib
16import logging
17import shutil
18from collections.abc import Generator
20from ._resourcePath import ResourcePath
21from .file import FileResourcePath
23log = logging.getLogger(__name__)
26class RemoteTestResourcePath(FileResourcePath):
27 """A local file resource path that pretends it is a remote resource."""
29 # By definition a remote file.
30 isLocal = False
32 @contextlib.contextmanager
33 def _as_local(
34 self, multithreaded: bool = True, tmpdir: ResourcePath | None = None
35 ) -> Generator[ResourcePath, None, None]:
36 """Copy file to a new location in a temporary directory.
38 Parameters
39 ----------
40 multithreaded : `bool`, optional
41 Unused.
42 tmpdir : `ResourcePath` or `None`, optional
43 Explicit override of the temporary directory to use for remote
44 downloads.
46 Returns
47 -------
48 local_uri : `ResourcePath`
49 A URI to a local POSIX file corresponding to a local temporary
50 downloaded copy of the resource.
51 """
52 with (
53 ResourcePath.temporary_uri(prefix=tmpdir, suffix=self.getExtension(), delete=True) as tmp_uri,
54 ):
55 shutil.copy(self.ospath, tmp_uri.ospath)
56 yield tmp_uri