From d63403be8fa7b7344e40e878858c40bab7414324 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 3 Jul 2022 13:33:39 -0400 Subject: [PATCH 1/3] Add test capturing expectation revealed by #253. --- importlib_resources/tests/test_reader.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/importlib_resources/tests/test_reader.py b/importlib_resources/tests/test_reader.py index 16841a50..0ea3a086 100644 --- a/importlib_resources/tests/test_reader.py +++ b/importlib_resources/tests/test_reader.py @@ -76,6 +76,10 @@ def test_join_path(self): os.path.join('namespacedata01', 'imaginary'), ) + def test_join_path_compound(self): + path = MultiplexedPath(self.folder) + assert not path.joinpath('imaginary/foo.py').exists() + def test_repr(self): self.assertEqual( repr(MultiplexedPath(self.folder)), From bad45d5b5c311598437cb720d58d2543d6dbff03 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 3 Jul 2022 13:44:50 -0400 Subject: [PATCH 2/3] Suppress all TraversalErrors in MultiplexedPath. Fixes #253. --- importlib_resources/readers.py | 11 ++++------- importlib_resources/tests/test_reader.py | 3 --- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/importlib_resources/readers.py b/importlib_resources/readers.py index 19450f46..ab34db74 100644 --- a/importlib_resources/readers.py +++ b/importlib_resources/readers.py @@ -85,13 +85,10 @@ def is_file(self): def joinpath(self, *descendants): try: return super().joinpath(*descendants) - except abc.TraversalError as exc: - # One of the paths didn't resolve. - msg, target, names = exc.args - if names: # pragma: nocover - raise - # It was the last; construct result with the first path. - return self._paths[0].joinpath(target) + except abc.TraversalError: + # One of the paths did not resolve (a directory does not exist). + # Just return something that will not exist. + return self._paths[0].joinpath(*descendants) def open(self, *args, **kwargs): raise FileNotFoundError(f'{self} is not a file') diff --git a/importlib_resources/tests/test_reader.py b/importlib_resources/tests/test_reader.py index 6148c31c..1c8ebeeb 100644 --- a/importlib_resources/tests/test_reader.py +++ b/importlib_resources/tests/test_reader.py @@ -3,8 +3,6 @@ import pathlib import unittest -import pytest - from importlib import import_module from importlib_resources.readers import MultiplexedPath, NamespaceReader @@ -79,7 +77,6 @@ def test_join_path(self): ) self.assertEqual(path.joinpath(), path) - @pytest.mark.xfail(reason="#253") def test_join_path_compound(self): path = MultiplexedPath(self.folder) assert not path.joinpath('imaginary/foo.py').exists() From 41d8e32e18998033ea9892412eb993458b78688b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 3 Jul 2022 13:45:43 -0400 Subject: [PATCH 3/3] Update changelog. Ref #253. --- CHANGES.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 5321b177..570fe86f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,10 @@ +v5.8.1 +====== + +* #253: In ``MultiplexedPath``, restore expectation that + a compound path with a non-existent directory does not + raise an exception. + v5.8.0 ======