Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't rely on Path.iterdir() output order in tests #131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ def zipfile_ondisk(self, alpharep):
def test_iterdir_and_types(self, alpharep):
root = zipfile.Path(alpharep)
assert root.is_dir()
a, n, b, g, j = root.iterdir()
a, b, g, j, n = sorted(root.iterdir(), key=lambda p: p.name)
assert a.is_file()
assert b.is_dir()
assert g.is_dir()
c, f, d = b.iterdir()
c, d, f = sorted(b.iterdir(), key=lambda p: p.name)
assert c.is_file() and f.is_file()
(e,) = d.iterdir()
assert e.is_file()
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_subdir_is_dir(self, alpharep):
@pass_alpharep
def test_open(self, alpharep):
root = zipfile.Path(alpharep)
a, n, b, g, j = root.iterdir()
a, b, g, j, n = sorted(root.iterdir(), key=lambda p: p.name)
with a.open(encoding="utf-8") as strm:
data = strm.read()
self.assertEqual(data, "content of a")
Expand Down Expand Up @@ -235,7 +235,7 @@ def test_open_missing_directory(self, alpharep):
@pass_alpharep
def test_read(self, alpharep):
root = zipfile.Path(alpharep)
a, n, b, g, j = root.iterdir()
a, b, g, j, n = sorted(root.iterdir(), key=lambda p: p.name)
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"
Expand Down Expand Up @@ -301,7 +301,7 @@ def test_mutability(self, alpharep):
reflect that change.
"""
root = zipfile.Path(alpharep)
a, n, b, g, j = root.iterdir()
a, b, g, j, n = sorted(root.iterdir(), key=lambda p: p.name)
alpharep.writestr('foo.txt', 'foo')
alpharep.writestr('bar/baz.txt', 'baz')
assert any(child.name == 'foo.txt' for child in root.iterdir())
Expand Down Expand Up @@ -617,7 +617,7 @@ def test_unsupported_names(self):
zf.writestr("V: NMS.flac", b"fLaC...")
zf.filename = ''
root = zipfile.Path(zf)
contents = root.iterdir()
contents = iter(sorted(root.iterdir(), key=lambda p: len(p.name)))
assert next(contents).name == 'path?'
assert next(contents).name == 'V: NMS.flac'
assert root.joinpath('V: NMS.flac').read_bytes() == b"fLaC..."
Expand Down