File tree Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change 1
1
from pathlib import Path
2
2
3
- path_type_labels = {
4
- ' is_dir' : 'directory' ,
5
- ' is_file' : 'file' ,
6
- ' is_mount' : 'mount point' ,
7
- ' is_symlink' : 'symlink' ,
8
- ' is_block_device' : 'block device' ,
9
- ' is_char_device' : 'char device' ,
10
- ' is_fifo' : 'FIFO' ,
11
- ' is_socket' : 'socket' ,
3
+ _PATH_TYPE_LABELS = {
4
+ Path . is_dir : 'directory' ,
5
+ Path . is_file : 'file' ,
6
+ Path . is_mount : 'mount point' ,
7
+ Path . is_symlink : 'symlink' ,
8
+ Path . is_block_device : 'block device' ,
9
+ Path . is_char_device : 'char device' ,
10
+ Path . is_fifo : 'FIFO' ,
11
+ Path . is_socket : 'socket' ,
12
12
}
13
13
14
14
@@ -17,8 +17,8 @@ def path_type_label(p: Path) -> str:
17
17
Find out what sort of thing a path is.
18
18
"""
19
19
assert p .exists (), 'path does not exist'
20
- for method , name in path_type_labels .items ():
21
- if getattr ( p , method )( ):
20
+ for method , name in _PATH_TYPE_LABELS .items ():
21
+ if method ( p ):
22
22
return name
23
23
24
24
return 'unknown'
Original file line number Diff line number Diff line change
1
+ from pydantic_settings .utils import path_type_label
2
+
3
+
4
+ def test_path_type_label (tmp_path ):
5
+ result = path_type_label (tmp_path )
6
+ assert result == 'directory'
You can’t perform that action at this time.
0 commit comments