def __init__(self, loader):
self.path = pathlib.Path(loader.path).parent
+ def resource_path(self, resource):
+ """
+ Return the file system path to prevent
+ `resources.path()` from creating a temporary
+ copy.
+ """
+ return str(self.path.joinpath(resource))
+
def files(self):
return self.path
-class ZipReader(FileReader):
+class ZipReader(abc.TraversableResources):
def __init__(self, loader, module):
_, _, name = module.rpartition('.')
prefix = loader.prefix.replace('\\', '/') + name + '/'
# for non-existent paths.
target = self.files().joinpath(path)
return target.is_file() and target.exists()
+
+ def files(self):
+ return self.path
class PathDiskTests(PathTests, unittest.TestCase):
data = data01
+ def test_natural_path(self):
+ """
+ Guarantee the internal implementation detail that
+ file-system-backed resources do not get the tempdir
+ treatment.
+ """
+ with resources.path(self.data, 'utf-8.file') as path:
+ assert 'data' in str(path)
+
class PathZipTests(PathTests, util.ZipSetup, unittest.TestCase):
def test_remove_in_context_manager(self):