Add pathclass.assert_exists and assert_not_exists.
This commit is contained in:
parent
e334396d56
commit
c22bcd290f
1 changed files with 13 additions and 1 deletions
|
@ -6,11 +6,15 @@ import re
|
||||||
class PathclassException(Exception):
|
class PathclassException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class Exists(PathclassException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class NotExists(PathclassException):
|
||||||
|
pass
|
||||||
|
|
||||||
class NotDirectory(PathclassException):
|
class NotDirectory(PathclassException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NotFile(PathclassException):
|
class NotFile(PathclassException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -96,6 +100,14 @@ class Path:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '{c}({path})'.format(c=self.__class__.__name__, path=repr(self.absolute_path))
|
return '{c}({path})'.format(c=self.__class__.__name__, path=repr(self.absolute_path))
|
||||||
|
|
||||||
|
def assert_exists(self):
|
||||||
|
if not self.exists:
|
||||||
|
raise NotExists(self)
|
||||||
|
|
||||||
|
def assert_not_exists(self):
|
||||||
|
if self.exists:
|
||||||
|
raise Exists(self)
|
||||||
|
|
||||||
def assert_is_file(self):
|
def assert_is_file(self):
|
||||||
if not self.is_file:
|
if not self.is_file:
|
||||||
raise NotFile(self)
|
raise NotFile(self)
|
||||||
|
|
Loading…
Reference in a new issue