Skip to content
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