@@ -1486,27 +1486,46 @@ def test_apply_on_nonexistent_base_path_matches_iteration_behavior(tmp_path: Pat
14861486 """
14871487 `apply()` should match iteration behavior for nonexistent base paths.
14881488
1489- The test compares the exception type from iteration and `apply()`. If
1490- iteration yields no error, it also verifies that no callback input appears .
1489+ The test records the normal iteration result for a missing path and verifies
1490+ that `apply()` visits exactly the same paths .
14911491 """
14921492 nonexistent = tmp_path / 'does_not_exist'
14931493
1494- iter_error : type = type (None )
1495- try :
1496- list (Crawler (nonexistent ))
1497- except Exception as e : # noqa: BLE001
1498- iter_error = type (e )
1499-
1494+ iter_paths = list (Crawler (nonexistent ))
15001495 seen : list = []
1501- apply_error : type = type (None )
1496+ Crawler (nonexistent ).apply (seen .append )
1497+ assert seen == iter_paths
1498+
1499+
1500+ def test_apply_propagates_rglob_errors_with_only_files_false (tmp_path : Path ):
1501+ """
1502+ `apply()` should propagate traversal errors from all-entity crawling.
1503+
1504+ The test creates an unreadable directory and first checks whether this
1505+ platform exposes that as a `PermissionError`. If it does, applying a
1506+ callback through the crawler must propagate the same error.
1507+ """
1508+ blocked = tmp_path / 'blocked'
1509+ blocked .mkdir ()
1510+ (blocked / 'file.txt' ).write_text ('content' )
1511+ blocked .chmod (0 )
1512+
15021513 try :
1503- Crawler (nonexistent ).apply (seen .append )
1504- except Exception as e : # noqa: BLE001
1505- apply_error = type (e )
1514+ try :
1515+ list (tmp_path .rglob ('*' ))
1516+ except PermissionError :
1517+ pass
1518+ else :
1519+ pytest .skip ('Path.rglob does not propagate permission errors on this platform.' )
15061520
1507- assert apply_error == iter_error
1508- if iter_error is type (None ):
1509- assert seen == []
1521+ seen : list = []
1522+ with pytest .raises (
1523+ PermissionError ,
1524+ match = match (str (PermissionError (errno .EACCES , os .strerror (errno .EACCES ), str (blocked )))),
1525+ ):
1526+ Crawler (tmp_path , only_files = False ).apply (seen .append )
1527+ finally :
1528+ blocked .chmod (stat .S_IRWXU )
15101529
15111530
15121531def test_apply_on_file_base_path_matches_iteration_behavior (tmp_path : Path ):
0 commit comments