Skip to content

Commit 856cc83

Browse files
committed
Update test cases
1 parent 53c7607 commit 856cc83

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

test/_common.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@
9595
"{:s}{:d}".format(name, num)
9696
for name, num in product(["COM", "com", "LPT", "lpt"], range(1, 10))
9797
]
98+
NTFS_RESERVED_FILE_NAMES = [
99+
"$Mft",
100+
"$MftMirr",
101+
"$LogFile",
102+
"$Volume",
103+
"$AttrDef",
104+
"$Bitmap",
105+
"$Boot",
106+
"$BadClus",
107+
"$Secure",
108+
"$Upcase",
109+
"$Extend",
110+
"$Quota",
111+
"$ObjId",
112+
"$Reparse",
113+
]
98114

99115

100116
def randstr(length, char_list=alphanum_chars):

test/test_filename.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
INVALID_PATH_CHARS,
3434
INVALID_WIN_FILENAME_CHARS,
3535
INVALID_WIN_PATH_CHARS,
36+
NTFS_RESERVED_FILE_NAMES,
3637
VALID_FILENAME_CHARS,
3738
VALID_PLATFORM_NAMES,
3839
WIN_RESERVED_FILE_NAMES,
@@ -123,13 +124,17 @@ class Test_validate_filename(object):
123124
chain.from_iterable(
124125
[
125126
[
126-
arg_list
127-
for arg_list in product(
127+
args
128+
for args in product(
128129
["{0}{1}{0}".format(randstr(64), valid_c)], VALID_PLATFORM_NAMES
129130
)
130131
]
131132
for valid_c in VALID_CHARS
132133
]
134+
+ [
135+
[args for args in product([filename], VALID_PLATFORM_NAMES)]
136+
for filename in NTFS_RESERVED_FILE_NAMES
137+
]
133138
),
134139
)
135140
def test_normal(self, value, platform):
@@ -140,7 +145,7 @@ def test_normal(self, value, platform):
140145
["value", "platform"],
141146
chain.from_iterable(
142147
[
143-
[arg_list for arg_list in product([multibyte_name], VALID_PLATFORM_NAMES)]
148+
[args for args in product([multibyte_name], VALID_PLATFORM_NAMES)]
144149
for multibyte_name in VALID_MULTIBYTE_NAMES
145150
]
146151
),
@@ -214,8 +219,8 @@ def test_locale_ja(self, locale):
214219
chain.from_iterable(
215220
[
216221
[
217-
arg_list
218-
for arg_list in product(
222+
args
223+
for args in product(
219224
["{0}{1}{0}".format(randstr(64), invalid_c)], VALID_PLATFORM_NAMES
220225
)
221226
]

test/test_filepath.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from ._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

Comments
 (0)