MCPcopy
hub / github.com/pex-tool/pex / test_deterministic_walk

Function test_deterministic_walk

tests/test_common.py:277–304  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

275
276
277def test_deterministic_walk():
278 # type: () -> None
279 with temporary_dir() as tmp:
280 root_dir = os.path.join(tmp, "root")
281 dir_a = os.path.join(root_dir, "a")
282 file_a = os.path.join(dir_a, "file_a")
283 touch(file_a)
284 dir_b = os.path.join(root_dir, "b")
285 file_b = os.path.join(dir_b, "file_b")
286 touch(file_b)
287
288 with mock.patch("os.walk", new=NonDeterministicWalk()):
289 result_a = []
290 for root, dirs, files in deterministic_walk(root_dir):
291 result_a.append((root, dirs, files))
292 if dirs:
293 dirs[:] = ["b", "a"]
294
295 result_b = []
296 for root, dirs, files in deterministic_walk(root_dir):
297 result_b.append((root, dirs, files))
298
299 assert result_a == [
300 (root_dir, ["a", "b"], []),
301 (dir_a, [], ["file_a"]),
302 (dir_b, [], ["file_b"]),
303 ], "Modifying dirs should not affect the order of the walk"
304 assert result_a == result_b, "Should be resilient to os.walk yielding in arbitrary order"
305
306
307@pytest.fixture

Callers

nothing calls this directly

Calls 7

temporary_dirFunction · 0.90
touchFunction · 0.90
deterministic_walkFunction · 0.90
appendMethod · 0.80
joinMethod · 0.45
patchMethod · 0.45

Tested by

no test coverage detected