Skip to content

Commit

Permalink
Fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Jan 6, 2019
1 parent 7af2e83 commit 674d72f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
6 changes: 5 additions & 1 deletion pathvalidate/_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ def sanitize(self, replacement_text=""):
def _validate(self, value):
self._validate_null_string(value)

file_path = os.path.normpath(os.path.splitdrive(value)[1])
value = os.path.splitdrive(value)[1]
if not value:
return

file_path = os.path.normpath(value)
unicode_file_path = preprocess(file_path)

self._validate_reserved_keywords(unicode_file_path)
Expand Down
34 changes: 14 additions & 20 deletions test/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,16 @@ def test_exception(self, value, expected):
class Test_validate_filepath(object):
VALID_CHAR_LIST = VALID_PATH_CHARS
VALID_MULTIBYTE_PATH_LIST = [
r"\\localhost\Users\新しいフォルダー\あいうえお.txt",
r"\\localhost\新しいフォルダー\ユーザ属性.txt",
"\\\\localhost\\Users\\新しいフォルダー\\あいうえお.txt",
"\\\\localhost\\新しいフォルダー\\ユーザ属性.txt",
]
WIN_VALID_PATH_LIST = [
r"\\\localhost\Users\test\AppData\Local\Temp\pytest-of-test\pytest-0\test_exception__hoge_csv_heade1\hoge.csv",
r"\\localhost/Users/test/AppData/Local/Temp/pytest-of-test/pytest-0/test_exception__hoge_csv_heade1/hoge.csv",
r"\\localhost\Users\test\AppData/Local\Temp/pytest-of-test\pytest-0/test_exception__hoge_csv_heade1\hoge.csv",
r"\\localhost\Users",
"\\\\localhost\\Users\\\est\\AppData\\Local\\Temp\\pytest-of-test\\pytest-0\\\hoge.csv",
"\\\\localhost/Users/test/AppData/Local/Temp/pytest-of-test/pytest-0/test_exception__hoge_csv_heade1/hoge.csv",
"\\\\localhost\\Users\\est\\AppData/Local\\Temp/pytest-of-test\\pytest-0/\hoge.csv",
"\\\\localhost\\Users",
"\\\\localhost\\",
r"\Users",
"\\Users",
]

@pytest.mark.parametrize(
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_normal_multibyte(self, value, platform):

@pytest.mark.parametrize(["value"], [[valid_path] for valid_path in WIN_VALID_PATH_LIST])
def test_normal_win(self, value):
validate_filepath(value, "windows")
validate_filepath(value, platform="windows")

@pytest.mark.parametrize(
["value", "platform", "max_len", "expected"],
Expand Down Expand Up @@ -383,21 +383,15 @@ class Test_validate_win_file_path(object):
@pytest.mark.parametrize(
["value"],
[
["C:\\Users\\est\\AppData\\Local\\Temp\\pytest-of-test\\pytest-0\\\hoge.csv"],
["Z:\\Users\\est\\AppData\\Local\\Temp\\pytest-of-test\\pytest-0\\hoge.csv"],
[
r"C:\Users\test\AppData\Local\Temp\pytest-of-test\pytest-0\test_exception__hoge_csv_heade1\hoge.csv"
"C:/Users/est/AppData/Local/Temp/pytest-of-test/pytest-0/test_exception__hoge_csv_heade1/hoge.csv"
],
[
r"Z:\Users\test\AppData\Local\Temp\pytest-of-test\pytest-0\test_exception__hoge_csv_heade1\hoge.csv"
],
[
r"C:/Users/test/AppData/Local/Temp/pytest-of-test/pytest-0/test_exception__hoge_csv_heade1/hoge.csv"
],
[
r"C:\Users/test\AppData/Local\Temp/pytest-of-test\pytest-0/test_exception__hoge_csv_heade1\hoge.csv"
],
[r"C:\Users"],
["C:\\Users/est\\AppData/Local\\Temp/pytest-of-test\\pytest-0/hoge.csv"],
["C:\\Users"],
["C:\\"],
[r"\Users"],
["\\Users"],
],
)
def test_normal(self, value):
Expand Down

0 comments on commit 674d72f

Please sign in to comment.