@@ -112,12 +112,36 @@ def test_ro_file(lock_type: type[BaseFileLock], tmp_file_ro: Path) -> None:
112
112
lock .acquire ()
113
113
114
114
115
+ WindowsOnly = pytest .mark .skipif (sys .platform != "win32" , reason = "Windows only" )
116
+
117
+
115
118
@pytest .mark .parametrize ("lock_type" , [FileLock , SoftFileLock ])
116
- def test_missing_directory (lock_type : type [BaseFileLock ], tmp_path_ro : Path ) -> None :
117
- lock_path = tmp_path_ro / "a" / "b"
118
- lock = lock_type (str (lock_path ))
119
+ @pytest .mark .parametrize (
120
+ ("expected_error" , "match" , "bad_lock_file" ),
121
+ [
122
+ pytest .param (FileNotFoundError , "No such file or directory:" , "a/b" , id = "non_existent_directory" ),
123
+ pytest .param (FileNotFoundError , "No such file or directory:" , "" , id = "blank_filename" ),
124
+ pytest .param (ValueError , "embedded null (byte|character)" , "\0 " , id = "null_byte" ),
125
+ pytest .param (
126
+ PermissionError if sys .platform == "win32" else IsADirectoryError ,
127
+ "Permission denied:" if sys .platform == "win32" else "Is a directory" ,
128
+ "." ,
129
+ id = "current_directory" ,
130
+ ),
131
+ ]
132
+ + [pytest .param (OSError , "Invalid argument" , i , id = f"invalid_{ i } " , marks = WindowsOnly ) for i in '<>:"|?*\a ' ]
133
+ + [pytest .param (PermissionError , "Permission denied:" , i , id = f"permission_{ i } " , marks = WindowsOnly ) for i in "/\\ " ],
134
+ )
135
+ @pytest .mark .timeout (5 ) # timeout in case of infinite loop
136
+ def test_bad_lock_file (
137
+ lock_type : type [BaseFileLock ],
138
+ expected_error : type [Exception ],
139
+ match : str ,
140
+ bad_lock_file : str ,
141
+ ) -> None :
142
+ lock = lock_type (bad_lock_file )
119
143
120
- with pytest .raises (OSError , match = "No such file or directory:" ):
144
+ with pytest .raises (expected_error , match = match ):
121
145
lock .acquire ()
122
146
123
147
0 commit comments