Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #204: Making Path validators resilient to None. #205

Merged
merged 1 commit into from
Sep 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions voluptuous/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,13 @@ def IsFile(v):
True
>>> with raises(FileInvalid, 'not a file'):
... IsFile()("random_filename_goes_here.py")
>>> with raises(FileInvalid, 'Not a file'):
... IsFile()(None)
"""
return os.path.isfile(v)
if v:
return os.path.isfile(v)
else:
raise FileInvalid('Not a file')


@message('not a directory', cls=DirInvalid)
Expand All @@ -427,8 +432,13 @@ def IsDir(v):

>>> IsDir()('/')
'/'
>>> with raises(DirInvalid, 'Not a directory'):
... IsDir()(None)
"""
return os.path.isdir(v)
if v:
return os.path.isdir(v)
else:
raise DirInvalid("Not a directory")


@message('path does not exist', cls=PathInvalid)
Expand All @@ -440,8 +450,13 @@ def PathExists(v):
True
>>> with raises(Invalid, 'path does not exist'):
... PathExists()("random_filename_goes_here.py")
>>> with raises(PathInvalid, 'Not a Path'):
... PathExists()(None)
"""
return os.path.exists(v)
if v:
return os.path.exists(v)
else:
raise PathInvalid("Not a Path")


class Range(object):
Expand Down