Add pathclass.assert_exists and assert_not_exists.

This commit is contained in:
Ethan Dalool 2020-02-19 16:22:22 -08:00
parent e334396d56
commit c22bcd290f

View file

@ -6,11 +6,15 @@ import re
class PathclassException(Exception):
pass
class Exists(PathclassException):
pass
class NotExists(PathclassException):
pass
class NotDirectory(PathclassException):
pass
class NotFile(PathclassException):
pass
@ -96,6 +100,14 @@ class Path:
def __repr__(self):
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):
if not self.is_file:
raise NotFile(self)