3131from ._common import (
3232 INVALID_PATH_CHARS ,
3333 INVALID_WIN_PATH_CHARS ,
34+ NTFS_RESERVED_FILE_NAMES ,
3435 VALID_PATH_CHARS ,
3536 VALID_PLATFORM_NAMES ,
3637 WIN_RESERVED_FILE_NAMES ,
@@ -130,8 +131,8 @@ class Test_validate_filepath(object):
130131 chain .from_iterable (
131132 [
132133 [
133- arg_list
134- for arg_list in product (
134+ args
135+ for args in product (
135136 ["/{0}/{1}{0}" .format (randstr (64 ), valid_c )], VALID_PLATFORM_NAMES
136137 )
137138 ]
@@ -147,7 +148,7 @@ def test_normal(self, value, platform):
147148 ["value" , "platform" ],
148149 chain .from_iterable (
149150 [
150- [arg_list for arg_list in product ([valid_path ], VALID_PLATFORM_NAMES )]
151+ [args for args in product ([valid_path ], VALID_PLATFORM_NAMES )]
151152 for valid_path in VALID_MULTIBYTE_PATH_LIST
152153 ]
153154 ),
@@ -271,6 +272,35 @@ def test_exception_invalid_win_char(self, value, platform):
271272 validate_filepath (value , platform = platform )
272273 assert not is_valid_filepath (value , platform = platform )
273274
275+ @pytest .mark .parametrize (
276+ ["value" , "platform" , "expected" ],
277+ [
278+ ["abc\\ {}\\ xyz" .format (reserved_keyword ), platform , ReservedNameError ]
279+ for reserved_keyword , platform in product (WIN_RESERVED_FILE_NAMES , ["linux" , "macos" ])
280+ if reserved_keyword not in ["." , ".." ]
281+ ]
282+ + [
283+ ["/foo/abc/{}.txt" .format (reserved_keyword ), platform , ReservedNameError ]
284+ for reserved_keyword , platform in product (WIN_RESERVED_FILE_NAMES , ["linux" , "macos" ])
285+ if reserved_keyword not in ["." , ".." ]
286+ ]
287+ + [
288+ ["{}\\ {}" .format (drive , filename ), platform , ReservedNameError ]
289+ for drive , platform , filename in product (
290+ ["C:" , "D:" ], ["linux" , "macos" ], NTFS_RESERVED_FILE_NAMES
291+ )
292+ ]
293+ + [
294+ ["{}\\ abc\\ {}" .format (drive , filename ), platform , ReservedNameError ]
295+ for drive , platform , filename in product (
296+ ["C:" , "D:" ], ["windows" , "universal" ], NTFS_RESERVED_FILE_NAMES
297+ )
298+ ],
299+ )
300+ def test_normal_reserved_name (self , value , platform , expected ):
301+ validate_filepath (value , platform = platform )
302+ assert is_valid_filepath (value , platform = platform )
303+
274304 @pytest .mark .parametrize (
275305 ["value" , "platform" , "expected" ],
276306 [
@@ -286,10 +316,17 @@ def test_exception_invalid_win_char(self, value, platform):
286316 WIN_RESERVED_FILE_NAMES , ["windows" , "universal" ]
287317 )
288318 if reserved_keyword not in ["." , ".." ]
319+ ]
320+ + [
321+ ["{}\\ {}" .format (drive , filename ), platform , ReservedNameError ]
322+ for drive , platform , filename in product (
323+ ["C:" , "D:" ], ["windows" , "universal" ], NTFS_RESERVED_FILE_NAMES
324+ )
289325 ],
290326 )
291327 def test_exception_reserved_name (self , value , platform , expected ):
292328 with pytest .raises (expected ) as e :
329+ print (platform , value )
293330 validate_filepath (value , platform = platform )
294331 assert e .value .reusable_name is False
295332 assert e .value .reserved_name
@@ -419,6 +456,18 @@ def test_normal_str(self, platform, value, replace_text, expected):
419456 ]
420457 for reserved_keyword , platform in product (WIN_RESERVED_FILE_NAMES , ["windows" ])
421458 if reserved_keyword not in ["." , ".." ]
459+ ]
460+ + [
461+ ["{}\\ {}" .format (drive , filename ), platform , "{}/{}_" .format (drive , filename )]
462+ for drive , platform , filename in product (
463+ ["C:" , "D:" ], ["universal" ], NTFS_RESERVED_FILE_NAMES
464+ )
465+ ]
466+ + [
467+ ["{}\\ {}" .format (drive , filename ), platform , "{}\\ {}_" .format (drive , filename )]
468+ for drive , platform , filename in product (
469+ ["C:" , "D:" ], ["windows" ], NTFS_RESERVED_FILE_NAMES
470+ )
422471 ],
423472 )
424473 def test_normal_reserved_name (self , value , test_platform , expected ):
0 commit comments