diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2024-08-12 00:33:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-12 00:33:33 (GMT) |
commit | 6aa35f3002dda25858d47e702e750e2871e42a7c (patch) | |
tree | a5acf584667ac9996681ded1ab591dbd5efbc692 /Lib/test | |
parent | 9cd03263100ddb1657826cc4a71470786cab3932 (diff) | |
download | cpython-6aa35f3002dda25858d47e702e750e2871e42a7c.zip cpython-6aa35f3002dda25858d47e702e750e2871e42a7c.tar.gz cpython-6aa35f3002dda25858d47e702e750e2871e42a7c.tar.bz2 |
gh-122903: Honor directories in zipfile.Path.glob. (#122908)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_zipfile/_path/test_path.py | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/Lib/test/test_zipfile/_path/test_path.py b/Lib/test/test_zipfile/_path/test_path.py index 4a31cae..90d6df0 100644 --- a/Lib/test/test_zipfile/_path/test_path.py +++ b/Lib/test/test_zipfile/_path/test_path.py @@ -101,7 +101,7 @@ class TestPath(unittest.TestCase): def test_iterdir_and_types(self, alpharep): root = zipfile.Path(alpharep) assert root.is_dir() - a, k, b, g, j = root.iterdir() + a, n, b, g, j = root.iterdir() assert a.is_file() assert b.is_dir() assert g.is_dir() @@ -121,7 +121,7 @@ class TestPath(unittest.TestCase): @pass_alpharep def test_iterdir_on_file(self, alpharep): root = zipfile.Path(alpharep) - a, k, b, g, j = root.iterdir() + a, n, b, g, j = root.iterdir() with self.assertRaises(ValueError): a.iterdir() @@ -136,7 +136,7 @@ class TestPath(unittest.TestCase): @pass_alpharep def test_open(self, alpharep): root = zipfile.Path(alpharep) - a, k, b, g, j = root.iterdir() + a, n, b, g, j = root.iterdir() with a.open(encoding="utf-8") as strm: data = strm.read() self.assertEqual(data, "content of a") @@ -240,7 +240,7 @@ class TestPath(unittest.TestCase): @pass_alpharep def test_read(self, alpharep): root = zipfile.Path(alpharep) - a, k, b, g, j = root.iterdir() + a, n, b, g, j = root.iterdir() assert a.read_text(encoding="utf-8") == "content of a" # Also check positional encoding arg (gh-101144). assert a.read_text("utf-8") == "content of a" @@ -306,7 +306,7 @@ class TestPath(unittest.TestCase): reflect that change. """ root = zipfile.Path(alpharep) - a, k, b, g, j = root.iterdir() + a, n, b, g, j = root.iterdir() alpharep.writestr('foo.txt', 'foo') alpharep.writestr('bar/baz.txt', 'baz') assert any(child.name == 'foo.txt' for child in root.iterdir()) @@ -476,6 +476,18 @@ class TestPath(unittest.TestCase): assert list(root.glob("**/*.txt")) == list(root.rglob("*.txt")) @pass_alpharep + def test_glob_dirs(self, alpharep): + root = zipfile.Path(alpharep) + assert list(root.glob('b')) == [zipfile.Path(alpharep, "b/")] + assert list(root.glob('b*')) == [zipfile.Path(alpharep, "b/")] + + @pass_alpharep + def test_glob_subdir(self, alpharep): + root = zipfile.Path(alpharep) + assert list(root.glob('g/h')) == [zipfile.Path(alpharep, "g/h/")] + assert list(root.glob('g*/h*')) == [zipfile.Path(alpharep, "g/h/")] + + @pass_alpharep def test_glob_subdirs(self, alpharep): root = zipfile.Path(alpharep) @@ -594,3 +606,10 @@ class TestPath(unittest.TestCase): 'two-slash.txt', 'parent.txt', ] + + @pass_alpharep + def test_interface(self, alpharep): + from importlib.resources.abc import Traversable + + zf = zipfile.Path(alpharep) + assert isinstance(zf, Traversable) |