()
| 275 | |
| 276 | |
| 277 | def 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 |
nothing calls this directly
no test coverage detected